-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
86 lines (67 loc) · 2.86 KB
/
main.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
from utils.slot_variables import spin, winnings
from utils.user_variables import add_deposit, withdraw, define_bet
from db.sql import db_main, update_balance_in_db
# Main user selection and game
def main():
# User log in and authentication
balance, username = db_main()
if balance == 0:
amount = input("Insufficient funds. Need to deposit to play, enter deposit amount: ")
try:
amount = float(amount)
balance = add_deposit(balance, amount)
update_balance_in_db(username, balance)
except ValueError:
print("Please enter a valid number")
# User setting total_bet
total_bet = define_bet(balance)
while True:
print(f'Balance: {balance}')
user_choice = input("do you want to spin? y / n / c to change bet size / d to deposit funds / w to withdraw funds: ")
if user_choice == "c":
total_bet = define_bet(balance)
elif user_choice == "d":
amount = input("how much do you want to deposit? ")
try:
amount = float(amount)
balance = add_deposit(balance, amount)
update_balance_in_db(username, balance)
except ValueError:
print("Please enter a valid number")
elif user_choice == "w":
while True:
try:
amount = float(input("how much do you want to withdraw? "))
if amount > balance:
print(f'unable to withdraw {amount}, current balance is {balance}')
else:
break
except ValueError:
print("Please enter a valid number")
balance = withdraw(balance, amount)
update_balance_in_db(username, balance)
elif user_choice == "n":
print("leaving game")
break
else:
symbols, symbols_per_line, winning_symbols = spin()
is_winner, balance = winnings(symbols, symbols_per_line, balance, total_bet, winning_symbols, username)
if is_winner:
print("Winner!")
else:
print("No win")
if balance == 0:
print("insufficient funds")
user_input = input("press q to quit or d to deposit funds: ")
if user_input == "q":
print("leaving game")
quit()
elif user_input == "d":
amount = input("how much do you want to deposit? ")
try:
amount = int(amount)
balance = add_deposit(balance, amount)
update_balance_in_db(username, balance)
except ValueError:
print("Please enter a valid number")
main()