-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeck.py
More file actions
70 lines (58 loc) · 1.84 KB
/
Copy pathdeck.py
File metadata and controls
70 lines (58 loc) · 1.84 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
import random
class Card:
def __init__(self, rank, suit):
self.rank = rank
self.suit = suit
self.value = rankValues[self.rank]
def show(self):
if self.rank == 1:
print(f"Ace of {self.suit}")
elif self.rank == 11:
print(f"Jack of {self.suit}")
elif self.rank == 12:
print(f"Queen of {self.suit}")
elif self.rank == 13:
print(f"King of {self.suit}")
else:
print(f"{self.rank} of {self.suit}")
class Deck:
def __init__(self):
self.build()
def show(self):
for card in self.contents:
card.show()
def build(self):
self.contents = []
for suit in suits:
for rank in ranks:
self.contents.append(Card(rank, suit))
def shuffle(self):
for i in range(0, 52):
j = random.randint(0, i + 1)
self.contents[j], self.contents[i] = self.contents[i], self.contents[j]
class Player:
def __init__(self, name):
self.name = name
self.hand = []
self.points = 0
def hit(self):
topCard = deck.contents.pop()
self.hand.append(topCard)
self.pointCheck()
def pHand(self):
for card in self.hand:
card.show()
def pointCheck(self):
self.points = sum(self.hand.value)
return self.points
suits = ['Hearts', 'Clubs', 'Diamonds', 'Spades']
ranks = list(range(1,14))
rankValues = {1 : 11, 2 : 2, 3 : 3, 4 : 4, 5 : 5, 6 : 6, 7 : 7, 8 : 8, 9 : 9, 10 : 10,
11 : 10,
12 : 10,
13 : 10}
deck = Deck()
deck.shuffle()
player = Player('Will')
player.hit()
player.pHand()