-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsupportSystem.py
166 lines (141 loc) · 4.61 KB
/
supportSystem.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
class Error:
@staticmethod
def is_Error():
while True:
x = input().lower()
if x != "yes" and x != "no":
print("Need be yes or no ")
else:
return x
@staticmethod
def Error_bet(have_Chip):
while True:
try:
x = int(input())
except:
print("need to be int ")
else:
if x > have_Chip:
print("Sorry, You do not have enough Chips , you have {} ".
format(have_Chip))
elif x <= 0:
print("num need to be > 0")
else:
return x
finally:
print("")
#------------------------------------------------------------------------------------------------------------
class Chips: # player Chips
def __init__(self):
self.total = 100
def add(self, num):
self.total = self.total + num
def remove(self, num):
self.total = self.total - num
#------------------------------------------------------------------------------------------------------------
class Card:
def __init__(self):
self.cart = {
"A": 11,
"K": 10,
"Q": 10,
"J": 10,
"10": 10,
"9": 9,
"8": 8,
"7": 7,
"6": 6,
"5": 5,
"4": 4,
"3": 3,
"2": 2
}
self.keys = self.cart.keys()
self.suits = ('Hearts', 'Diamonds', 'Spades', 'Clubs')
self.all_card = []
for i in self.keys:
for j in self.suits:
self.all_card.append((i, j))
def __len__(self):
return len(self.all_card)
#------------------------------------------------------------------------------------------------------------
class Hand:
def __init__(self):
self.Card_in_hand = []
self.value = 0
self.aces = 0
def add_card(self, cart, value):
self.Card_in_hand.append(cart)
if value == 11:
self.aces = self.aces + 1
self.value = self.value + value
if self.value > 21 and self.aces >= 1:
self.value = self.value - 10 # if i have 21+ and i have 1 ace , ace now == 1 and not 11
self.aces = self.aces - 1 # -1 ace its no more ace now i have 1 and not 11
def hand_win(self):
if (self.value) == 21:
return "Win"
elif (self.value) > 21:
return "Lose"
else:
return "Go on"
def __str__(self):
return "{" + str(self.Card_in_hand) + "," + str(self.value) + "}"
class Presentation:
@staticmethod
def Hand_printing(player):
x = str(player)
x = x.replace(" ", "")
x = x[3:len(x) - 5]
x = x.replace("[", "")
x = x.replace("]", "")
x = x.replace(")", "")
x = x.replace("(", "")
x = x.replace("'", "")
x = x.split(',')
y = 0
for _ in range(len(x)):
if (y + 1) < len(x):
print(" ---------------------")
print(" | {} {} |".format(x[y], x[y + 1]))
print(" ---------------------")
y = y + 2
print(player.value) # For people who do not understand in Card
@staticmethod
def dealer_printing(dealer):
x = str(dealer)
x = x.replace(" ", "")
x = x[3:len(x) - 5]
x = x.replace("[", "")
x = x.replace("]", "")
x = x.replace(")", "")
x = x.replace("(", "")
x = x.replace("'", "")
x = x.split(',')
print("~ Dealer Hand ~")
print("~~~~~~~~~~~~~~~~")
if x[0] == '':
print("No cart")
elif len(x) == 2:
print(" ------------------")
print(" | {} {} |".format(x[0], x[1]))
print(" ------------------")
else:
print(" --------------------- -------------------")
print(" | {} {} | |#################|".format(
x[0], x[1]))
print(" --------------------- -------------------")
print(" ")
#------------------------------------------------------------------------------------------------------------
class Deck(Card):
def __init__(self, cards):
Card.__init__(self)
self.cards = cards
def Deck_pop(self, i):
self.cards.pop(i)
def find_idx(self, x):
return self.cards.index(x)
def __str__(self):
return str(self.cards)
def __len__(self):
return len(self.cards)