24 lines
734 B
Python
24 lines
734 B
Python
|
|
from time import sleep
|
|
from game.game import Game
|
|
from game.handlers.gameHandler import GameHandler
|
|
|
|
|
|
class UserPlayerGameHandler(GameHandler):
|
|
KEYBOARD_INPUTS = ["w", "q", "a", "z", "e", "d", "c"]
|
|
|
|
def __init__(self, game: Game):
|
|
super().__init__(game)
|
|
|
|
def on_position_update(self) -> None:
|
|
"""
|
|
Refresh the screen
|
|
"""
|
|
print("\033[2J\033[H" + self.game.to_string())
|
|
sleep(0.1)
|
|
|
|
def on_input_request(self) -> str:
|
|
"""
|
|
Listen for keyboard input, and map it to a gameState PLAYER_MOVEMENTS
|
|
"""
|
|
return self.game.gameState.PLAYER_MOVEMENTS[self.KEYBOARD_INPUTS.index(input(f"Enter a movement ({', '.join(self.KEYBOARD_INPUTS)}): "))] |