Skip to content

Commit 8b2c97e

Browse files
committed
fixed bugs
1 parent f70e324 commit 8b2c97e

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

Dice_game/game.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44
import random
55
#Simple function to clean all terminal and detects your OS
66
def clear_console():
7-
match os.name:
8-
case "nt":
9-
os.system('clear')
10-
case _ :
11-
os.system('clear')
7+
if os.name == "nt":
8+
os.system("cls")
9+
else:
10+
os.system("clear")
1211
#SECTION WHEN "TURNING DICE" AND GIVES A RESULT
1312
def turning_and_result(predict:int):
1413
clear_console()
@@ -33,6 +32,11 @@ def Game_Step1():
3332
print(ASCII_ASSETS["ready?"])
3433
try:
3534
input_number = int(input('Choise a number from 1 to 6\n\n> '))
35+
if input_number > 6 or input_number < 0:
36+
clear_console()
37+
print(" ⚠ That's not a number... redirecting to menu")
38+
time.sleep(3)
39+
menu()
3640
turning_and_result(input_number)
3741
except ValueError:
3842
clear_console()
@@ -46,13 +50,17 @@ def menu():
4650
print(ASCII_ASSETS["TextMenu"])
4751
print(ASCII_ASSETS["Menu_Image"])
4852
input_menu = input('\nPress Enter to play or type "exit" to leave the game\n\n> ')
49-
match input_menu:
50-
case "exit":
51-
exit()
52-
case '' :
53-
Game_Step1()
54-
53+
if input_menu == "":
54+
Game_Step1()
55+
elif input_menu == "exit":
56+
exit()
5557

5658

5759
if __name__ == '__main__':
58-
menu()
60+
try:
61+
menu()
62+
except KeyboardInterrupt:
63+
clear_console()
64+
print(" ⚠ Leaving the game...")
65+
time.sleep(1)
66+
exit()

0 commit comments

Comments
 (0)