-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.py
70 lines (54 loc) · 1.19 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import IOUtils
import Player
import Board
import Data
player = None
board = None
# Initializing the game
def init(width, height):
global _running, player, board
board = Board.Board(width, height)
player = Player.Player(width / 2, height / 2, board)
_running = False
# Starting the game
def start():
global _running
_running = True
return _loop()
# Stopping the game
def stop():
global _running
_running = False
def _loop():
while _running:
# Drawing
IOUtils.clear()
board.draw()
# Updating
updateVal = _update(IOUtils.getch())
if updateVal != None:
return updateVal
if _hasWon():
return _finish(True)
# Loop functions
def _update(char):
# Checking if the user wants to quit
if char == 'q':
return _finish()
player.update(char, board) # Updating the player
def _hasWon():
for x in board.getTiles():
if x == Data.UNACTIVATED:
return False
return True
def _finish(won = False):
IOUtils.clear()
if (won):
print "You won!"
answer = ''
while (answer.lower() != 'y') and (answer.lower() != 'n'):
answer = raw_input("Would you like to play again? y/N: ")
if answer.lower() == 'y':
return True
elif (answer == '') or (answer.lower() == 'n'):
return False