-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenu.py
More file actions
54 lines (46 loc) · 1.55 KB
/
Copy pathmenu.py
File metadata and controls
54 lines (46 loc) · 1.55 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
import pygame
import utils.menu_items as menu_items
from env import games
class MenuSelector:
usernames = []
def __init__(self):
self._start_menu()
def check_startmenu(self, response):
if response:
username = response['Username']
game_code = response['Game Code']
if username and game_code:
retcode = self.uname_status(username)
if self.check_gc(game_code):
return retcode
return None
def check_gc(self, game_code):
if game_code in games.keys():
return games[game_code]
return None
def uname_status(self, username):
if username not in self.usernames:
self.usernames.append(username)
return 0
return 1
def update(self):
events = pygame.event.get()
self.menu.update(events)
if self.menu.response:
ret = self.menu.response.copy()
self.menu.response = None
return ret
return None
def _start_menu(self):
self.menu = menu_items.Menu()
self.menu.add_object(menu_items.Button(50,300, 32, 'Submit'))
self.menu.add_object(menu_items.InputBox(50, 100, 200, 32, 'Username'))
self.menu.add_object(menu_items.InputBox(50, 200, 200, 32, 'Game Code'))
if __name__ == '__main__':
ms = MenuSelector()
while True:
ret = ms.update()
if ret:
print('Ret:', ret)
retcode = ms.check_startmenu(ret)
print('retcode:', retcode)