-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplayer.py
37 lines (28 loc) · 841 Bytes
/
player.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
STOCK = 0
DISCARD_PILE = 1
class CardNotInHandError(Exception): pass
class Player(object):
def __init__(self, _name):
self.name = _name
self.hand = []
self.game = None
def __str__(self):
return "Player %s" %(self.name)
def receive_card(self, card):
self.hand.append(card)
def set_game(self, game):
self.game = game
def draws_card(self, pile):
if pile == STOCK:
card = self.game.pop_stock_card()
self.hand.append(card)
elif pile == DISCARD_PILE:
for card in self.game.discard_pile:
self.hand.append(card)
def discard(self, card):
try:
self.hand.remove(card)
except:
raise CardNotInHandError
else:
self.game.discard_pile.append(card)