-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame_solution.py
More file actions
86 lines (67 loc) · 2.24 KB
/
game_solution.py
File metadata and controls
86 lines (67 loc) · 2.24 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
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
## runs in 1280x720
import tkinter as tk
import game_manager
import menu_manager
# class to handle the interactions between menus (game over, pause and main menu) and the game
# also handles when the game is started
class Handler:
def __init__(self):
self.swidth, self.sheight = 1280, 720
self.window = tk.Tk()
self.window.bind("<Key>", self.check_boss_key)
self.window.title("Nuclear Whiskers")
self.window.geometry(f"{self.swidth}x{self.sheight}")
self.bindings = {"Move Right":"d", "Move Left":"a", "Interact":"e", "Reload":"r", "Heal":"2", "Melee":"3", "Boss Button":"o", "Cheats": "p"}
self.game = game_manager.GameManager(self)
self.menu = menu_manager.MenuManager(self)
self.state = "menu"
def get_swidth(self):
return self.swidth
def get_sheight(self):
return self.sheight
def get_window(self):
return self.window
def get_bindings(self):
return self.bindings
def get_state(self):
return self.state
def get_current_game_save_info(self):
return self.game.get_save_info()
def get_current_game_score(self):
return self.game.get_score()
def set_bindings(self, bindings):
self.bindings = bindings
# called each time a state of the game is changed
# displays the correct menu or the game depending on which state it it
def set_state(self, state):
self.state = state
if state == "menu":
self.menu.get_current_frame().pack()
elif state == "game":
self.menu.destroy_current_frame()
self.game.setup_game_loop()
elif state == "pause":
self.menu.pause()
self.menu.get_current_frame().pack()
elif state == "resume":
self.state = "game"
self.menu.destroy_current_frame()
self.game.resume()
elif state == "game_over":
self.menu.game_over()
self.menu.get_current_frame().pack()
elif state == "load_game":
self.state = "game"
self.game.setup_game_loop(self.menu.get_loaded_game())
# minimise application if boss button is pressed
def check_boss_key(self, event):
if event.char == self.bindings["Boss Button"] and self.state != "menu":
self.game.on_escape_key_pressed(None)
self.window.iconify()
# function called to load the application
def loop(self):
self.menu.get_current_frame().pack()
self.window.mainloop()
if __name__ == "__main__":
handler = Handler()
handler.loop()