-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame_round.py
120 lines (112 loc) · 4.03 KB
/
game_round.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
from token_randomizer import token_randomizer as token_rand
from time import sleep
from debug import force_range
def round_loop(start_bal: float):
"""Starts each round, and asks for the player"""
#Variable to calculate money gained
money_gained = 0
#Variable to check the total amount of money that has been betted
money_betted = 0
#Loop condition
loop = True
while loop:
if money_betted > 10:
loop = False
print("""--------------------------
You've betted the maximum amount of money, time to see your winnings
--------------------------""")
continue
# Ask player for their bet
betting_amount = request_bet(money_betted, start_bal)
# Update money gained, balance, and amount betted
money_gained -= betting_amount
start_bal -= betting_amount
money_betted += betting_amount
# Generate a reward
reward = reward_player(betting_amount)
# Update money gained & balance
money_gained += reward
start_bal += reward
# Ask player if they want to continue playing
loop = continue_game()
else:
return money_gained, start_bal
def reward_player(money_bet: float) -> float:
# Generate Token
print("""--------------------------
Generating Token...
--------------------------""")
# Start token generation
token, token_value = token_rand()
print("""--------------------------
Token Generation complete!
--------------------------""")
print("""--------------------------
The token you won is...
--------------------------""")
sleep(3)
# Provide feedback
if token == "unicorn":
print(f"""--------------------------
Congratulations, you won the \033[35mUnicorn \033[37mtoken, which means that you get \033[35m${token_value * money_bet:.2f}!
\033[37m--------------------------""")
elif token == "horse":
print(f"""--------------------------
You won the \033[36mHorse \033[37mtoken, which means you get \033[36m${token_value * money_bet:.2f}!
\033[37m--------------------------""")
elif token == "zebra":
print(f"""--------------------------
You won the \033[36mZebra \033[37mtoken, which means you get \033[36m${token_value * money_bet:.2f}!
\033[37m--------------------------""")
elif token == "donkey":
print("""--------------------------
Sorry to say, but you got the Donkey token, which means you don't win.
But hey, there's always next time!
--------------------------""")
# Return the money won
return token_value * money_bet
def request_bet(money_spent: float, balance: float) -> float:
loop = True
while loop:
# Ask player how much money they want to bet
betting_amount = force_range("""--------------------------
How much would you like to bet?
--------------------------""", 1, 10)
# If the player bets more then $10, or more then the total amount of money spent,
# ask for a lower bet
if balance < betting_amount or betting_amount > (10 - money_spent):
print("""--------------------------
Too high of a bet, please try again.
--------------------------""")
continue
# If the player bets less then $1, ask for a higher bet
elif betting_amount < 1:
print("""--------------------------
Too low of a bet, please try again
--------------------------""")
else:
loop = False
return betting_amount
def continue_game() -> bool:
#Lists of possible responses
yes = ["yes", "yeah", "y"]
no = ["no", "nah", "n"]
loop = True
while loop:
# Ask player if they would like to continue playing
response = input("""--------------------------
would you like to play another round? Y/N
--------------------------""").lower().strip()
# If yes, continue playing the game
if response in yes:
loop = False
return True
# Else if no, stop playing
elif response in no:
loop = False
return False
# If response matches none of the possible responses, ask again
else:
print("""--------------------------
That isn't an answer, please try again.
--------------------------""")