-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeck.py
More file actions
104 lines (81 loc) · 2.84 KB
/
Copy pathDeck.py
File metadata and controls
104 lines (81 loc) · 2.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
##########################################################################
# Deck implements the class Deck and the class Card.
# Card is our representation of actual game cards. They have a number
# and a suit. We can check if a Card has been revealed or not.
# Deck holds the 52 cards of a traditional deck. It is able to shuffle
# them when necessary. Deck is also able to deal cards
##########################################################################
import random
class Card:
def __init__(self, value, suit, numVal):
self.value = value
self.suit = suit
self.name = value + " of " + suit
self.numVal = numVal
self.showing = False
def getValue(self):
return self.value
def getSuit(self):
return self.suit
def getName(self):
return self.name
def getNumericalValue(self):
return self.numVal
def isShowing(self):
return self.showing
def turn(self):
self.showing = True
# checks whether other card is the same as this card
def isEqual(self, other):
if other.value == self.value and other.suit == self.suit:
return True
return False
def __sort__(self):
#Useful for ordering lists of cards, to help classify each hand
pass
class Deck:
def __init__(self):
self.cards = []
suits = ["Clubs", "Spades", "Hearts", "Diamonds"]
values = {"2":2,"3":3,"4":4,"5":5,"6":6,"7":7,"8":8,"9":9,"10":10,"Jack":11,"Queen":12,"King":13,"Ace":14}
for suit in suits:
for value in values:
self.cards.append(Card(value,suit,values[value]))
# returns the deck
def getCards(self):
return self.cards
# returns the current number of cards in the deck
def getNumberCards(self):
return len(self.cards)
# checks whether the deck is empty or not
def isEmpty(self):
if len(self.cards) > 0:
return False
else:
return True
# returns card with card name
def getCardByName(self, cardName):
for card in self.cards:
if cardName == card.getName():
return card
return None
# removes card with card name
def removeCard(self, cardName):
card = self.getCardByName(cardName)
if card:
self.cards.remove(card)
# checks if specific card is in the deck, by the card name
def containsCard(self, cardName):
for card in self.cards:
if cardName == card.getName():
return True
return False
# shuffles the deck
def shuffle(self):
random.shuffle(self.cards)
# returns one card from the deck
def dealCard(self):
if len(self.cards) == 0:
return None
else:
return self.cards.pop()