def test_singleton() -> None: bottom_left = Point(0, 0) top_right = Point(100, 100) first_instace = GameMap(bottom_left, top_right) second_instance = GameMap(bottom_left, top_right) assert first_instace is second_instance
def test_adding_tiles() -> None: bottom_left = Point(0, 0) top_right = Point(100, 100) game_map = GameMap(bottom_left, top_right) tile = BasicTile(20, 20) other_object = InteractiveObject() game_map.add_object(tile) assert tile in game_map.container with pytest.raises(InteractiveObject.AddingObjectError) as exc_info: game_map.add_object(other_object) error_message = 'Map should contains BasicTiles only!' assert error_message in str(exc_info.value)
def Load(pathname): """ @return a MapAndEntities tuple containing the game map and the collections of entities created from parsing the map """ if not path.exists(pathname): raise FileNotFoundError map_list = [] player = None workers = [] commuters = [] player_symbols = schema.ENTITIES["player"] worker_symbols = schema.ENTITIES["worker"] commuter_symbols = schema.ENTITIES["commuter"] with open(pathname, 'r') as map_file: row = 0 for line in map_file: line = line.rstrip('\n') col = 0 for char in line: if char in player_symbols: # The map should only contain a single player symbol. assert player == None player = Player("player", True, Point(row, col), char) elif char in worker_symbols: workers.append(Worker("worker", True, Point(row,col), schema.WORKER_SYMBOL)) elif char in commuter_symbols: commuters.append(Commuter("commuter", True, Point(row,col), schema.COMMUTER_SYMBOL)) map_list.append(char) col = col + 1 row = row + 1 assert player != None return MapAndEntities(GameMap.from_list(map_list, schema.NUM_ROWS, schema.NUM_COLS), GameEntities(player, workers, commuters))
# Vertical tunnel, then Horizontal self._create_v_tunnel(prev_y, new_y, prev_x) self._create_h_tunnel(prev_x, new_x, new_y) pass def _create_h_tunnel(self, x1, x2, y): """ Create a tunnel :param int x1: Start of Tunnel :param int x2: End of Tunnel :param int y: The y position of the tunnel """ for x in range(min(x1, x2), max(x1, x2) + 1): self.game_map.tiles[x][y].block(False) def _create_v_tunnel(self, y1, y2, x): """ Create a vertical tunnel :param int y1: Start of Tunnel :param int y2: End of Tunnel :param int x: X position of the tunnel """ for y in range(min(y1, y2), max(y1, y2) + 1): self.game_map.tiles[x][y].block(False) if __name__ == "__main__": test_map = GameMap(80, 25) dungeon = TutorialDungeon(test_map) dungeon.generate(max_rooms=10) print(dungeon.game_map.printable_map())
from user_input.input_handler import InputHandler from Item import DamageItem from game_map.game_map import GameMap from scene_manager import SCENE_MANAGER from game_state_manager import GAME_STATE_MANAGER, GameState from fight_manager import FIGHT_MANAGER from ActionTree import ActionTree # from Inventory import Inventory # CONSTATN INITIALIZATION pygame.init() last_frame_time = 0 tb = termbox.Termbox() input_handler = InputHandler() game_map = GameMap('./game_map/game_map.csv') SCENE_MANAGER['MainMenu'](game_map) # inventory = Inventory(5, 10) # inventory.add_item(DamageItem(500)) #SCENE_MANAGER['FightScene'](inventory) current_game_state = GAME_STATE_MANAGER['CurrentState'] def update_fight(): if FIGHT_MANAGER['CurrentFight'].is_battle_over() == True: if FIGHT_MANAGER['CurrentFight'].get_player_inventory().get_health( ) > 0: FIGHT_MANAGER['CurrentFight'] = None GAME_STATE_MANAGER['CurrentState'] = GameState.MAP SCENE_MANAGER['CurrentScene'] = SCENE_MANAGER['OldScene']