""" Represents the current state of the game. Contains : - Player coins - stopGame flag - Player position """ class GameState: PLAYER_MOVEMENTS = ["left_down", "left", "left_up", "up", "right_up", "right", "right_down"] PLAYER_VELOCITIES = [*PLAYER_MOVEMENTS, "down"] def __init__(self): self.playerPosition = (0, 0) self.stopGame = False self.movesCount = 0 self.playerVelocity = -1 # -1 means no velocity self.gameWon = False self.coins = 0 def set_player_position(self, x, y): self.playerPosition = (x, y) def set_player_position(self, position: tuple): self.playerPosition = position def get_player_position(self): return self.playerPosition def set_player_velocity(self, velocity): """Set the player velocity, meaning where the player is currently going """ if velocity not in self.PLAYER_VELOCITIES and velocity != -1: raise ValueError(f"Invalid player velocity: {velocity}. Must be one of {self.PLAYER_VELOCITIES} or -1.") self.playerVelocity = velocity def add_move_count(self, nb=1): self.movesCount += nb def set_stop_game(self, stop): self.stopGame = stop def set_game_won(self, won): self.gameWon = won def add_coin(self): self.coins += 1