Search in sources :

Example 71 with PlayerID

use of games.strategy.engine.data.PlayerID 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));
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) UnitType(games.strategy.engine.data.UnitType) Test(org.junit.jupiter.api.Test)

Example 72 with PlayerID

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

the class ParserTest method testPlayerProduction.

@Test
public void testPlayerProduction() {
    final ProductionFrontier cf = gameData.getProductionFrontierList().getProductionFrontier("canProd");
    final PlayerID can = gameData.getPlayerList().getPlayerId("chretian");
    assertEquals(cf, can.getProductionFrontier());
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) ProductionFrontier(games.strategy.engine.data.ProductionFrontier) Test(org.junit.jupiter.api.Test)

Example 73 with PlayerID

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

the class PlayerChooser method createComponents.

private void createComponents() {
    final Collection<PlayerID> players = new ArrayList<>(this.players.getPlayers());
    if (allowNeutral) {
        players.add(PlayerID.NULL_PLAYERID);
    }
    list = new JList<>(players.toArray(new PlayerID[0]));
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    list.setSelectedValue(defaultPlayer, true);
    list.setFocusable(false);
    list.setCellRenderer(new PlayerChooserRenderer(uiContext));
    list.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(final MouseEvent evt) {
            if (evt.getClickCount() == 2) {
                // set OK_OPTION on DoubleClick, this fires a property change which causes the dialog to close()
                setValue(OK_OPTION);
            }
        }
    });
    setMessage(SwingComponents.newJScrollPane(list));
    final int maxSize = 700;
    final int suggestedSize = this.players.size() * 40;
    final int actualSize = suggestedSize > maxSize ? maxSize : suggestedSize;
    setPreferredSize(new Dimension(300, actualSize));
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) MouseEvent(java.awt.event.MouseEvent) ArrayList(java.util.ArrayList) MouseAdapter(java.awt.event.MouseAdapter) Dimension(java.awt.Dimension)

Example 74 with PlayerID

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

the class PlayersPanel method showPlayers.

public static void showPlayers(final IGame game, final Component parent) {
    final JPanel panel = JPanelBuilder.builder().verticalBoxLayout().build();
    for (final String player : game.getPlayerManager().getPlayers()) {
        final PlayerID playerId = game.getData().getPlayerList().getPlayerId(player);
        if (playerId.isAi()) {
            panel.add(new JLabel(playerId.getWhoAmI().split(":")[1] + " is " + playerId.getName(), JLabel.RIGHT));
        } else {
            panel.add(new JLabel(game.getPlayerManager().getNode(player).getName() + " is " + playerId.getName(), JLabel.RIGHT));
        }
    }
    JOptionPane.showMessageDialog(JOptionPane.getFrameForComponent(parent), panel, "Players", JOptionPane.PLAIN_MESSAGE);
}
Also used : JPanel(javax.swing.JPanel) PlayerID(games.strategy.engine.data.PlayerID) JLabel(javax.swing.JLabel)

Example 75 with PlayerID

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

the class PoliticalStateOverview method getRelationshipLabel.

/**
 * Gets a label showing the coloured relationshipName between these two
 * players.
 */
private JPanel getRelationshipLabel(final PlayerID player1, final PlayerID player2) {
    RelationshipType relType = null;
    for (final Triple<PlayerID, PlayerID, RelationshipType> changesSoFar : editChanges) {
        if ((player1.equals(changesSoFar.getFirst()) && player2.equals(changesSoFar.getSecond())) || (player2.equals(changesSoFar.getFirst()) && player1.equals(changesSoFar.getSecond()))) {
            relType = changesSoFar.getThird();
        }
    }
    if (relType == null) {
        data.acquireReadLock();
        try {
            relType = data.getRelationshipTracker().getRelationshipType(player1, player2);
        } finally {
            data.releaseReadLock();
        }
    }
    final JComponent relationshipLabel = getRelationshipComponent(player1, player2, relType);
    final JPanel relationshipLabelPanel = new JPanel();
    relationshipLabelPanel.add(relationshipLabel);
    relationshipLabelPanel.setBackground(getRelationshipTypeColor(relType));
    return relationshipLabelPanel;
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) JPanel(javax.swing.JPanel) RelationshipType(games.strategy.engine.data.RelationshipType) JComponent(javax.swing.JComponent)

Aggregations

PlayerID (games.strategy.engine.data.PlayerID)323 Territory (games.strategy.engine.data.Territory)163 Unit (games.strategy.engine.data.Unit)133 Test (org.junit.jupiter.api.Test)122 TripleAUnit (games.strategy.triplea.TripleAUnit)104 ITestDelegateBridge (games.strategy.engine.data.ITestDelegateBridge)94 GameData (games.strategy.engine.data.GameData)90 ArrayList (java.util.ArrayList)79 UnitType (games.strategy.engine.data.UnitType)74 Route (games.strategy.engine.data.Route)67 ScriptedRandomSource (games.strategy.engine.random.ScriptedRandomSource)46 HashSet (java.util.HashSet)44 Change (games.strategy.engine.data.Change)29 CompositeChange (games.strategy.engine.data.CompositeChange)29 IntegerMap (games.strategy.util.IntegerMap)29 List (java.util.List)29 HashMap (java.util.HashMap)28 Collection (java.util.Collection)27 Resource (games.strategy.engine.data.Resource)25 UnitAttachment (games.strategy.triplea.attachments.UnitAttachment)23