-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcards.py
More file actions
61 lines (47 loc) · 1.27 KB
/
Copy pathcards.py
File metadata and controls
61 lines (47 loc) · 1.27 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
import random
class Card:
def __init__(self, suit, val,):
self.suit = suit
self.val = val
def show(self):
print("{} of {}".format(self.val, self.suit))
class Deck:
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))
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()
def draw(self, deck):
self.hand.append(deck.drawcard())
return self
class Player:
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()
deck = Deck()
deck.shuffle()
player_1 = Player('Name_1')
player_1.draw(deck)
print('Name_1: ')
player_1.showHand()
player_2 = Player('Name_2')
player_2.draw(deck)
print('Name_2: ')
player_2.showHand()