Ejemplo n.º 1
0
def test_save_move_in_and_out_tokyo():
    repository_play = IRepositoryPlay()
    repository_game = IRepositoryGame()
    repository_game.save_game('Room3')
    repository_player = IRepositoryPlayer()
    repository_player.save_player('Godzilla3', 'Room3')
    assert repository_play.save_move_in_and_out_tokyo('Godzilla3', 'Room3',
                                                      '1', 10, 10, 10).id == 3
Ejemplo n.º 2
0
def test_get_play_by_id():
    repository_play = IRepositoryPlay()
    repository_game = IRepositoryGame()
    repository_game.save_game('Room4')
    repository_player = IRepositoryPlayer()
    repository_player.save_player('Godzilla4', 'Room4')
    repository_play.save_play_card_swept('Godzilla4', 'Room4', '04', '1', '05',
                                         '1', '06', '1', '1', 10, 10, 10)
    assert repository_play.get_play_by_id(4).card1_swept == '04'
Ejemplo n.º 3
0
def test_save_play_card_purchased_db():
    repository_play = IRepositoryPlay()
    repository_game = IRepositoryGame()
    repository_game.save_game('Room2')
    repository_player = IRepositoryPlayer()
    repository_player.save_player('Godzilla2', 'Room2')
    assert repository_play.save_play_card_purchased('Godzilla2', 'Room2', '01',
                                                    '1', '1', 10, 10,
                                                    10).id == 2
Ejemplo n.º 4
0
def test_delete_dice_by_id():
    repository_play = IRepositoryPlay()
    repository_game = IRepositoryGame()
    repository_game.save_game('Room12')
    repository_player = IRepositoryPlayer()
    repository_player.save_player('Godzilla12', 'Room12')
    repository_play.save_play_card_swept('Godzilla12', 'Room12', '01', '1',
                                         '02', '1', '03', '1', '1', 10, 10, 10)
    assert repository_play.delete_play_by_id(12) is None
Ejemplo n.º 5
0
def test_save_play_card_swept_db():
    repository_play = IRepositoryPlay()
    repository_game = IRepositoryGame()
    repository_game.save_game('Room1')
    repository_player = IRepositoryPlayer()
    repository_player.save_player('Godzilla1', 'Room1')
    assert repository_play.save_play_card_swept('Godzilla1', 'Room1', '01',
                                                '1', '02', '1', '03', '1', '1',
                                                10, 10, 10).id == 1
Ejemplo n.º 6
0
def test_get_plays_by_player_and_room():
    repository_play = IRepositoryPlay()
    repository_game = IRepositoryGame()
    repository_game.save_game('Room5')
    repository_player = IRepositoryPlayer()
    repository_player.save_player('Godzilla5', 'Room5')
    repository_play.save_play_card_swept('Godzilla5', 'Room5', '04', '1', '05',
                                         '1', '06', '1', '1', 10, 10, 10)
    assert repository_play.get_plays_by_player_and_room(
        'Godzilla5', 'Room5').card2_swept == '05'
Ejemplo n.º 7
0
    def buy_card_request_handler(self, data):
        username, room, game, state = reconstruct_game(data)

        if username != state.players.current_player.username:
            return

        index_to_buy = data['payload']
        try:
            bought = state.deck_handler.buy_card_from_store(
                index_to_buy, state.players.current_player,
                state.players.get_all_alive_players_minus_current_player())
            if bought:
                i_repository_play = IRepositoryPlay()
                i_repository_play.save_play_card_purchased(
                    username, room, bought.name, bought.card_type,
                    state.players.current_player.location,
                    state.players.current_player.victory_points,
                    state.players.current_player.energy,
                    state.players.current_player.current_health)

            if isinstance(bought, DropFromHighAltitude):
                if state.players.get_count_in_tokyo_ignore_current_player(
                ) > 1:
                    self.trigger_force_yield_choice(username, state, room)
                else:
                    move_players_out_of_tokyo(
                        state.players.
                        get_all_alive_players_minus_current_player())
                    state.players.current_player.move_to_tokyo()

            current_card_store = state.deck_handler.json_store()
            self.send_to_client(CARD_STORE_RESPONSE, username, room,
                                current_card_store)

            self.update_player_status(state, username, room, game)

            self.send_to_client(
                SERVER_RESPONSE, username, room,
                "{} bought {}!".format(state.players.current_player.username,
                                       bought.name))
        except InsufficientFundsException:
            self.send_to_client(
                SERVER_RESPONSE, username, room,
                "{} tried to buy {} but has insufficient energy!".format(
                    username, state.deck_handler.store[index_to_buy].name))

        save_game(game, state)
Ejemplo n.º 8
0
def test_update_play_card_purchased():
    repository_play = IRepositoryPlay()
    repository_game = IRepositoryGame()
    repository_game.save_game('Room7')
    repository_player = IRepositoryPlayer()
    repository_player.save_player('Godzilla7', 'Room7')
    repository_play.save_play_card_purchased('Godzilla7', 'Room7', '01', '1',
                                             '1', 10, 10, 10)
    repository_play.update_play_card_purchased_by_id(7, '21', '1')
    assert repository_play.get_play_by_id(7).card_purchased == '21'
Ejemplo n.º 9
0
def test_update_play_card_location_by_id():
    repository_play = IRepositoryPlay()
    repository_game = IRepositoryGame()
    repository_game.save_game('Room8')
    repository_player = IRepositoryPlayer()
    repository_player.save_player('Godzilla8', 'Room8')
    repository_play.save_play_card_purchased('Godzilla8', 'Room8', '01', '1',
                                             '1', 10, 10, 10)
    repository_play.update_play_location_by_id(8,
                                               locations.Locations.TOKYO.value)
    assert repository_play.get_play_by_id(8).location == '1'
Ejemplo n.º 10
0
def test_update_play_card_swept():
    repository_play = IRepositoryPlay()
    repository_game = IRepositoryGame()
    repository_game.save_game('Room6')
    repository_player = IRepositoryPlayer()
    repository_player.save_player('Godzilla6', 'Room6')
    repository_play.save_play_card_swept('Godzilla6', 'Room6', '01', '1', '02',
                                         '1', '03', '1', '1', 10, 10, 10)
    repository_play.update_play_card_swept_by_id(6, '10', '1', '12', '1', '13',
                                                 '1')
    assert repository_play.get_play_by_id(6).card3_swept == '13'
Ejemplo n.º 11
0
def test_update_play_card_health_by_id():
    repository_play = IRepositoryPlay()
    repository_game = IRepositoryGame()
    repository_game.save_game('Room11')
    repository_player = IRepositoryPlayer()
    repository_player.save_player('Godzilla11', 'Room11')
    repository_play.save_play_card_purchased('Godzilla11', 'Room11', '01', '1',
                                             '1', 10, 10, 10)
    repository_play.update_play_health_by_id(11, constants.DEFAULT_HEALTH)
    assert repository_play.get_play_by_id(
        11).health_points == constants.DEFAULT_HEALTH
Ejemplo n.º 12
0
def test_update_play_card_energy_by_id():
    repository_play = IRepositoryPlay()
    repository_game = IRepositoryGame()
    repository_game.save_game('Room10')
    repository_player = IRepositoryPlayer()
    repository_player.save_player('Godzilla10', 'Room10')
    repository_play.save_play_card_purchased('Godzilla10', 'Room10', '01', '1',
                                             '1', 10, 10, 10)
    repository_play.update_play_energy_by_id(10,
                                             constants.ENERGY_HOARDER_DIVIDER)
    assert repository_play.get_play_by_id(
        10).energy_cube == constants.ENERGY_HOARDER_DIVIDER
Ejemplo n.º 13
0
def test_update_play_card_victory_point_by_id():
    repository_play = IRepositoryPlay()
    repository_game = IRepositoryGame()
    repository_game.save_game('Room9')
    repository_player = IRepositoryPlayer()
    repository_player.save_player('Godzilla9', 'Room9')
    repository_play.save_play_card_purchased('Godzilla9', 'Room9', '01', '1',
                                             '1', 10, 10, 10)
    repository_play.update_play_victory_points_by_id(
        9, constants.VICTORY_POINTS_TO_WIN)
    assert repository_play.get_play_by_id(
        9).victory_points == constants.VICTORY_POINTS_TO_WIN
Ejemplo n.º 14
0
    def card_store_sweep_request_handler(self, data):
        username, room, game, state = reconstruct_game(data)
        if state.players.current_player.username == username:
            cards_swept = state.deck_handler.store.copy()
            print("Cards to be swept {}".format(cards_swept))

            successfully_swept_cardstore = state.deck_handler.sweep_store(
                state.players.current_player)

            if successfully_swept_cardstore is None:
                i_repository_play = IRepositoryPlay()
                i_repository_play.save_play_card_swept(
                    username, room, cards_swept[2].name,
                    cards_swept[2].card_type, cards_swept[1].name,
                    cards_swept[1].card_type, cards_swept[0].name,
                    cards_swept[0].card_type,
                    state.players.current_player.location,
                    state.players.current_player.victory_points,
                    state.players.current_player.energy,
                    state.players.current_player.current_health)
            cards_swept.clear()

            if not successfully_swept_cardstore:
                message = "{} does not have enough funds to sweep the card store!".format(
                    username)
                self.send_to_client(SERVER_RESPONSE, username, room, message)
        else:
            print("{} tried to sweep out of turn!".format(username))

        self.update_player_status(state, username, room, game)

        selected_cards_ui_message = state.deck_handler.json_store()
        self.send_to_client(CARD_STORE_RESPONSE, username, room,
                            selected_cards_ui_message)

        save_game(game, state)