2020-10-23 12:53:08 +00:00
|
|
|
from .interfaces import Map
|
2020-10-23 13:00:59 +00:00
|
|
|
from .mapdisplay import MapDisplay
|
2020-10-23 12:53:08 +00:00
|
|
|
from .term_manager import TermManager
|
|
|
|
|
|
|
|
|
|
|
|
class Game:
|
|
|
|
INSTANCE = None
|
|
|
|
|
|
|
|
def init(self) -> None:
|
|
|
|
Game.INSTANCE = self
|
|
|
|
with TermManager() as term_manager:
|
|
|
|
self._start_game(term_manager.screen)
|
|
|
|
|
|
|
|
def _start_game(self, screen):
|
|
|
|
# TODO Generate map, or make the possibility to load another one
|
|
|
|
m = Map.load("example_map.txt")
|
2020-10-23 13:14:19 +00:00
|
|
|
player = Player()
|
|
|
|
self.player = player
|
|
|
|
player.y = 1
|
|
|
|
player.x = 6
|
|
|
|
d = MapDisplay(m, player)
|
2020-10-23 12:53:08 +00:00
|
|
|
while True:
|
2020-10-23 13:40:32 +00:00
|
|
|
screen.clear()
|
2020-10-23 12:53:08 +00:00
|
|
|
screen.refresh()
|
2020-10-23 13:40:32 +00:00
|
|
|
d.display(player.getPosY(), player.getPosX())
|
2020-10-23 12:53:08 +00:00
|
|
|
key = screen.getkey()
|
|
|
|
self.handle_key_pressed(key)
|
|
|
|
|
|
|
|
def handle_key_pressed(self, key):
|
|
|
|
# TODO load keys from settings
|
|
|
|
if key == 'z' or key == 'KEY_UP':
|
2020-10-23 13:14:19 +00:00
|
|
|
self.player.move_up()
|
2020-10-23 12:53:08 +00:00
|
|
|
if key == 's' or key == 'KEY_DOWN':
|
2020-10-23 13:14:19 +00:00
|
|
|
self.player.move_down()
|
2020-10-23 12:53:08 +00:00
|
|
|
if key == 'q' or key == 'KEY_LEFT':
|
2020-10-23 13:14:19 +00:00
|
|
|
self.player.move_left()
|
2020-10-23 12:53:08 +00:00
|
|
|
if key == 'd' or key == 'KEY_RIGHT':
|
2020-10-23 13:14:19 +00:00
|
|
|
self.player.move_right()
|
|
|
|
|
|
|
|
|
|
|
|
class Player:
|
|
|
|
# FIXME Should be elsewhere, only useful to don't break the previous code
|
|
|
|
y: int = 0
|
|
|
|
x: int = 0
|
|
|
|
|
|
|
|
def move_up(self):
|
|
|
|
self.y -= 1
|
|
|
|
|
|
|
|
def move_down(self):
|
|
|
|
self.y += 1
|
|
|
|
|
|
|
|
def move_left(self):
|
|
|
|
self.x -= 1
|
|
|
|
|
|
|
|
def move_right(self):
|
|
|
|
self.x += 1
|
|
|
|
|
|
|
|
def getPosX(self):
|
|
|
|
return self.x
|
|
|
|
|
|
|
|
def getPosY(self):
|
|
|
|
return self.y
|