-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart_menu.py
More file actions
57 lines (45 loc) · 2.54 KB
/
Copy pathstart_menu.py
File metadata and controls
57 lines (45 loc) · 2.54 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
55
56
57
import pygame
import pickle
import requests
import globals
from globals import *
from utils import *
from settings import *
class StartMenu():
def __init__(self, main_screen: pygame.Surface, timer: pygame.time.Clock) -> None:
self.main_screen = main_screen
self.greeting_font = get_font(100)
self.greeting_text = self.greeting_font.render("Zuckerberg's IDE", True, (255, 255, 255))
self.greeting_text_rect = self.greeting_text.get_rect(center=(self.main_screen.get_width() / 2, self.main_screen.get_height() * 0.15))
self.prompt_text_font = get_font(30)
self.prompt_text = self.prompt_text_font.render("Enter your HC ID and password and click START!", True, (255, 255, 255))
self.prompt_text_rect = self.prompt_text.get_rect(center=(self.main_screen.get_width() / 2, (self.main_screen.get_height() / 2) - 100))
self.hc_input_box = InputBox((self.main_screen.get_width() / 2, self.main_screen.get_height() / 2), 50)
self.password_input_box = InputBox((self.main_screen.get_width() / 2, (self.main_screen.get_height() / 2) + 80), 50, isPassword=True)
self.start_button = Button(None, (self.main_screen.get_width() / 2, (self.main_screen.get_height() / 2) + 200), "START", get_font(50), (255, 255, 255), (192, 34, 200))
def OnEvent(self, event: pygame.event.Event):
self.hc_input_box.OnEvent(event)
self.password_input_box.OnEvent(event)
if event.type == pygame.MOUSEBUTTONDOWN:
if self.start_button.checkForInput(pygame.mouse.get_pos()):
dictToSend = {"hcid": str(self.hc_input_box.text), "password": str(self.password_input_box.text) }
res = requests.post(f'{BASE_URL}/login', json=dictToSend, timeout=5)
if res.status_code == 401:
# Unauthorized
pass
else:
with open('currentUser', 'wb') as f:
pickle.dump(str(self.hc_input_box.text), f)
globals.StartChallenge()
print('Started!')
def Update(self, dt):
self.hc_input_box.Update(dt)
self.password_input_box.Update(dt)
return None
def Render(self):
self.main_screen.fill((0, 0, 0))
self.main_screen.blit(self.greeting_text, self.greeting_text_rect)
self.main_screen.blit(self.prompt_text, self.prompt_text_rect)
self.hc_input_box.Render(self.main_screen)
self.password_input_box.Render(self.main_screen)
self.start_button.update(self.main_screen)