-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgameplay.py
88 lines (66 loc) · 2.53 KB
/
gameplay.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
from timer import Timer
# Status is tracked as a number, but to make the code readable constants are used
STATUS_NEW = 0 # Game is ready to start, but not running
STATUS_PLAYER1_START = 1
STATUS_PLAYER1_CARDS_1 = 2
STATUS_PLAYER1_CARDS_2 = 3
STATUS_END = 50
# Number of seconds to display high score before allowing click to continue
TIME_DISPLAY_SCORE = 3
class GamePlay:
# These are what we need to track
score = 0
status = STATUS_NEW
# These are the cards that have been turned up.
# Should be a positive number which is the index in the array (-1 is not set)
cards_selected = [-1, -1]
def __init__(self, count_down):
self.count_down = count_down
pass
# If game has not yet started
def isNewGame(self):
if self.status == STATUS_NEW:
return True
return False
def isGameOver(self):
if self.status == STATUS_END:
return True
return False
def setGameOver(self):
# Add short timer for game over to ensure
# player gets to see high score
self.count_down.start_count_down(TIME_DISPLAY_SCORE)
self.status = STATUS_END
def isGameRunning(self):
if (self.status >= STATUS_PLAYER1_START and self.status < STATUS_END):
return True
return False
def startGame(self):
self.score = 0
self.status = STATUS_PLAYER1_START
def setNewGame(self):
self.status = STATUS_NEW
def isPairTurnedOver(self):
if (self.status == STATUS_PLAYER1_CARDS_2):
return True
return False
# Return the index position of the specified card
def getCard(self, card_number):
return self.cards_selected[card_number]
# Point scored, so add score and update status
def scorePoint(self):
self.score += 1
self.status = STATUS_PLAYER1_START
def getScore(self):
return self.score
# Not a pair - just update status
def notPair(self):
self.status = STATUS_PLAYER1_START
# If a card is clicked then update the status accordingly
def cardClicked(self, card_index):
if (self.status == STATUS_PLAYER1_START):
self.cards_selected[0] = card_index
self.status = STATUS_PLAYER1_CARDS_1
elif (self.status == STATUS_PLAYER1_CARDS_1):
self.cards_selected[1] = card_index
self.status = STATUS_PLAYER1_CARDS_2