-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
display the unfolding game with pygame
- Loading branch information
1 parent
6e45b09
commit 6f0696f
Showing
4 changed files
with
46 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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""" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |