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.

34 lignes
627 B

  1. public class Screen {
  2. private int width, height;
  3. public int[] pixels;
  4. private int[] _grid;
  5. public Screen(int width, int height) {
  6. this.width = width;
  7. this.height = height;
  8. pixels = new int[width * height];
  9. _grid = new int[width * height];
  10. }
  11. public void clear() {
  12. for (int x = 0; x < _grid.length; x++) {
  13. pixels[x] = 0;
  14. }
  15. }
  16. public void render() {
  17. for (int x = 0; x < width; x++) {
  18. for (int y = 0; y < height; y++) {
  19. pixels[x + y * width] = _grid[x + y * width];
  20. }
  21. }
  22. }
  23. public void draw(int x, int y, int color) {
  24. _grid[x + y * width] = color;
  25. }
  26. }