from typing import Any from .entities.player import Player 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() with TermManager() as term_manager: self._start_game(term_manager.screen) def _start_game(self, screen: Any) -> None: # TODO Generate map, or make the possibility to load another one m = Map.load("example_map.txt") player = Player() self.player = player m.entities.append(player) player.move(1, 6) d = MapDisplay(m, player) while True: screen.clear() screen.refresh() d.display(player.y, player.y) 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()