-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcard_game.py
45 lines (32 loc) · 1.03 KB
/
card_game.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
import random
class Card:
def __init__(self, suit, value):
self.suit = suit
self.value = value
def __repr__(self):
return f"{self.value} of {self.suit}"
class Deck:
def __init__(self):
self.cards = [Card(suit, value) for suit in ['Hearts', 'Diamonds', 'Spades', 'Clubs']
for value in ['Ace', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'Jack', 'Queen', 'King']]
def shuffle(self):
random.shuffle(self.cards)
def deal(self):
return self.cards.pop()
class Player:
def __init__(self, name):
self.name = name
self.hand = []
def take_card(self, card):
self.hand.append(card)
def __repr__(self):
return f"Player {self.name} with hand {self.hand}"
deck = Deck()
deck.shuffle()
player1 = Player("Player 1")
player2 = Player("Player 2")
for i in range(5):
player1.take_card(deck.deal())
player2.take_card(deck.deal())
print(player1)
print(player2)