diff --git a/src/game.py b/src/game.py index 1ea2f43..846724f 100644 --- a/src/game.py +++ b/src/game.py @@ -4,7 +4,7 @@ from src.game_client.types.archived_client import ArchivedGameClient from src.game_client.types.remote_client import RemoteGameClient from src.game_map.map import Map -from src.parameters import DEFAULT_ACTION_FILE +from src.parameters import DEFAULT_ACTION_FILE, ARCHIVED_GAME_TURN from src.players.player import Player from src.players.player_manager import PlayerManager @@ -152,7 +152,7 @@ def run(self) -> None: self.__init_game_state() while not self.over.is_set(): - if self.__next_round: + if self.__next_round and not (self.__is_archived_game and ARCHIVED_GAME_TURN[0] <= self.__num_turns): # start next round if need be self.__start_next_round() elif self.__next_turn: @@ -289,7 +289,8 @@ def __start_next_turn(self, game_state: dict = None) -> None: if game_state["finished"]: self.__round_winner_index = game_state["winner"] - self.__print_round_winner() + # TODO add logging enable/disable macro + # self.__print_round_winner() # set the new player win counts self.__set_player_win_counts(game_state) diff --git a/src/game_client/types/archived_client.py b/src/game_client/types/archived_client.py index aa5ef29..ddbb327 100644 --- a/src/game_client/types/archived_client.py +++ b/src/game_client/types/archived_client.py @@ -15,6 +15,9 @@ def __init__(self, file_path: str): with open(os.path.join(REPLAYS_LOCATION, file_path), 'r') as f: self.__archive_file = json.load(f) + self.__max_turn: int = (self.__archive_file["0"]["game_state"]["num_turns"] + 1) \ + * self.__archive_file["0"]["game_state"]["num_rounds"] - 1 + def __enter__(self): return self @@ -67,12 +70,10 @@ def force_turn(self) -> bool: @property def __current_turn(self) -> list[int]: - max_turn: int = self.__archive_file["0"]["game_state"]["num_turns"] - if ARCHIVED_GAME_TURN[0] < 0: ARCHIVED_GAME_TURN[0] = 0 - if ARCHIVED_GAME_TURN[0] > max_turn: - ARCHIVED_GAME_TURN[0] = max_turn + if ARCHIVED_GAME_TURN[0] > self.__max_turn: + ARCHIVED_GAME_TURN[0] = self.__max_turn return ARCHIVED_GAME_TURN diff --git a/src/gui/menus_and_screens/menu.py b/src/gui/menus_and_screens/menu.py index 3b52fda..f45f002 100644 --- a/src/gui/menus_and_screens/menu.py +++ b/src/gui/menus_and_screens/menu.py @@ -21,6 +21,11 @@ def __init__(self, menu_width: int, menu_height: int, start_game_function): self.__create_menu_theme() + self.__create_menu() + + self.__is_enabled = self.__main_menu.is_enabled() + + def __create_menu(self) -> None: # submenus need to be created before main menu self.__create_options_menu() self.__create_multiplayer_menu() @@ -29,8 +34,6 @@ def __init__(self, menu_width: int, menu_height: int, start_game_function): self.__create_credits_menu() self.__create_main_menu() - self.__is_enabled = self.__main_menu.is_enabled() - """Menu callbacks""" @staticmethod @@ -220,6 +223,9 @@ def disable(self) -> None: def enable(self) -> None: play_menu_music(MENU_THEME, MUSIC_VOLUME[0]) + + # Recreate the menu to show new archived game replay + self.__create_menu() self.__main_menu.enable() def draw(self, screen) -> None: