Added coins

This commit is contained in:
2026-10-10 15:28:42 +02:00
parent 9030146ec8
commit 10a3d93821
7 changed files with 59 additions and 8 deletions
+14 -2
View File
@@ -14,11 +14,23 @@ class UserPlayerGameHandler(GameHandler):
"""
Refresh the screen
"""
print("\033[2J\033[H" + self.game.to_string())
print("\n\033[2J") # Add margin for stupid vscode terminal
game_string = self.game.to_string()
for i, line in enumerate(game_string.splitlines()):
if i == 0:
line += "\tCoins: " + str(self.game.gameState.coins)
elif i == 1:
line += "\tMoves: " + str(self.game.gameState.movesCount)
print(line)
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)}): "))]
user_input = input(f"Enter a movement ({', '.join(self.KEYBOARD_INPUTS)}): ")
if user_input not in self.KEYBOARD_INPUTS:
print(f"Invalid input: {user_input}. Please enter one of {', '.join(self.KEYBOARD_INPUTS)}.")
return self.on_input_request()
return self.game.gameState.PLAYER_MOVEMENTS[self.KEYBOARD_INPUTS.index(user_input)]