Search in sources :

Example 21 with Resource

use of games.strategy.engine.data.Resource in project triplea by triplea-game.

the class PlayerAttachment method setSuicideAttackResources.

private void setSuicideAttackResources(final String value) throws GameParseException {
    final String[] s = value.split(":");
    if (s.length != 2) {
        throw new GameParseException("suicideAttackResources must have exactly 2 fields" + thisErrorMsg());
    }
    final int attackValue = getInt(s[0]);
    if (attackValue < 0) {
        throw new GameParseException("suicideAttackResources attack value must be positive" + thisErrorMsg());
    }
    final Resource r = getData().getResourceList().getResource(s[1]);
    if (r == null) {
        throw new GameParseException("no such resource: " + s[1] + thisErrorMsg());
    }
    m_suicideAttackResources.put(r, attackValue);
}
Also used : Resource(games.strategy.engine.data.Resource) GameParseException(games.strategy.engine.data.GameParseException)

Example 22 with Resource

use of games.strategy.engine.data.Resource in project triplea by triplea-game.

the class ResourceCollectionUtilsTest method testExcludeByResources_ShouldIgnoreUnregisteredResources.

@Test
public void testExcludeByResources_ShouldIgnoreUnregisteredResources() {
    final Resource gold = createResource("gold");
    final ResourceCollection unfiltered = createResourceCollection(pus);
    final ResourceCollection filtered = ResourceCollectionUtils.exclude(unfiltered, gold);
    assertThat(filtered.getQuantity(pus), is(unfiltered.getQuantity(pus)));
}
Also used : Resource(games.strategy.engine.data.Resource) ResourceCollection(games.strategy.engine.data.ResourceCollection) Test(org.junit.jupiter.api.Test)

Example 23 with Resource

use of games.strategy.engine.data.Resource in project triplea by triplea-game.

the class ResourceCollectionUtilsTest method testExcludeByNames_ShouldIgnoreUnregisteredResourceNames.

@Test
public void testExcludeByNames_ShouldIgnoreUnregisteredResourceNames() {
    final Resource gold = createResource("gold");
    givenGameResources(pus);
    final ResourceCollection unfiltered = createResourceCollection(pus);
    final ResourceCollection filtered = ResourceCollectionUtils.exclude(unfiltered, gold.getName());
    assertThat(filtered.getQuantity(pus), is(unfiltered.getQuantity(pus)));
}
Also used : Resource(games.strategy.engine.data.Resource) ResourceCollection(games.strategy.engine.data.ResourceCollection) Test(org.junit.jupiter.api.Test)

Example 24 with Resource

use of games.strategy.engine.data.Resource in project triplea by triplea-game.

the class ResourceCollectionUtilsTest method givenGameResources.

private void givenGameResources(final Resource... resources) {
    final ResourceList gameResources = mock(ResourceList.class);
    doReturn(null).when(gameResources).getResource(anyString());
    for (final Resource resource : resources) {
        doReturn(resource).when(gameResources).getResource(resource.getName());
    }
    when(data.getResourceList()).thenReturn(gameResources);
}
Also used : ResourceList(games.strategy.engine.data.ResourceList) Resource(games.strategy.engine.data.Resource)

Example 25 with Resource

use of games.strategy.engine.data.Resource in project triplea by triplea-game.

the class ResourceCollectionUtilsTest method testGetProductionResources_ShouldIncludeAllResourcesExceptTechTokensAndVPs.

@Test
public void testGetProductionResources_ShouldIncludeAllResourcesExceptTechTokensAndVPs() {
    final Resource gold = createResource("gold");
    givenGameResources(gold, pus, techTokens, vps);
    final ResourceCollection unfiltered = createResourceCollection(gold, pus, techTokens, vps);
    final ResourceCollection filtered = ResourceCollectionUtils.getProductionResources(unfiltered);
    assertThat(filtered.getQuantity(gold), is(unfiltered.getQuantity(gold)));
    assertThat(filtered.getQuantity(pus), is(unfiltered.getQuantity(pus)));
    assertThat(filtered.getQuantity(techTokens), is(0));
    assertThat(filtered.getQuantity(vps), is(0));
}
Also used : Resource(games.strategy.engine.data.Resource) ResourceCollection(games.strategy.engine.data.ResourceCollection) Test(org.junit.jupiter.api.Test)

Aggregations

Resource (games.strategy.engine.data.Resource)71 PlayerID (games.strategy.engine.data.PlayerID)22 IntegerMap (games.strategy.util.IntegerMap)16 GameData (games.strategy.engine.data.GameData)15 Unit (games.strategy.engine.data.Unit)15 ArrayList (java.util.ArrayList)15 Territory (games.strategy.engine.data.Territory)14 UnitType (games.strategy.engine.data.UnitType)13 Change (games.strategy.engine.data.Change)11 CompositeChange (games.strategy.engine.data.CompositeChange)11 ProductionRule (games.strategy.engine.data.ProductionRule)10 TripleAUnit (games.strategy.triplea.TripleAUnit)10 NamedAttachable (games.strategy.engine.data.NamedAttachable)9 ResourceCollection (games.strategy.engine.data.ResourceCollection)8 PlayerAttachment (games.strategy.triplea.attachments.PlayerAttachment)7 GameParseException (games.strategy.engine.data.GameParseException)6 UnitAttachment (games.strategy.triplea.attachments.UnitAttachment)6 HashMap (java.util.HashMap)6 HashSet (java.util.HashSet)6 Test (org.junit.jupiter.api.Test)5