Code refactoring in game.Game
This commit is contained in:
parent
9c8a352ecd
commit
f3bc3101f0
|
@ -8,25 +8,29 @@ class Game:
|
|||
|
||||
def init(self) -> None:
|
||||
Game.INSTANCE = self
|
||||
with TermManager() as term_manager:
|
||||
self._start_game(term_manager.screen)
|
||||
self.key_handler = player_move
|
||||
|
||||
def _start_game(self, screen):
|
||||
# TODO Generate map, or make the possibility to load another one
|
||||
def new_game(self):
|
||||
# TODO generate a new map procedurally
|
||||
m = Map.load("example_map.txt")
|
||||
player = Player()
|
||||
self.player = player
|
||||
player.y = 1
|
||||
player.x = 6
|
||||
d = MapDisplay(m, player)
|
||||
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()
|
||||
d.display(player.getPosY(), player.getPosX())
|
||||
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
|
||||
if key == 'z' or key == 'KEY_UP':
|
||||
self.player.move_up()
|
||||
|
|
Loading…
Reference in New Issue