-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.py
70 lines (50 loc) · 1.98 KB
/
player.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
class Player:
coins = 1000
card_list = []
def __init__(self,name):
self.name = name
self.balance = Player.coins
print(self.name + " your balance is: " +str(self.balance))
def Place_a_bet(self):
while True:
try:
self.bet = int(input(self.name + " please place your bet: "))
if self.bet > self.balance:
raise Exception(self.name + ",the bet you've placed exceeds your balance which is " +str(self.balance)+ ".")
else:
print(self.name+ " you have bet " +str(self.bet)+ " coins.")
except ValueError :
print(self.name+ " Please place a valid bet ")
continue
except Exception as msg:
print(msg)
continue
else:
self.balance -= self.bet
print(self.name + " your balance is: " +str(self.balance)+ ".")
break
def Display_cards(self):
print(self.name+ " your card(s) is/are: ",end="" )
for i in Player.card_list:
#print(Player.card_list)
print(i,end=" ")
def Player_cards(self,card):
Player.card_list.append(card)
#self.Display_cards()
def reset(self):
del Player.card_list[:]
def result(self,blackjack_in_two = False):
if not blackjack_in_two:
winning = 2*self.bet
self.balance += winning
elif blackjack_in_two == "PUSH":
winning = self.bet
self.balance +=winning
else:
winning = 3*self.bet
self.balance += winning
print(self.name+ " You've won " +str(winning)+ " coins.")
if __name__ == "__main__":
player1 = Player('Rutvij')
player1.Place_a_bet()
player1.Player_cards()