-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.py
More file actions
98 lines (80 loc) · 2.5 KB
/
util.py
File metadata and controls
98 lines (80 loc) · 2.5 KB
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
"""
util module
"""
import os
import first_round
from color import *
if __name__ == "__main__":
print(f"{RED}Please start the game by running the main.py file{RESET}")
def scan_buy_in():
"""
getting the buy_in from the user
"""
buy_in = 1
while True:
try:
buy_in = int(input("How much are you buying in?\n"))
except ValueError:
print(f"{RED}Please enter a valid integer amount.{RESET}\n")
continue
else:
if buy_in % 50 != 0 or buy_in < 50:
print(
f"{RED}Sorry, we only accept amounts in multiples of 50, like 50, 100, 150...{RESET}\n"
)
continue
return buy_in
def clear_screen():
os.system("cls" if os.name == "nt" else "clear")
def scan_chips(message):
"""
util func getting the money from the user
"""
money = 1
while True:
try:
money = int(input(message))
except ValueError:
print(f"{RED}Please enter a valid integer amount.{RESET}\n")
continue
else:
if money % 50 != 0 or money < 50:
print(
f"{RED}Sorry, we only accept amounts in multiples of 50, like 50, 100, 150...{RESET}\n"
)
continue
return money
def get_player_choice():
print("You can now: ")
print(f"{BLUE}1.{RESET} Hit")
print(f"{BLUE}2.{RESET} Stand")
print(f"{BLUE}3.{RESET} Double-Down")
print(f"{RED}4.{RESET} Surrender\n")
return scan_choice(start=1, end=4)
def scan_choice(start, end):
while True:
try:
choice = int(input(f"What u gonna do? ({start} - {end}): "))
except ValueError:
print(f"{RED}Enter a valid number{RESET}\n")
continue
else:
if choice > 4 or choice < 1:
print(f"{RED}Enter a valid number{RESET}\n")
continue
return choice
def ask_to_play_again(game):
print(f"\nYour chips value at {GREEN}{game.chips}${RESET}\n")
print("Are you willing to play again?")
print(f"{BLUE}1. Yes{RESET}")
print(f"{RED}2. No{RESET}")
choice = scan_choice(1, 2)
handle_play_again_choice(game, choice)
def handle_play_again_choice(game, choice):
if choice == 1:
clear_screen()
game.reset_for_new_hand()
first_round.play_1st_round()
else:
clear_screen()
print(f"{GREEN}Looking forward seeing you again!{RESET}\n")