use of games.strategy.engine.data.UnitType in project triplea by triplea-game.
the class AirThatCantLandUtilTest method testCanLandNeighborLandV2.
@Test
public void testCanLandNeighborLandV2() {
final PlayerID japanese = GameDataTestUtil.japanese(gameData);
final PlayerID americans = GameDataTestUtil.americans(gameData);
final ITestDelegateBridge bridge = getDelegateBridge(japanese);
// we need to initialize the original owner
final InitializationDelegate initDel = (InitializationDelegate) gameData.getDelegateList().getDelegate("initDelegate");
initDel.setDelegateBridgeAndPlayer(bridge);
initDel.start();
initDel.end();
// Get necessary sea zones and unit types for this test
final Territory sz9 = gameData.getMap().getTerritory("9 Sea Zone");
final Territory eastCanada = gameData.getMap().getTerritory("Eastern Canada");
final Territory sz11 = gameData.getMap().getTerritory("11 Sea Zone");
final UnitType subType = GameDataTestUtil.submarine(gameData);
final UnitType carrierType = GameDataTestUtil.carrier(gameData);
final UnitType fighterType = GameDataTestUtil.fighter(gameData);
// Add units for the test
gameData.performChange(ChangeFactory.addUnits(sz11, subType.create(1, japanese)));
gameData.performChange(ChangeFactory.addUnits(sz9, carrierType.create(1, americans)));
gameData.performChange(ChangeFactory.addUnits(sz9, fighterType.create(1, americans)));
// Get total number of defending units before the battle
final int preCountCanada = eastCanada.getUnits().size();
final int preCountAirSz9 = sz9.getUnits().getMatches(Matches.unitIsAir()).size();
// now move to attack
final MoveDelegate moveDelegate = (MoveDelegate) gameData.getDelegateList().getDelegate("move");
bridge.setStepName("CombatMove");
moveDelegate.setDelegateBridgeAndPlayer(bridge);
moveDelegate.start();
moveDelegate.move(sz11.getUnits().getUnits(), gameData.getMap().getRoute(sz11, sz9));
moveDelegate.end();
// fight the battle
final BattleDelegate battle = (BattleDelegate) gameData.getDelegateList().getDelegate("battle");
battle.setDelegateBridgeAndPlayer(bridge);
bridge.setRandomSource(new ScriptedRandomSource(new int[] { 0 }));
bridge.setRemote(getDummyPlayer());
battle.start();
battle.end();
// Get the total number of units that should be left after the planes retreat
final int expectedCountCanada = eastCanada.getUnits().size();
final int postCountInt = preCountCanada + preCountAirSz9;
// Compare the expected count with the actual number of units in landing zone
assertEquals(expectedCountCanada, postCountInt);
}
use of games.strategy.engine.data.UnitType in project triplea by triplea-game.
the class AirThatCantLandUtilTest method testCanLandNeighborLandWithRetreatedBattleV2.
@Test
public void testCanLandNeighborLandWithRetreatedBattleV2() {
final PlayerID japanese = GameDataTestUtil.japanese(gameData);
final PlayerID americans = GameDataTestUtil.americans(gameData);
final ITestDelegateBridge bridge = getDelegateBridge(japanese);
// Get necessary sea zones and unit types for this test
final Territory sz9 = gameData.getMap().getTerritory("9 Sea Zone");
final Territory eastCanada = gameData.getMap().getTerritory("Eastern Canada");
final Territory sz11 = gameData.getMap().getTerritory("11 Sea Zone");
final UnitType subType = GameDataTestUtil.submarine(gameData);
final UnitType carrierType = GameDataTestUtil.carrier(gameData);
final UnitType fighterType = GameDataTestUtil.fighter(gameData);
final UnitType transportType = GameDataTestUtil.transport(gameData);
final UnitType infantryType = GameDataTestUtil.infantry(gameData);
// Add units for the test
gameData.performChange(ChangeFactory.addUnits(sz11, subType.create(1, japanese)));
gameData.performChange(ChangeFactory.addUnits(sz11, transportType.create(1, japanese)));
gameData.performChange(ChangeFactory.addUnits(sz11, infantryType.create(1, japanese)));
gameData.performChange(ChangeFactory.addUnits(sz9, carrierType.create(1, americans)));
gameData.performChange(ChangeFactory.addUnits(sz9, fighterType.create(2, americans)));
// we need to initialize the original owner
final InitializationDelegate initDel = (InitializationDelegate) gameData.getDelegateList().getDelegate("initDelegate");
initDel.setDelegateBridgeAndPlayer(bridge);
initDel.start();
initDel.end();
// Get total number of defending units before the battle
final int preCountCanada = eastCanada.getUnits().size();
final int preCountAirSz9 = sz9.getUnits().getMatches(Matches.unitIsAir()).size();
// now move to attack
final MoveDelegate moveDelegate = (MoveDelegate) gameData.getDelegateList().getDelegate("move");
bridge.setStepName("CombatMove");
moveDelegate.setDelegateBridgeAndPlayer(bridge);
moveDelegate.start();
moveDelegate.move(sz11.getUnits().getUnits(), gameData.getMap().getRoute(sz11, sz9));
moveDelegate.move(sz9.getUnits().getUnits(infantryType, 1), gameData.getMap().getRoute(sz9, eastCanada));
moveDelegate.end();
// fight the battle
final BattleDelegate battle = (BattleDelegate) gameData.getDelegateList().getDelegate("battle");
battle.setDelegateBridgeAndPlayer(bridge);
battle.start();
bridge.setRandomSource(new ScriptedRandomSource(new int[] { 0, 0, 0 }));
bridge.setRemote(getDummyPlayer());
fight(battle, sz9, false);
battle.end();
// Get the total number of units that should be left after the planes retreat
final int expectedCountCanada = eastCanada.getUnits().size();
final int postCountInt = preCountCanada + preCountAirSz9;
// Compare the expected count with the actual number of units in landing zone
assertEquals(expectedCountCanada, postCountInt);
}
use of games.strategy.engine.data.UnitType in project triplea by triplea-game.
the class AiUtilsTest method testCost.
@Test
public void testCost() {
final UnitType infantry = GameDataTestUtil.infantry(gameData);
final PlayerID british = GameDataTestUtil.british(gameData);
assertEquals(3, AiUtils.getCost(infantry, british, gameData));
}
use of games.strategy.engine.data.UnitType in project triplea by triplea-game.
the class SimpleUnitPanel method addUnits.
private void addUnits(final PlayerID player, final int quantity, final NamedAttachable unit, final boolean damaged, final boolean disabled) {
final JLabel label = new JLabel();
label.setText(" x " + quantity);
if (unit instanceof UnitType) {
final Optional<ImageIcon> icon = uiContext.getUnitImageFactory().getIcon((UnitType) unit, player, damaged, disabled);
icon.ifPresent(label::setIcon);
} else if (unit instanceof Resource) {
label.setIcon(uiContext.getResourceImageFactory().getIcon(unit, true));
}
add(label);
}
use of games.strategy.engine.data.UnitType in project triplea by triplea-game.
the class MyFormatterTest method unitsToText_ShouldPluralizeTextWhenMultipleUnitsOwnedBySamePlayer.
@Test
public void unitsToText_ShouldPluralizeTextWhenMultipleUnitsOwnedBySamePlayer() {
final PlayerID playerId = newPlayerId("playerId");
final UnitType unitType = newUnitType("unitType");
final Collection<Unit> units = Arrays.asList(newUnit(unitType, playerId), newUnit(unitType, playerId));
assertThat(MyFormatter.unitsToText(units), is("2 unitTypes owned by the playerId"));
}
Aggregations