Search in sources :

Example 1 with UserActionAttachment

use of games.strategy.triplea.attachments.UserActionAttachment in project triplea by triplea-game.

the class TripleAPlayer method userActions.

private void userActions(final boolean firstRun) {
    if (getPlayerBridge().isGameOver()) {
        return;
    }
    final IUserActionDelegate userActionDelegate;
    try {
        userActionDelegate = (IUserActionDelegate) getPlayerBridge().getRemoteDelegate();
    } catch (final ClassCastException e) {
        final String errorContext = "PlayerBridge step name: " + getPlayerBridge().getStepName() + ", Remote class name: " + getPlayerBridge().getRemoteDelegate().getClass();
        // for some reason the client is not seeing or getting these errors, so print to err too
        System.err.println(errorContext);
        ClientLogger.logQuietly(errorContext, e);
        throw new IllegalStateException(errorContext, e);
    }
    final UserActionAttachment actionChoice = ui.getUserActionChoice(getPlayerId(), firstRun, userActionDelegate);
    if (actionChoice != null) {
        userActionDelegate.attemptAction(actionChoice);
        userActions(false);
    }
}
Also used : IUserActionDelegate(games.strategy.triplea.delegate.remote.IUserActionDelegate) UserActionAttachment(games.strategy.triplea.attachments.UserActionAttachment)

Example 2 with UserActionAttachment

use of games.strategy.triplea.attachments.UserActionAttachment in project triplea by triplea-game.

the class UserActionPanelTest method testCanPlayerAffordUserAction_ShouldReturnFalseWhenUserActionCostGreaterThanPlayerPUs.

@Test
public void testCanPlayerAffordUserAction_ShouldReturnFalseWhenUserActionCostGreaterThanPlayerPUs() {
    givenGameHasPuResource();
    final PlayerID player = createPlayer();
    final UserActionAttachment userAction = createUserActionWithCost(player.getResources().getQuantity(pus) + 1);
    final boolean canAffordUserAction = UserActionPanel.canPlayerAffordUserAction(player, userAction);
    assertThat(canAffordUserAction, is(false));
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) UserActionAttachment(games.strategy.triplea.attachments.UserActionAttachment) Test(org.junit.jupiter.api.Test)

Example 3 with UserActionAttachment

use of games.strategy.triplea.attachments.UserActionAttachment in project triplea by triplea-game.

the class UserActionPanelTest method testCanPlayerAffordUserAction_ShouldReturnTrueWhenUserActionCostIsZeroAndPlayerPUsIsZero.

@Test
public void testCanPlayerAffordUserAction_ShouldReturnTrueWhenUserActionCostIsZeroAndPlayerPUsIsZero() {
    givenGameHasPuResource();
    final PlayerID player = createPlayer();
    final UserActionAttachment userAction = createUserActionWithCost(0);
    final boolean canAffordUserAction = UserActionPanel.canPlayerAffordUserAction(player, userAction);
    assertThat(canAffordUserAction, is(true));
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) UserActionAttachment(games.strategy.triplea.attachments.UserActionAttachment) Test(org.junit.jupiter.api.Test)

Example 4 with UserActionAttachment

use of games.strategy.triplea.attachments.UserActionAttachment in project triplea by triplea-game.

the class UserActionPanelTest method testCanPlayerAffordUserAction_ShouldReturnTrueWhenUserActionCostEqualToPlayerPUs.

@Test
public void testCanPlayerAffordUserAction_ShouldReturnTrueWhenUserActionCostEqualToPlayerPUs() {
    givenGameHasPuResource();
    final PlayerID player = createPlayer();
    final UserActionAttachment userAction = createUserActionWithCost(player.getResources().getQuantity(pus));
    final boolean canAffordUserAction = UserActionPanel.canPlayerAffordUserAction(player, userAction);
    assertThat(canAffordUserAction, is(true));
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) UserActionAttachment(games.strategy.triplea.attachments.UserActionAttachment) Test(org.junit.jupiter.api.Test)

Example 5 with UserActionAttachment

use of games.strategy.triplea.attachments.UserActionAttachment in project triplea by triplea-game.

the class UserActionPanelTest method createUserActionWithCost.

private UserActionAttachment createUserActionWithCost(final int costInPUs) {
    final UserActionAttachment userAction = new UserActionAttachment("userAction", mock(Attachable.class), data);
    userAction.setCostPu(costInPUs);
    return userAction;
}
Also used : UserActionAttachment(games.strategy.triplea.attachments.UserActionAttachment) Attachable(games.strategy.engine.data.Attachable)

Aggregations

UserActionAttachment (games.strategy.triplea.attachments.UserActionAttachment)7 PlayerID (games.strategy.engine.data.PlayerID)4 Test (org.junit.jupiter.api.Test)4 Attachable (games.strategy.engine.data.Attachable)1 IUserActionDelegate (games.strategy.triplea.delegate.remote.IUserActionDelegate)1 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 Insets (java.awt.Insets)1 JButton (javax.swing.JButton)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1