-
Notifications
You must be signed in to change notification settings - Fork 0
/
score.py
79 lines (62 loc) · 1.89 KB
/
score.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
import requests
import terminal
from Menu import Menu
def write_score(score, name, game, level, offline):
if offline:
return
url = "http://localhost:3000/highscore/" + game + "/" + level
myobj = {
"name": name,
"points": score
}
x = requests.post(url, json=myobj)
def print_highscore(game, level):
terminal.clear()
url = "http://localhost:3000/highscore/" + game + "/" + level
x = requests.get(url)
x = x.json()
head = f"{'Highscore!':^30s} \n"
head += f"{'-':-^30s}\n"
for score in x:
head += " "
head += str(score['name']).ljust(10)
head += "| "
head += str(score['points']).rjust(2)
head += "\n"
head += f"{'-':-^30s} \n\n"
terminal_menu = Menu(["Back", "Exit"], head)
menu_entry_index = terminal_menu()
if menu_entry_index == 0:
highscore_level(game)
elif menu_entry_index == 1:
exit_game(EXIT_CODE_NONE)
def highscore_level(game):
terminal.clear()
head = f"{'Highscore!':^30s} \n"
head += f"{'-':-^30s} \n"
terminal_menu = Menu(["Leicht", "Mittel", "Schwer", "Back", "Exit"], head)
menu_entry_index = terminal_menu()
if menu_entry_index == 0:
print_highscore(game, "easy")
elif menu_entry_index == 1:
print_highscore(game, "medium")
elif menu_entry_index == 2:
print_highscore(game, "hard")
elif menu_entry_index == 3:
show_highscore()
elif menu_entry_index == 4:
exit_game(EXIT_CODE_NONE)
def show_highscore():
terminal.clear()
head = f"{'Highscore!':^30s} \n"
head += f"{'-':-^30s} \n"
terminal_menu = Menu(["Guessing Game", "Treasure Hunt", "Back", "Exit"], head)
menu_entry_index = terminal_menu()
if menu_entry_index == 0:
highscore_level("guessing_game")
elif menu_entry_index == 1:
highscore_level("treasure_hunt")
elif menu_entry_index == 2:
show_main_menu()
elif menu_entry_index == 3:
exit_game(EXIT_CODE_NONE)