-
Notifications
You must be signed in to change notification settings - Fork 0
/
UI.py
99 lines (87 loc) · 2.52 KB
/
UI.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
import os
import time
from Entity import Client
# 菜单可以使用栈来实现返回操作
def ui_menu(client: Client):
"""
:param client:
:return:
"""
menu_option_name = ['Login with a registered account', 'Match a game', 'setting']
menu_option_func = [func_login, func_match, func_setting]
# menu_choice = [str(each+1) for each in range(len(menu_option_name))]
login_fun = [1, 2]
no_login_fun = [0, 2]
available_option = []
print(
" \n"
" Nice to see you! This is a popular board game, UNO!\n"
" \n"
" Powered By Dthcle\n"
" Menu")
if client.is_login:
for each in range(len(login_fun)):
print('\t' + str(each+1) + '.' + menu_option_name[login_fun[each]])
available_option.append(menu_option_func[login_fun[each]])
else:
for each in range(len(no_login_fun)):
print('\t' + str(each+1) + '.' + menu_option_name[no_login_fun[each]])
available_option.append(menu_option_func[no_login_fun[each]])
print(
" \n"
" \t0. Exit\n"
" Please input your choice:"
, end='')
choice = input()
try:
choice = int(choice)
except ValueError:
os.system('cls')
print(
" Irregular input!\n"
, end='')
return
if choice == 0:
print("See you later...")
client.logout()
time.sleep(1)
exit(0)
elif choice <= len(available_option):
available_option[choice-1](client)
else:
os.system('cls')
print(
" Irregular input!")
return
def func_login(client: Client):
os.system('cls')
print(
" To Login Your Account\n"
" Please Input Your Username:"
, end='')
username = input()
print(
" Please input Your Password:"
, end='')
password = input()
client.set_username_password(username, password)
client.login()
def func_match(client: Client):
os.system('cls')
print(
" Please input how many players you want to play with(include yourself)\n"
" (0 to exit)\n"
" How many? Number: "
, end='')
player_num = input()
try:
player_num = int(player_num)
except ValueError:
os.system('cls')
print(
" Irregular input!\n"
, end='')
return
client.match(player_num)
def func_setting(client: Client):
print("setting UI constructing......")