-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCards.py
94 lines (78 loc) · 2.65 KB
/
Cards.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
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
import random
class Card:
__suit = ""
__value = ""
__image = ""
__discarded = False
def __init__(this, suit, value):
this.__suit = suit
this.__value = value
if suit in ['Staves', 'Sabers', 'Flasks', 'Coins']:
this.__image = str(value) + suit + '.png'
else:
this.__image = suit + '.png'
def getSuit(this):
return this.__suit
def getName(this):
name = ""
if this.__suit in ['Staves', 'Sabers', 'Flasks', 'Coins']:
if this.__value == 12:
name = "Commander of " + this.__suit
elif this.__value == 13:
name = "Mistress of " + this.__suit
elif this.__value == 14:
name = "Master of " + this.__suit
elif this.__value == 15:
name = "Ace of " + this.__suit
else:
name = str(this.__value) + " of " + this.__suit
else:
name = this.__suit
if this.__discarded:
name = "(discarded) " + name
return name + "(" + str(this.__value) + ")"
def getValue(this):
return this.__value
def getImage(this):
return this.__image
def isDiscarded(this):
return this.__discarded
def discard(this):
this.__discarded = not this.__discarded
return this.__discarded
def __str__(this):
return this.getName()
class Deck():
__faces = {}
__cards = []
__discardPile = []
def discard(this, card):
this.__discardPile.append(card)
def shuffle(this):
random.shuffle(this.__cards)
def deal(this):
list1 = []
list2 = []
for i in range(4):
list1.append(this.draw(1)[0])
list2.append(this.draw(1)[0])
if len(this.__cards) < 16:
this.shuffle()
return (list1, list2)
def draw(this, num):
list1 = []
for i in range(num):
list1.append(this.__cards.pop(0))
this.__discardPile = this.__discardPile + list1
return list1
def __init__(this,faces):
this.__faces = faces
suits = ['Staves', 'Sabers', 'Flasks', 'Coins']
#ranked = {'Commander':12, 'Mistress':13, 'Master':14, 'Ace':15}
for suit in suits:
for i in range(15):
this.__cards.append(Card(suit, i+1))
for face,value in this.__faces.items():
this.__cards.append(Card(face,value))
this.__cards.append(Card(face,value))
this.shuffle()