示例#1
0
class TestGame():
    def setup_class(self):
        self.player_1 = Player('bene', 'Bene', 0)
        self.player_2 = Player('lara', 'Lara', 1)
        self.player_3 = Player('thilo', 'Thilo', 2)
        self.player_4 = Player('bibi', 'Bibi', 3)
        self.game = Brandi('ABCD', seed=1, host=self.player_1)

    def test_pre_start_game(self):
        assert self.game.game_state == 0
        assert self.game.players['bene'].username == 'Bene'
        assert len(self.game.players.values()) == 1

    def test_player_join(self):
        self.game.player_join(self.player_2)
        self.game.player_join(self.player_3)
        self.game.player_join(self.player_4)

        assert len(self.game.players.values()) == 4
        assert self.game.players['lara'].username == 'Lara'

    def test_change_teams(self):
        self.game.change_postion(self.player_1, 2)

        assert self.game.players['thilo'].position == 0
        assert self.game.players['lara'].position == 1
        assert self.game.players['bene'].position == 2

    def test_start_game(self):
        self.game.start_game()

        assert hasattr(self.game.players['bene'], 'starting_node')
        assert isinstance(self.game.players['bene'].starting_node, GameNode)
class TestGame():
    def setup_class(self):
        self.id1 = User('Bene', 0)
        self.id2 = User('Lara', 1)
        self.id3 = User('Thilo', 2)
        self.id4 = User('Bibi', 3)
        self.game = Brandi('ABCD', seed=1, host=self.id1)

    def test_pre_start_game(self):
        assert self.game.game_state == 0
        assert self.game.players[0].username == 'Bene'
        assert len(self.game.players.values()) == 1

    def test_player_join(self):
        self.game.player_join(self.id2)
        self.game.player_join(self.id3)
        self.game.player_join(self.id4)

        assert len(self.game.order) == 4
        assert self.game.players[1].username == 'Lara'

    def test_change_teams(self):
        self.game.change_teams([self.id1, self.id3, self.id2, self.id4])

        assert self.game.players[1].username == 'Lara'
        assert self.game.players[2].username == 'Thilo'
        assert self.game.order == [0, 2, 1, 3]

    def test_start_game(self):
        self.game.start_game()

        assert hasattr(self.game.players[0], 'starting_node')
        assert isinstance(self.game.players[0].starting_node, EntryExitNode)
示例#3
0
async def initialize_new_game(player: User = Depends(get_current_user),
                              game_name: str = Body(...),
                              seed: int = None,
                              debug: bool = False):
    """
    Start a new game.
    """
    # check if the game_name is an empty string
    if not game_name:
        raise HTTPException(status_code=HTTP_400_BAD_REQUEST,
                            detail="Please enter a game name.")
    # check for duplicate name
    if game_name in [game.game_name for game in games.values()]:
        raise HTTPException(status_code=HTTP_400_BAD_REQUEST,
                            detail='A game with this name already exists.')

    game_id = ''.join(random.choice(string.ascii_uppercase) for i in range(4))
    while game_id in games:
        # generate new game ids until a new id is found
        game_id = ''.join(
            random.choice(string.ascii_uppercase) for i in range(4))

    games[game_id] = Brandi(game_id,
                            game_name=game_name,
                            host=player,
                            seed=seed,
                            debug=debug)

    await sio_emit_game_list()

    token = create_game_token(game_id)

    return {'game_token': token, 'game_id': game_id}
示例#4
0
 def setup_class(self):
     self.player_1 = Player('bene', 'Bene', 0)
     self.player_2 = Player('lara', 'Lara', 1)
     self.player_3 = Player('thilo', 'Thilo', 2)
     self.player_4 = Player('bibi', 'Bibi', 3)
     self.game = Brandi('ABCD', seed=1, host=self.player_1)
 def setup_class(self):
     self.id1 = User('Bene', 0)
     self.id2 = User('Lara', 1)
     self.id3 = User('Thilo', 2)
     self.id4 = User('Bibi', 3)
     self.game = Brandi('ABCD', seed=1, host=self.id1)