diff --git a/main.py b/game-of-life.py similarity index 80% rename from main.py rename to game-of-life.py index 31fb8a3..5728cc8 100644 --- a/main.py +++ b/game-of-life.py @@ -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 @@ -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() @@ -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() diff --git a/universe.py b/universe.py index 8206a96..d6d292b 100644 --- a/universe.py +++ b/universe.py @@ -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 diff --git a/universeview.py b/universeview.py index fef2754..c434c30 100644 --- a/universeview.py +++ b/universeview.py @@ -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)