- Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCardGame.py
More file actions
Latest commit
71 lines (62 loc) · 1.33 KB
/
Copy pathCardGame.py
File metadata and controls
71 lines (62 loc) · 1.33 KB
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
importrandom
classNumber(object):
ACE=1
TWO=2
JACK=11
QUEEN=12
KING=13
@staticmethod
defToString(num):
ifnum==1:
return"A"
elifnum<=10:
returnstr(num)
elifnum==11:
return"J"
elifnum==12:
return"Q"
else:
return"K"
classSuit(object):
HEART=1
DIAMOND=2
CLUB=3
SPADE=4
@staticmethod
defToString(suit):
ifsuit==1:
returnu"\u2665"
elifsuit==2:
returnu"\u2666"
elifsuit==3:
returnu"\u2663"
else:
returnu"\u2660"
classCard(object):
def__init__(self,num,suit):
self.suit=suit
self.num=num
defprintCard(self):
printself.ToString()
defToString(self):
returnSuit.ToString(self.suit) +Number.ToString(self.num)
classDeck(object):
def__init__(self):
self.allCards= [Card(i,j) foriinrange(1,14) forjinrange(1,5)]
# Fisher-Yates shuffle
defshuffle(self):
foriinrange(len(self.allCards)-1,-1,-1):
j=random.randint(0,i+1)
temp=self.allCards[i]
self.allCards[i] =self.allCards[j]
self.allCards[j] =temp
defdeal(self):
returnself.allCards.pop()
defprintDeck(self):
forcardinself.allCards:
card.printCard()
deck=Deck()
deck.shuffle()
deck.printDeck()
card=deck.deal()
card.printCard()