Skip to content

Commit

Permalink
Recreating menu when enabling game. Fixed some bugs (lol)
Browse files Browse the repository at this point in the history
  • Loading branch information
MegatronJeremy committed Aug 25, 2024
1 parent 248fbf3 commit 48df498
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
7 changes: 4 additions & 3 deletions src/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 5 additions & 4 deletions src/game_client/types/archived_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
10 changes: 8 additions & 2 deletions src/gui/menus_and_screens/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 48df498

Please sign in to comment.