from typing import Any from .interfaces import Map from .mapdisplay import MapDisplay from .settings import Settings from .term_manager import TermManager class Game: INSTANCE = None def init(self) -> None: Game.INSTANCE = self self.settings = Settings() self.settings.load_settings() self.settings.write_settings() def new_game(self): # TODO generate a new map procedurally self.m = Map.load("example_map.txt") self.d = MapDisplay(self.m) self.player = Player() self.player.y = 1 self.player.x = 6 @classmethod def load_game(filename): # TODO loading map from a file raise NotImplementedError() def run(self, screen): while True: screen.clear() screen.refresh() self.d.display(self.player.getPosY(), self.player.getPosX()) key = screen.getkey() self.handle_key_pressed(key) def handle_key_pressed(self, key: str) -> None: # TODO load keys from settings if key == 'z' or key == 'KEY_UP': self.player.move_up() if key == 's' or key == 'KEY_DOWN': self.player.move_down() if key == 'q' or key == 'KEY_LEFT': self.player.move_left() if key == 'd' or key == 'KEY_RIGHT': 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) -> None: self.y -= 1 def move_down(self) -> None: self.y += 1 def move_left(self) -> None: self.x -= 1 def move_right(self) -> None: self.x += 1