-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUI_manager.py
131 lines (103 loc) · 3.84 KB
/
UI_manager.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
import os
import art
from profile_manager import Profile_Manager
class UIManager:
def __init__(self) -> None:
"""Empty init for the UIManager"""
pass
def show_main_menu(self, title):
"""UI for Main Menu"""
self.clear_screen()
print(art.logo)
print(title + "\n")
print("1. Play Wordle")
print("2. See scoreboards")
print("3. See profiles")
print("4. Add word to wordlist")
print("5. Remove word from wordlist")
print("\nPress any other button to quit")
choice = input("(1 / 2 / 3 / 4 / 5): ")
return choice
def game_mode(self):
"""UI for Game Mode selection"""
self.clear_screen()
print(art.game_mode)
print("Pick Game Mode:")
print("1. Normal\n\t5 letter word, 5 guesses\n")
print("2. Squadrant\n\t4 letter word, 6 guesses\n")
print("3. Rule of 7\n\t7 letter word, 7 guesses\n")
mode = input("(1 / 2 / 3):\n")
return mode
def see_scoreboards(self):
"""UI to choose a scoreboard"""
self.clear_screen()
print(art.scoreboard)
print("Choose scoreboard")
print("1. Normal Mode")
print("2. Squadrant")
print("3. Rule of 7")
print("(1 / 2 / 3):")
choice = input()
return choice
def see_specified_scoreboard(self, scoreboard, title, number_of_lines):
"""UI for Specified scoreboard"""
# clear screen and show UI
self.clear_screen()
print(art.scoreboard)
print(" -- " + title + " -- ")
# Check there is any data in the file
if number_of_lines == 0:
print("No data available for this game mode\n")
input("Press Enter to quit")
else:
# base the number of spaces on the longest word in the file
longest_word_length = max([len(word) for word in scoreboard])
for i in range(number_of_lines):
# find correct number of spaces
number_of_spaces = (2 * longest_word_length - len(scoreboard[i])) // 2
spaces = " " * number_of_spaces
# Words of odd length need one more space
if len(scoreboard[i]) % 2 == 0:
print("|" + spaces + scoreboard[i] + spaces + "|")
else:
print("|" + spaces + scoreboard[i] + spaces + " |")
input("\nPress Enter to quit\n")
def see_profiles(self):
"""UI to see profiles"""
self.clear_screen()
print(art.profiles)
pf = Profile_Manager()
pf.get_profiles()
pf.print_profiles()
print("\n*Note that only the highest score of each user is shown.")
print("For further details, see High Scores page")
input("\nPress enter to quit\n")
def add_remove_word(self, operation):
"""UI to add or remove a word"""
self.clear_screen()
print(art.settings)
print(f"First enter the length of the word that you want to {operation}")
print("(Must be 4, 5, or 7)")
def play_round(self):
os.system("cls" if os.name == "nt" else "clear")
print(art.logo)
print("Previous Guesses")
print("-----------------")
def lose_game(self, answer):
print(art.lost)
print(f"You lost. The Answer was: {answer}")
def win_game(self, answer):
print(art.celebration)
print(f"The answer is {answer}")
def print_previous_guesses(self, guesses):
top_line = "| "
bottom_line = "| "
for guess in guesses:
top_line += guess[0] + " | "
bottom_line += guess[1] + " | "
print(top_line)
print(bottom_line)
print()
def clear_screen(self):
"""Clears the screen"""
os.system("cls" if os.name == "nt" else "clear")