A simple Game of Life implementation in Java
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Goldfish.java 1.1 KiB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package edu.stuy.goldfish;
  2. import edu.stuy.goldfish.rules.*;
  3. public class Goldfish {
  4. private Grid _grid;
  5. private Render _render;
  6. public Goldfish() {
  7. int width = 128;
  8. int height = 128;
  9. _grid = new Grid(width, height);
  10. _render = new Render(width, height, _grid);
  11. }
  12. public void run() {
  13. for (int i = 0; i < _grid.getWidth(); i += 16) {
  14. for (int j = 0; j < _grid.getHeight(); j += 16) {
  15. _grid.getPatch(i + 1, j + 0).setState(1);
  16. _grid.getPatch(i + 2, j + 1).setState(1);
  17. _grid.getPatch(i + 2, j + 2).setState(1);
  18. _grid.getPatch(i + 1, j + 2).setState(1);
  19. _grid.getPatch(i + 0, j + 2).setState(1);
  20. }
  21. }
  22. while (true) {
  23. if(!_render.paused){
  24. _grid = Conway.run(_grid);
  25. }
  26. _render.setGrid(_grid);
  27. _render.run();
  28. _render.sleep();
  29. }
  30. }
  31. public static void main(String[] args) {
  32. Goldfish g = new Goldfish();
  33. g.run();
  34. }
  35. }