A simple Game of Life implementation in Java
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

40 lignes
844 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 Patch getPatch (int x, int y) {
  17. return _grid[x][y];
  18. }
  19. public void setPatch (int x, int y, Patch p) {
  20. _grid[x][y] = p;
  21. }
  22. public String toString() {
  23. String ans = "";
  24. for(int i = 0; i < _grid.length; i++) {
  25. for(int j = 0; j < _grid[i].length; j++) {
  26. ans += _grid[i][j];
  27. }
  28. ans += "\n";
  29. }
  30. return ans;
  31. }
  32. }