コード例 #1
0
    def handle_suggestion_response(self, player_username, gamecard_item):
        """
        Handles a suggestion response that will prove
        the current player's suggestion false
        """
        #validate request
        self._validate_player(player_username)
        self._validate_suggestion_response_player(player_username)
        self._validate_gamecard_item(gamecard_item)
        self._validate_suggestion_response_player_owns_card(gamecard_item)

        if gamecard_item in game_state.WEAPONS:
            item_type = game_state.WEAPON
        elif gamecard_item in game_state.ROOMS:
            item_type = game_state.ROOM
        else:
            item_type = game_state.SUSPECT

        card = game_state.GameCard(gamecard_item, item_type)

        #show the current player the card
        self.game.current_player.card_items_seen.append(card)

        message = "Player {0} has proven the suggestion false.".format(
            player_username)
        self._send_player_message(message)

        #update the turn status
        self.game.turn_status = game_state.AWAITING_ACCUSATION_OR_END_TURN
        message = "Player {0} must make an accusation " \
            "or end their turn.".format(
            self.game.current_player.username)
        self._send_player_message(message)
コード例 #2
0
 def test_format(self):
     player = game_state.Player(username="******")
     player.suspect = game_state.PLUM
     player.game_cards = [
         game_state.GameCard(item=game_state.WRENCH,
                             item_type=game_state.WEAPON),
         game_state.GameCard(item=game_state.PEACOCK,
                             item_type=game_state.SUSPECT)
     ]
     player_dict = player.format()
     self.assertEqual(player.username, player_dict["username"])
     self.assertEqual(player.suspect, player_dict["suspect"])
     for game_card in player.game_cards:
         self.assertTrue(game_card.format() in player_dict["game_cards"])
     for game_card in player.card_items_seen:
         self.assertTrue(
             game_card.format() in player_dict["card_items_seen"])
コード例 #3
0
 def setUp(self):
     self.game_cards1 = [
         game_state.GameCard(item=game_state.WRENCH,
                             item_type=game_state.WEAPON)
     ]
     self.game_cards2 = [
         game_state.GameCard(item=game_state.REVOLVER,
                             item_type=game_state.WEAPON)
     ]
     self.players = [
         game_state.Player(username="******",
                           suspect=game_state.PLUM,
                           game_cards=self.game_cards1),
         game_state.Player(username="******",
                           suspect=game_state.PEACOCK,
                           game_cards=self.game_cards2)
     ]
     self.game_state = game_state.GameState(game_id="12345",
                                            players=self.players)
コード例 #4
0
    def __init__(self):

        #create a list of GameCard objects for the suspects
        self._suspects = [
            game_state.GameCard(item=item, item_type=game_state.SUSPECT)
            for item in game_state.SUSPECTS
        ]
        #create a list of GameCard objects for the weapons
        self._weapons = [
            game_state.GameCard(item=item, item_type=game_state.WEAPON)
            for item in game_state.WEAPONS
        ]
        #create a list of GameCard objects for the rooms
        self._rooms = [
            game_state.GameCard(item=item, item_type=game_state.ROOM)
            for item in game_state.ROOMS
        ]
        #create a full list of cards
        self._game_cards = self._suspects + self._weapons + self._rooms

        self._winning_cards = list()
コード例 #5
0
 def test_format(self):
     game_card = game_state.GameCard(item=game_state.WRENCH,
                                     item_type=game_state.WEAPON)
     card__dict = game_card.format()
     self.assertEqual(game_card.item, card__dict["item"])
     self.assertEqual(game_card.type, card__dict["item_type"])