Exemplo n.º 1
0
def test_build_ship():
    game_state = initialise_gamestate()
    game = Game(game_state)
    game_state.world.speed = 1000000
    earth = PlanetLocation(1, 1, 3)

    outcome = game.action_build_ship("max", earth, "light_fighter")

    assert not outcome.success

    game.update(24 * 3600)

    success = game.action_upgrade_building("max", earth, "shipyard")

    assert success

    outcome = game.action_build_ship("max", earth, "light_fighter")

    assert not outcome.success

    assert game.action_upgrade_building("max", earth, "research_lab")
    assert game.action_upgrade_research("max", earth, "energy")
    assert game.action_upgrade_research("max", earth, "combustion_drive")

    outcome = game.action_build_ship("max", earth, "light_fighter")
    assert outcome.success

    assert len(game_state.players["max"].fleets) == 1
    assert (
        game_state.players["max"]
        .fleets[0]
        .light_fighter.components[ShipComponent]
        .number
        == 1
    )
Exemplo n.º 2
0
def test_upgrade_research():
    game_state = initialise_gamestate()
    game = Game(game_state)

    game.update(24 * 3600)
    earth = PlanetLocation(1, 1, 3)

    upgrade_success = game.action_upgrade_research("max", earth, "energy")
    assert not upgrade_success

    upgrade_success = game.action_upgrade_building("max", earth, "research_lab")
    assert upgrade_success

    upgrade_success = game.action_upgrade_research("max", earth, "laser")
    assert not upgrade_success

    upgrade_success = game.action_upgrade_research("max", earth, "energy")
    assert upgrade_success

    upgrade_success = game.action_upgrade_research("max", earth, "laser")
    assert not upgrade_success

    upgrade_success = game.action_upgrade_building("max", earth, "research_lab")
    upgrade_sucess = game.action_upgrade_research("max", earth, "energy")

    upgrade_sucess = game.action_upgrade_research("max", earth, "laser")
    assert upgrade_success
Exemplo n.º 3
0
def test_upgrade_building():
    game_state = initialise_gamestate()
    game = Game(game_state)

    upgrade_success = game.action_upgrade_building(
        "max", PlanetLocation(1, 1, 3), "metal_mine"
    )

    assert not upgrade_success

    game.update(3600)

    upgrade_success = game.action_upgrade_building(
        "max", PlanetLocation(1, 1, 3), "metal_mine"
    )

    planet_component = game_state.world.planets[PlanetLocation(1, 1, 3)].components[
        PlanetComponent
    ]

    assert upgrade_success
    assert planet_component.resources[Resources.Metal] < 30 * game_state.world.speed
    assert (
        int(planet_component.resources[Resources.Cristal]) < 20 * game_state.world.speed
    )

    with pytest.raises(AssertionError) as excinfo:
        game.action_upgrade_building("max", "ploup", "metal_mine")

        assert "unkwnown planet" in str(excinfo.value).lower()

    with pytest.raises(AssertionError) as excinfo:
        game.action_upgrade_building("ploup", PlanetLocation(1, 1, 3), "metal_mine")

        assert "unknown player" in str(excinfo.value).lower()
Exemplo n.º 4
0
def test_ids():
    game_state = initialise_gamestate()

    metal_mine = game_state.world.planets[PlanetLocation(1, 1, 3)].buildings[
        "metal_mine"
    ]

    assert metal_mine.components[ProducerComponent]._entity_id == metal_mine.id
    assert metal_mine.id in EntityCatalog.entities_index
Exemplo n.º 5
0
def test_universe_speed():
    game_state = initialise_gamestate()
    game = Game(game_state)
    game_state.world.speed = 10000000
    earth = game_state.world.planets[PlanetLocation(1, 1, 3)]

    game.update(1)

    assert earth.components[PlanetComponent].resources[Resources.Metal] == 10000
Exemplo n.º 6
0
def test_initialise_gamestate():
    game_state = initialise_gamestate()

    assert len(game_state.players) == 1
    assert "max" in game_state.players
    assert game_state.players["max"].components[PlayerComponent].name == "Max"

    assert PlanetLocation(1, 1, 3) in game_state.world.planets
    earth = game_state.world.planets[PlanetLocation(1, 1, 3)]

    assert earth.components[PlanetComponent].name == "Earth"

    metal_mine = earth.buildings["metal_mine"]
    assert metal_mine.components[BuildingComponent].level == 0
Exemplo n.º 7
0
def test_game_update():
    game_state = initialise_gamestate()
    game = Game(game_state)
    earth = game.game_state.world.planets[PlanetLocation(1, 1, 3)]

    game.update(3600)

    assert (
        earth.components[PlanetComponent].resources[Resources.Metal]
        == 30 * game_state.world.speed
    )

    earth.buildings["metal_mine"].components[BuildingComponent].level += 1
    earth.buildings["solar_plant"].components[BuildingComponent].level += 1

    # assert earth.components[PlanetComponent].production_per_second == 800

    game.update(3600)

    assert (
        earth.components[PlanetComponent].resources[Resources.Metal]
        > 60 * game_state.world.speed
    )
Exemplo n.º 8
0
def test_serialise_gamestate():
    game_state = initialise_gamestate()

    game_state_dict = game_state.serialise()

    game_state_string = json.dumps(game_state_dict)