-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoinFlip.py
141 lines (107 loc) · 4.14 KB
/
coinFlip.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
'''
Coin flip
Rules:
1. You will enter /flip to flip your coin
2. You start with a balance of 5 and must have at least five balance to continue playing; however,
if you run out of balance or are below the 5 minimum balance every 300 seconds you will get an addition 5 balance.
3. If you make it to balance 1,000 you win.
4. Max flips are 50 balance
'''
import random # Imported for random choice
import time # For tracking time before replenishment
import threading
# Debugging
logging = True
# Misc settings
game_on = True
winning_balance = 1000
# Predetermined win/loss number
coin_sides = ["heads", "tails"]
# Staring balance of player
balance = 5
minimum_balance = 5
balance_refresh_rate = 300
max_wager = 50
# Replenishment ##############################################
def replenishment(): # Handling replenishment
# Starting off with the timer, before firing off.
time.sleep(balance_refresh_rate)
while True:
if balance < minimum_balance:
balance += 5
print(f"Balance replenished. Your new balance is {balance}")
else:
if logging:
print(
f"Your balance remained the same. Your current balance is: {balance}")
time.sleep(balance_refresh_rate)
##############################################################
def play_again():
while True:
try:
play_again_prompt = input("Would you like to play again?\n")
if play_again_prompt.islower == "yes" or play_again_prompt.islower == "y":
balance = 5
main()
elif play_again_prompt.islower == "no" or play_again_prompt.islower == "n":
print("Thank you for playing!")
exit()
else:
print("Please enter yes or no.")
except ValueError:
print("Invalid input. Try again.")
def check_wager(wager):
if wager > balance:
print(
f"You don't have enough balance for this wager. Your balance is: {balance}")
coin_flip()
if wager < minimum_balance:
print(
f"This wager does not meet the requirements. Minimum wagers are: {minimum_balance}")
coin_flip()
if wager > max_wager:
print(
f"This wager does not meet the requirements. Maximum wagers are: {max_wager}")
coin_flip()
def coin_flip():
if balance >= winning_balance:
print(f"You won the game! Your balance is: {balance}\n")
play_again()
if balance < minimum_balance:
print("You don't have enough balance to wager yet. Please wait.")
time.sleep(balance_refresh_rate)
coin_flip()
else:
while True:
try:
wager = int(input("What is your wager?\n"))
break
except ValueError:
print("Please make sure to use numbers only.")
check_wager(wager)
outcome = random.choice(coin_sides)
if outcome == coin_sides[1]:
balance -= wager
print(f"You lost! Your new balance is: {balance}")
coin_flip()
else:
balance += wager
print(f"You won! Your new balance is: {balance}")
coin_flip()
def main():
while game_on:
# Thread it so it can run in the background
replenishment_thread = threading.Thread(target=replenishment)
replenishment_thread.start() # Start the thread
# Welcome message
print(
f"Welcome to Coin Flip Simulator. Your balance is {balance}.\n")
print("Rules are simple...\nYou must flip your coin and if you lose you'll be deducted balance and if you win you'll be added balance.")
print("Max flips are 50 balance.\nMinimum flips are 5 balance.\n")
print("If you drop below 5, don't worry you'll be replenished balance every 5 minutes.\n")
print("To flip you will need to enter your wager.")
print("If you win, you'll get the original 10 + 10 to your balance.\n")
print("The objective is to reach a balance of 1,000. If you can do this, you will win.\n")
# Start of game functions
coin_flip()
main()