Skip to content

Commit

Permalink
display the unfolding game with pygame
Browse files Browse the repository at this point in the history
  • Loading branch information
erikkristoferanderson committed Aug 1, 2021
1 parent 6e45b09 commit 6f0696f
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
1 change: 1 addition & 0 deletions game_of_life/game.py → game_of_life/mygamefile.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
import copy


class Game:
"""defines an instance of the game of life"""

Expand Down
42 changes: 42 additions & 0 deletions game_of_life/mypygamefile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import pygame
import sys
from pygame.locals import *
import mygamefile
import resources

pygame.init()

FPS = 2
FramePerSec = pygame.time.Clock()

BLACK = (0, 0, 0)
WHITE = (255, 255, 255)

DISPLAYSURF = pygame.display.set_mode((200, 200))
DISPLAYSURF.fill(WHITE)
pygame.display.set_caption("Game of Life")


def main():
game = mygamefile.Game()
game.board = resources.BOARD_WITH_BLINKER_A
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
DISPLAYSURF.fill(BLACK)
game.advance_to_next_generation()
for i, column in enumerate(game.board):
for j, row in enumerate(column):
surf = pygame.Surface((10, 10))
surf.fill(WHITE)
if row == 1:
DISPLAYSURF.blit(surf, (j*10, i*10))
# cell.draw()
pygame.display.update()
FramePerSec.tick(FPS)


if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion game_of_life/test_game.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# import pytest
from game import Game
from mygamefile import Game
import resources


Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pytest~=6.2.4
pytest~=6.2.4
pygame~=2.0.1

0 comments on commit 6f0696f

Please sign in to comment.