-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGame.py
48 lines (42 loc) · 1.36 KB
/
Game.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from Grid import Grid
from Color import Color
class Game(object):
def __init__(self, grid, cycles, x, y):
self.grid = grid
self.cycles = cycles
self.x = x # row
self.y = y # column
self.current_cycle = 0
# Green counter for cell (y,x)
self.green_score = 0
def play(self):
'''
Executes all cycles
Updates the grid and green counter for specified cell (y,x) after each cycle
'''
while self.current_cycle < self.cycles:
if self.grid.grid[self.x][self.y].color == Color.GREEN:
self.green_score +=1
self.grid.next()
# Debugging
# print(self.grid)
# print("-"*self.grid.width)
self.current_cycle +=1
if self.grid.grid[self.x][self.y].color == Color.GREEN:
self.green_score +=1
def result(self):
'''
Returns final result - green score for specified cell
'''
if self.current_cycle == self.cycles:
return(self.green_score)
else:
raise Exception("Final Cycle has not been reached")
def __str__(self):
'''
Overwrites str
Returns the grid at current cycle
'''
output = "Current cycle: " + str(self.current_cycle) + "/n"
output += str(self.grid)
return output