Exemplo n.º 1
0
def test_register_map_adds_new_map_to_maps():
    base_map = generate_valid_map()
    test_map = generate_valid_map()

    game = BaseGame(initial_map=base_map, initial_map_name="base map")
    game.register_map("test map", test_map)

    assert game.maps["test map"] is test_map
    assert len(game.maps) == 2
Exemplo n.º 2
0
def test_change_map_sets_active_screen():
    base_map = generate_valid_map()
    test_map = generate_valid_map()

    game = BaseGame(initial_map=base_map, initial_map_name="bae map")
    game.register_map("test map", test_map)
    game.change_map("test map")

    assert game.active_screen is test_map
Exemplo n.º 3
0
def test_register_warp_zone_correctly_adds_large_zone(x_pos, y_pos, final_x, final_y):

    test_map = generate_valid_map()
    warp_map = generate_valid_map()

    test_map.register_warp_zone(
        x_pos, y_pos, warp_map, 0, 0, final_x_pos=final_x, final_y_pos=final_y
    )

    assert (0, 0, 1, 1, warp_map, 0, 0) in test_map._warp_zones
Exemplo n.º 4
0
def test_registering_warp_zone_outside_warp_location_raises_exception():

    test_map = generate_valid_map()

    # Try to create a warp zone to 10, 10 in a 2x2 sheet.
    with pytest.raises(Map.InvalidWarpZoneLocationException):
        test_map.register_warp_zone(0, 0, test_map, 10, 10)
Exemplo n.º 5
0
def test_register_warp_zone_correctly_adds_zone():

    test_map = generate_valid_map()

    test_map.register_warp_zone(0, 0, test_map, 0, 0)

    assert (0, 0, 0, 0, test_map, 0, 0) in test_map._warp_zones
Exemplo n.º 6
0
def test_open_menu_with_invalid_menu_name_raises_value_error():
    base_map = generate_valid_map()

    game = BaseGame(initial_map=base_map)

    with pytest.raises(ValueError):
        game.open_menu("test")
Exemplo n.º 7
0
def test_change_map_to_invalid_map_throws_exception():
    base_map = generate_valid_map()

    game = BaseGame(initial_map=base_map)

    with pytest.raises(ValueError):
        game.change_map("Invalid map name.")
Exemplo n.º 8
0
def test_shutdown_stops_the_game(event_post_mock):
    base_map = generate_valid_map()
    quit_event = pygame.event.Event(pygame.QUIT, dict=None)

    game = BaseGame(initial_map=base_map)
    game.shutdown()

    event_post_mock.assert_called_with(quit_event)
Exemplo n.º 9
0
def test_creating_game_with_initial_map_sets_active_screen_and_maps():
    test_map = generate_valid_map()

    game = BaseGame(initial_map=test_map, initial_map_name="test map")

    assert game.active_screen is test_map
    assert game.active_menu is None
    assert game.maps["test map"] is test_map
Exemplo n.º 10
0
def test_clear_player_controlled_objects_clears_them():

    game = BaseGame(initial_map=generate_valid_map())
    game.register_player_controlled_object(PlayerControlledObject("sprite.png"), 0, 0)
    game.register_player_controlled_object(PlayerControlledObject("sprite.png"), 0, 1)

    game.clear_player_controlled_objects()

    assert game.player_controlled_objects == {}
Exemplo n.º 11
0
def test_register_player_controlled_object_correctly_registers():
    pco = PlayerControlledObject("sprite.txt")

    game = BaseGame(initial_map=generate_valid_map())

    game.register_player_controlled_object(pco, 1, 2)

    assert game.player_controlled_objects[pco] == (1, 2)
    assert len(game.player_controlled_objects) == 1
Exemplo n.º 12
0
def test_open_menu_unloads_current_map(unload_map_mock):
    base_map = generate_valid_map()
    base_menu = get_base_menu()

    game = BaseGame(initial_map=base_map)
    game.register_menu("menu", base_menu)

    game.open_menu("menu")

    assert unload_map_mock.called
Exemplo n.º 13
0
def test_loading_a_game_with_no_menu_loads_the_active_map(
        load_map_mock, event_get_mock):
    event_get_mock.return_value = [DummyEvent(pygame.QUIT)]

    game_map = generate_valid_map()
    game = BaseGame(initial_map=game_map)
    engine = Engine(game)

    engine.start()

    assert load_map_mock.called
Exemplo n.º 14
0
def test_load_player_controlled_objects_loads_them():

    game = BaseGame(initial_map=generate_valid_map())
    pco1 = PlayerControlledObject("sprite.png")
    pco2 = PlayerControlledObject("sprite.png")
    load_map = Map([[pco1, pco2]], [[0, 0]], [[0, 0]], [[0, 0]], validate=False)

    game.load_player_controlled_objects(load_map)

    assert pco1 in game.player_controlled_objects
    assert pco2 in game.player_controlled_objects
    assert game.player_controlled_objects[pco1] == (0, 0)
    assert game.player_controlled_objects[pco2] == (1, 0)