-
Notifications
You must be signed in to change notification settings - Fork 0
/
controller.py
50 lines (35 loc) · 1.24 KB
/
controller.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
"""
Clase controlador, obtiene el input, lo procesa, y manda los mensajes
a los modelos.
"""
from modelos import Snake
import glfw
import sys
from typing import Union
class Controller(object):
model: Union['Snake', None] # Con esto queremos decir que el tipo de modelo es 'Snake' (nuestra clase) ó None
def __init__(self):
self.model = None
self.menu = None
def set_model(self, m):
self.model = m
def set_menu(self,menu):
self.menu = menu
def on_key(self, window, key, scancode, action, mods):
if not (action == glfw.PRESS or action == glfw.RELEASE):
return
if key == glfw.KEY_ESCAPE:
sys.exit()
# Controlador modifica al modelo
elif key == glfw.KEY_LEFT and action == glfw.PRESS:
self.model.move_left()
elif key == glfw.KEY_RIGHT and action == glfw.PRESS:
self.model.move_right()
elif key == glfw.KEY_UP and action == glfw.PRESS:
self.model.move_up()
elif key == glfw.KEY_DOWN and action == glfw.PRESS:
self.model.move_down()
elif key == glfw.KEY_E and action == glfw.PRESS:
self.menu.start = False
else:
print('Unknown key')