From 7d97befee4b34f399654b9a9447fbd8ec4857ef6 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Fri, 23 Oct 2020 14:53:08 +0200 Subject: [PATCH] Load game externally --- dungeonbattle/game.py | 31 +++++++++++++++++++++++++++++++ main.py | 4 ++-- 2 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 dungeonbattle/game.py diff --git a/dungeonbattle/game.py b/dungeonbattle/game.py new file mode 100644 index 0000000..92d7722 --- /dev/null +++ b/dungeonbattle/game.py @@ -0,0 +1,31 @@ +from .interfaces import Map +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") + while True: + screen.addstr(0, 0, m.draw_string()) + screen.refresh() + 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': + pass # TODO Go up + if key == 's' or key == 'KEY_DOWN': + pass # TODO Go down + if key == 'q' or key == 'KEY_LEFT': + pass # TODO Go left + if key == 'd' or key == 'KEY_RIGHT': + pass # TODO Go right diff --git a/main.py b/main.py index 0eb26bf..a3c6f79 100755 --- a/main.py +++ b/main.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -from dungeonbattle.proof_of_concept import proof_of_concept +from dungeonbattle.game import Game if __name__ == "__main__": - proof_of_concept() + Game().init()