Code refactoring in game.Game

This commit is contained in:
Charles Peyrat 2020-10-23 18:01:39 +02:00
parent 9c8a352ecd
commit f3bc3101f0
1 changed files with 15 additions and 11 deletions

View File

@ -8,25 +8,29 @@ class Game:
def init(self) -> None: def init(self) -> None:
Game.INSTANCE = self Game.INSTANCE = self
with TermManager() as term_manager: self.key_handler = player_move
self._start_game(term_manager.screen)
def _start_game(self, screen): def new_game(self):
# TODO Generate map, or make the possibility to load another one # TODO generate a new map procedurally
m = Map.load("example_map.txt") m = Map.load("example_map.txt")
player = Player() self.player = Player()
self.player = player self.player.y = 1
player.y = 1 self.player.x = 6
player.x = 6
d = MapDisplay(m, player) @classmethod
def load_game(filename):
# TODO loading map from a file
raise NotImplementedError()
def run(self, screen):
while True: while True:
screen.clear() screen.clear()
screen.refresh() screen.refresh()
d.display(player.getPosY(), player.getPosX()) d.display(player.getPosY(), player.getPosX())
key = screen.getkey() key = screen.getkey()
self.handle_key_pressed(key) self.key_handler(key)
def handle_key_pressed(self, key): def player_move(self, key):
# TODO load keys from settings # TODO load keys from settings
if key == 'z' or key == 'KEY_UP': if key == 'z' or key == 'KEY_UP':
self.player.move_up() self.player.move_up()