-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeck.py
51 lines (37 loc) · 1.1 KB
/
deck.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
""" We create a "card" class and a "deck" class to keep the
information used in a card game with some useful methods."""
import random
VALUES = ['2', '3', '4', '5', '6', '7', '8', '9', 'X', 'J', 'Q', 'K', 'A']
SUITS = ['S', 'C', 'H', 'D']
class Card:
""" A class abstracting the notion of a card."""
def __init__(self, suit, value):
self.suit = suit
self.value = value
# print card to screen
def display(self):
print('/------\\')
print('| |')
print('| ' + self.value + self.suit + ' |')
print('| |')
print('\\------/')
def display_list(hand):
size = len(hand)
print('/------\\' * size)
print('| |' * size)
for card in hand[:-1]:
print('| ' + card.value + card.suit + ' |', end="")
print('| ' + hand[-1].value + hand[-1].suit + ' |')
print('| |' * size)
print('\\------/' * size)
class Deck:
""" A class modeling the notion of a deck of cards."""
def __init__(self):
self.deck = []
for val in VALUES:
for suit in SUITS:
self.deck.append(Card(suit, val))
def shuffle(self):
random.shuffle(self.deck)
def draw(self):
return self.deck.pop()