Skip to content

Commit

Permalink
c1 & c2 can now be passed via command line
Browse files Browse the repository at this point in the history
  • Loading branch information
Darius Berghe committed Dec 21, 2016
1 parent f2bc764 commit 1deab99
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
18 changes: 14 additions & 4 deletions main.py → game-of-life.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from random import randint

class MainWindow(QMainWindow):
def __init__(self, screen_width, screen_height):
def __init__(self, screen_width, screen_height, c1, c2):
super().__init__()

# build ui
Expand All @@ -21,7 +21,7 @@ def __init__(self, screen_width, screen_height):

# create a random initial state for the universe
initial = [[(randint(0, 10) == 9) for i in range(uv.cols)] for j in range(uv.rows)]
uv.initialize(initial)
uv.initialize(initial, c1, c2)

# start the animation directly
uv.start()
Expand All @@ -36,15 +36,25 @@ def keyPressEvent(self, QKeyEvent):
self.showNormal()
else:
self.showFullScreen()


if __name__ == '__main__':
c1 = 2
c2 = 3
try:
c1 = int(sys.argv[1])
c2 = int(sys.argv[2])
except IndexError:
pass
except ValueError:
print("c1 and c2 must be positive integers\ngame-of-life [c1 c2]")
sys.exit(0)

# set up graphics
app = QApplication(sys.argv)

# get screen resolution and create the main window
screen_resolution = app.desktop().screenGeometry()
main = MainWindow(screen_resolution.width(), screen_resolution.height())
main = MainWindow(screen_resolution.width(), screen_resolution.height(), c1, c2)

# draw, launch qt app
main.show()
Expand Down
2 changes: 1 addition & 1 deletion universe.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from life import *

class Universe():
def __init__(self, state, c1 = 2, c2 = 3):
def __init__(self, state, c1, c2):
'''
Initialize the game with the initial state (the only input to the original Game of Life)
:param state: 2D list of booleans
Expand Down
4 changes: 2 additions & 2 deletions universeview.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ def __init__(self, parent=None):
self._CellToScreenRatio = 0.01
self._recording = False

def initialize(self, initialState):
self.universe = Universe(initialState)
def initialize(self, initialState, c1, c2):
self.universe = Universe(initialState, c1, c2)

def seed(self, state):
self.universe.seed(state)
Expand Down

0 comments on commit 1deab99

Please sign in to comment.