-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGame.py
executable file
·99 lines (90 loc) · 3.72 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import random
import os
class Game(object):
def __int__(self):
self.currentHand = []
self.lastDiscard
self.dropCard
def start(self, deck, pile, playerCount, playerList):
print('Starting game...')
print('Dealing cards...')
print('Game start')
firstTurn = random.randint(0, playerCount-1)
for i in range(playerCount):
playerList.getPlayerAt(i).startDraw(deck)
pile.discard(deck.drawCard())
return firstTurn
def checkDiscard(self, deck, pile, player):
dropCard = False
self.lastDiscard = pile.getLast()
self.currentHand = []
for card in player.hand:
self.currentHand.append(card)
for i in range(len(self.currentHand)):
if(self.currentHand[i].colour == self.lastDiscard.colour):
dropCard = True
elif(self.currentHand[i].value == self.lastDiscard.value):
dropCard = True
return dropCard
def checkDrop(self, index, pile, player):
dropCard = False
self.lastDiscard = pile.getLast()
self.dropCard = player.getCardAt(index) #-1
if(self.lastDiscard.colour == self.dropCard.colour):
dropCard = True
elif(self.lastDiscard.value == self.dropCard.value):
dropCard = True
return dropCard
def clear(self):
os.system('clear')
def discardLoop(self, deck, pile, currentPlayer):
# if(not currentPlayer.drawStatus()):
discard = False
skipTurn = False
currentPlayer.displayHand()
while((discard is False) and (skipTurn is False)):
if(not currentPlayer.drawStatus):
dropIndex = self.checkIndexRange(currentPlayer)
if(self.checkDrop(dropIndex-1, pile, currentPlayer)):
#print(currentPlayer.getCardAt(dropIndex-1))
pile.discard(currentPlayer.discard(dropIndex-1))
discard = True
else:
self.clear()
print('Choose another card to discard')
pile.showLast()
currentPlayer.displayHand()
else:
if(self.checkDiscard(deck, pile, currentPlayer)):
dropIndex = self.checkIndexRange(currentPlayer)
if(self.checkDrop(dropIndex-1, pile, currentPlayer)):
#print(currentPlayer.getCardAt(dropIndex-1))
pile.discard(currentPlayer.discard(dropIndex-1))
discard = True
else:
self.clear()
print('Choose another card to discard')
pile.showLast()
currentPlayer.displayHand()
else:
print('The card you drew cannot be discarded. Skipping turn')
skipTurn = True
currentPlayer.updateDrawStatus(False)
def checkIndexRange(self, player):
endLoop = False
dropIndex = 0
while endLoop is False:
dropIndex = int(input('Choose card to discard: '))
if(dropIndex > len(player.hand)):
print('Index out of range!')
print('Choose a number within the index range 1 to ' + str(len(player.hand)))
else:
endLoop = True
return dropIndex
def getTurnIncrement(self, playerList):
turnIncrement = 0
for player in playerList.list:
if(player.done):
turnIncrement =+ 1
return turnIncrement
# def isNextDone(self, player):