Spikes, better gameHandler, map width and height computed automatically & big peanut hard map
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
from abc import abstractmethod
|
||||
|
||||
from game.game import Game
|
||||
|
||||
|
||||
class GameHandler:
|
||||
def __init__(self, game: Game):
|
||||
self.game = game
|
||||
self.game.set_waiting_for_input_callback(self.on_input_request)
|
||||
self.game.set_position_update_callback(self.on_position_update)
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def run(self) -> None:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def on_position_update(self) -> None:
|
||||
@@ -14,4 +16,6 @@ class GameHandler:
|
||||
|
||||
@abstractmethod
|
||||
def on_input_request(self) -> str:
|
||||
pass
|
||||
pass
|
||||
|
||||
|
||||
@@ -1,14 +1,48 @@
|
||||
|
||||
from time import sleep
|
||||
from game.game import Game
|
||||
from game.handlers.gameHandler import GameHandler
|
||||
|
||||
from game.handlers.gameHandler import GameHandler
|
||||
from game.game import Game
|
||||
from game.gameState import GameState
|
||||
from game.mapReader import MapReader
|
||||
from game.mapSet import MapSet
|
||||
|
||||
class UserPlayerGameHandler(GameHandler):
|
||||
KEYBOARD_INPUTS = ["w", "q", "a", "z", "e", "d", "c"]
|
||||
|
||||
def __init__(self, game: Game):
|
||||
super().__init__(game)
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.mapReader = MapReader()
|
||||
self.mapSet = MapSet(self.mapReader, self.mapReader.get_map_names())
|
||||
self.map = self._choose_map()
|
||||
self.gameState = GameState()
|
||||
self.game = Game(self.map, self.gameState)
|
||||
self.game.set_waiting_for_input_callback(self.on_input_request)
|
||||
self.game.set_position_update_callback(self.on_position_update)
|
||||
|
||||
def _choose_map(self):
|
||||
"""
|
||||
Prompt the user to choose a map from the available maps
|
||||
"""
|
||||
print("\nAvailable maps:")
|
||||
for i, map_name in enumerate(self.mapReader.get_map_names()):
|
||||
print(f"{i + 1}. {map_name.replace("_", " ").title()}")
|
||||
|
||||
while True:
|
||||
try:
|
||||
choice = int(input("Choose a map by number: ")) - 1
|
||||
if 0 <= choice < len(self.mapReader.get_map_names()):
|
||||
return self.mapSet.get_map(choice)
|
||||
else:
|
||||
print("Invalid choice. Please try again.")
|
||||
except ValueError:
|
||||
print("Invalid input. Please enter a number.")
|
||||
|
||||
def run(self) -> None:
|
||||
"""
|
||||
Run the game loop
|
||||
"""
|
||||
self.game.start_game()
|
||||
print("Game over : You " + ("Won!" if self.game.gameState.gameWon else "Lost!"))
|
||||
|
||||
def on_position_update(self) -> None:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user