Exemple #1
0
 def test_create_initial_state(self):
     """
     Purpose:Test creating an initial game state where only the ref can remove
             penguins (no players yet)
     Signature: Void -> Void
     """
     board = FishBoardModel.create_with_same_fish_amount(4, 3, 3)
     game_state = FishGameState(
         board, player_colors=[PlayerColor.RED, PlayerColor.BROWN])
     self.assertEqual([PlayerColor.RED, PlayerColor.BROWN],
                      game_state.get_player_order())
     self.assertEqual(PlayerColor.RED, game_state.get_current_turn())
     self.assertEqual(GamePhase.PLACE_PENGUINS, game_state.get_game_phase())
 def convert_state_to_json(state: FishGameState):
     board = TestHarnessTransformationHelper.convert_board_to_json(
         state.get_board())
     player_order = state.get_player_order()
     current_player_index = player_order.index(state.get_current_turn())
     players = [{
         "color":
         color.value,
         "score":
         state.get_fish_for_player(color),
         "places": [
             TestHarnessTransformationHelper.convert_back_to_posn(
                 coordinate[0], coordinate[1])
             for coordinate in state.get_penguins_for_player(color)
         ]
     } for color in player_order[current_player_index:] +
                player_order[:current_player_index]]
     return {"players": players, "board": board}
 def create_state_window(cls, state: FishGameState) -> Tuple[Tk, Canvas]:
     """
     Purpose: Display the game state overall
     Signature: FishGameState -> TkWindow TkCanvas
     :param state: current state of the game to display
     :return: the state window and canvas the board is drawn on
     """
     board = state.get_board()
     window, canvas = FishBoardView.create_board_window(Tk(), board)
     FishGameStateView.render_penguins(state, canvas)
     order = state.get_player_order()
     fish_dict = dict()
     for color in order:
         fish_dict[color] = state.get_fish_for_player(color)
     FishGameStateView.render_order(order, window)
     FishGameStateView.render_fish(fish_dict, window)
     FishGameStateView.render_game_phase(state.get_game_phase(), window)
     FishGameStateView.render_turn(state.get_current_turn(), window)
     return window, canvas