A simple Game of Life implementation in Java
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
683 B

  1. package edu.stuy.goldfish;
  2. public class Grid {
  3. private Patch[][] _grid;
  4. public Grid() {
  5. _grid = new Patch[1][1];
  6. _grid[0][0] = new Patch(this, 0, 0);
  7. }
  8. public Grid(int x, int y) {
  9. _grid = new Patch[x][y];
  10. for(int i = 0; i < x; i++) {
  11. for(int j = 0; j < y; j++) {
  12. _grid[i][j] = new Patch(this, i, j);
  13. }
  14. }
  15. }
  16. public String toString() {
  17. String ans = "";
  18. for(int i = 0; i < _grid.length; i++) {
  19. for(int j = 0; j < _grid[i].length; j++) {
  20. ans += _grid[i][j];
  21. }
  22. ans += "\n";
  23. }
  24. return ans;
  25. }
  26. }