-
Notifications
You must be signed in to change notification settings - Fork 0
/
doc.py
70 lines (45 loc) · 1.42 KB
/
doc.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
print('hello world')
import random
class Card(object):
def __init__(self,suit,value):
self.suit = suit
self.value = value
def show(self):
print(f'{self.value} of {self.suit}')
class Deck(object):
def __init__(self):
self.cards = []
self.build()
def build(self):
for s in ['Spades',"clubs","Diamonds","Hearts"]:
for v in range(1,14):
self.cards.append(Card(s,v))
#print(f'{v} of {s}')
def show(self):
for c in self.cards:
c.show()
def shuffle(self):
for i in range(len(self.cards)-1,0, -1):
r = random.randint(0,i)
self.cards[i], self.cards[r] = self.cards[r],self.cards[i]
def drawCard(self):
return self.cards.pop()
class Player(object):
def __init__(self,name):
self.name = name
self.hand = []
def draw(self, deck):
self.hand.append(deck.drawCard())
return self
def showHand(self):
for card in self.hand:
card.show()
def discard(self):
return self.hand.pop()
#card = Card('clubs',6)
#card.show()
deck = Deck()
deck.shuffle()
bob = Player('Bob')
bob.draw(deck).draw(deck)
bob.showHand()