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))
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 update(model, msg, audio_api): begin = lambda *args: args[-1] def assign(o, a, v): o.__setattr__(a, v) case_of = { (StartScreenState, LeftMouseDownAt): lambda: begin(audio_api.stop_music(), GameState()), (StartScreenState, Tick): lambda: begin((assign(model, 'time', msg.time)), (audio_api.play_music('music') if not model.music_playing else None), (assign(model, 'music_playing', True)), model) } # if isinstance(model, StartScreenState): # if isinstance(msg, LeftMouseDownAt): # audio_api.stop_music() # return GameState() # if isinstance(msg, Tick): # if not model.music_playing: # audio_api.play_music('music') # model.music_playing = True # model.time = msg.time # return model for condition in case_of: stateClass, msgClass = condition if isinstance(model, stateClass) and isinstance(msg, msgClass): return case_of[condition]() if isinstance(model, GameState): return update_gamestate(model, msg, audio_api) if isinstance(model, GameOverState): if isinstance(msg, LeftMouseDownAt): return StartScreenState() return model
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_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_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))
def game_underway(): model = GameState() return model
def test_mouse_movement_over_game_screen(log): game = GameState() mouse_events = [MouseMovedTo((x, x)) for x in range(0, 500, 10)] result = simulate_main_event_loop(game, mouse_events, log) verify(print_scenario(mouse_events, result, log))
def game_underway(): return GameState()