A simple Game of Life implementation in Java
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

Goldfish.java 1.1 KiB

11 yıl önce
11 yıl önce
11 yıl önce
11 yıl önce
11 yıl önce
11 yıl önce
11 yıl önce
11 yıl önce
123456789101112131415161718192021222324252627282930313233343536373839
  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. _grid = Conway.run(_grid);
  24. _render.setGrid(_grid);
  25. _render.run();
  26. _render.sleep();
  27. }
  28. }
  29. public static void main(String[] args) {
  30. Goldfish g = new Goldfish();
  31. g.run();
  32. }
  33. }