def test_slash_red_win(log):
    game = GameState()
    player_moves = [
        ColumnWasClicked(c) for c in [0, 1, 1, 2, 2, 3, 2, 3, 3, 5, 3]
    ]
    result = simulate_main_event_loop(game, player_moves, log)
    verify(print_scenario(player_moves, result, log))
예제 #2
0
def update_gamestate(gamestate, msg, audio_api):
    if isinstance(msg, Tick):
        gamestate.time = msg.time
        if (gamestate.mouse_down_time and
                gamestate.time > gamestate.mouse_down_time + DROP_DELAY_MS):
            gamestate.mouse_down_time = None
            gamestate = update(
                gamestate,
                ColumnWasClicked(convert_to_column(gamestate.mouse_pos[0])),
                audio_api)
    if isinstance(msg, MouseMovedTo):
        gamestate.mouse_pos = msg.pos
    if (isinstance(msg, LeftMouseDownAt)
            and convert_to_column(msg.pos[0]) is not None):
        gamestate.mouse_down = msg.pos
        gamestate.mouse_down_time = gamestate.time
    if isinstance(msg, LeftMouseUpAt):
        gamestate.mouse_down_time = None
    if isinstance(msg, ColumnWasClicked):
        if gamestate.board[(msg.column, 0)] != EMPTY:
            audio_api.play_sound('blocked')
        else:
            audio_api.play_sound('drop')
            gamestate.juice = 10
            gamestate.board = place_brick(gamestate.board,
                                          gamestate.whos_turn_is_it,
                                          msg.column)
            gamestate.whos_turn_is_it = (gamestate.whos_turn_is_it + 1) % 2
            for color in [RED, YELLOW]:
                won = check_winning_state(gamestate.board, color)
                if won:
                    gamestate = GameOverState(winner=color,
                                              board=gamestate.board)
    return gamestate
def test_backslash_yellow_win(log):
    game = GameState()
    player_moves = [
        ColumnWasClicked(c)
        for c in [0, 6, 5, 5, 4, 4, 3, 4, 5, 3, 0, 3, 0, 3]
    ]
    result = simulate_main_event_loop(game, player_moves, log)
    verify(print_scenario(player_moves, result, log))
def test_letting_yellow_win_horisontally(log):
    game = GameState()
    player_moves = [ColumnWasClicked(c) for c in [0, 1, 0, 2, 0, 3, 1, 4]]
    result = simulate_main_event_loop(game, player_moves, log)
    verify(print_scenario(player_moves, result, log))
def test_letting_red_win(log):
    game = GameState()
    player_moves = [ColumnWasClicked(0),
                    ColumnWasClicked(1)] * 3 + [ColumnWasClicked(0)]
    result = simulate_main_event_loop(game, player_moves, log)
    verify(print_scenario(player_moves, result, log))
def test_placing_too_many_bricks_in_first_column(log):
    game = GameState()
    player_moves = [ColumnWasClicked(0)] * 8
    result = simulate_main_event_loop(game, player_moves, log)
    verify(print_scenario(player_moves, result, log))
def test_first_placed_brick_is_red(log):
    game = GameState()
    player_moves = [ColumnWasClicked(0)]
    result = simulate_main_event_loop(game, player_moves, log)
    verify(print_scenario(player_moves, result, log))