diff --git a/.gitattributes b/.gitattributes
index 0f53032df45..2b818c085be 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -14170,6 +14170,7 @@ src/main/java/forge/control/input/InputPayManaOfCostPayment.java -text
src/main/java/forge/control/input/InputPayManaSimple.java svneol=native#text/plain
src/main/java/forge/control/input/InputPayManaX.java -text
src/main/java/forge/control/input/InputPayment.java -text
+src/main/java/forge/control/input/InputPlayOrDraw.java -text
src/main/java/forge/control/input/InputProliferate.java -text
src/main/java/forge/control/input/InputQueue.java svneol=native#text/plain
src/main/java/forge/control/input/InputSelectCards.java -text
diff --git a/src/main/java/forge/control/input/InputPlayOrDraw.java b/src/main/java/forge/control/input/InputPlayOrDraw.java
new file mode 100644
index 00000000000..6d8aeedfbf1
--- /dev/null
+++ b/src/main/java/forge/control/input/InputPlayOrDraw.java
@@ -0,0 +1,78 @@
+/*
+ * Forge: Play Magic: the Gathering.
+ * Copyright (C) 2011 Forge Team
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package forge.control.input;
+
+import forge.game.player.Player;
+import forge.view.ButtonUtil;
+ /**
+ *
+ * InputMulligan class.
+ *
+ *
+ * @author Forge
+ * @version $Id: InputConfirmMulligan.java 21647 2013-05-24 22:31:11Z Max mtg $
+ */
+public class InputPlayOrDraw extends InputSyncronizedBase {
+ /** Constant serialVersionUID=-8112954303001155622L. */
+ private static final long serialVersionUID = -8112954303001155622L;
+
+ private final Player startingPlayer;
+ private final boolean firstGame;
+ private boolean willPlayFirst = true;
+
+ public InputPlayOrDraw(Player startsGame, boolean isFirstGame) {
+ startingPlayer = startsGame;
+ firstGame = isFirstGame;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public final void showMessage() {
+ ButtonUtil.setButtonText("Play", "Draw");
+ ButtonUtil.enableAllFocusOk();
+
+ StringBuilder sb = new StringBuilder();
+ sb.append(startingPlayer.getName()).append(", you ").append(firstGame ? " have won the coin toss." : " lost the last game.");
+ sb.append("\n\n");
+ sb.append("Would you like to play or draw?");
+ showMessage(sb.toString());
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ protected final void onOk() {
+ willPlayFirst = true;
+ done();
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ protected final void onCancel() {
+ willPlayFirst = false;
+ done();
+ }
+
+ private void done() {
+ ButtonUtil.reset();
+ stop();
+ }
+
+ public final boolean isPlayingFirst() {
+ return willPlayFirst;
+ }
+}
diff --git a/src/main/java/forge/game/MatchController.java b/src/main/java/forge/game/MatchController.java
index 61782add51f..933f7dfa308 100644
--- a/src/main/java/forge/game/MatchController.java
+++ b/src/main/java/forge/game/MatchController.java
@@ -18,6 +18,7 @@ import forge.game.event.FlipCoinEvent;
import forge.game.player.LobbyPlayer;
import forge.game.player.Player;
import forge.properties.ForgePreferences.FPref;
+import forge.util.Aggregates;
import forge.util.MyRandom;
/**
@@ -104,34 +105,29 @@ public class MatchController {
currentGame = new GameState(players, gameType, this);
- try {
- FControl.SINGLETON_INSTANCE.attachToGame(currentGame);
+ FControl.SINGLETON_INSTANCE.attachToGame(currentGame);
- final boolean canRandomFoil = Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_RANDOM_FOIL) && gameType == GameType.Constructed;
- GameNew.newGame(currentGame, canRandomFoil, this.useAnte);
+ final boolean canRandomFoil = Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_RANDOM_FOIL) && gameType == GameType.Constructed;
+ GameNew.newGame(currentGame, canRandomFoil, this.useAnte);
- if (useAnte) { // Deciding which cards go to ante
- List> list = GameNew.chooseCardsForAnte(currentGame);
- GameNew.moveCardsToAnte(list);
- currentGame.getEvents().post(new CardsAntedEvent(list));
- }
-
- // Draw cards
- for (final Player p1 : currentGame.getPlayers()) {
- p1.drawCards(p1.getMaxHandSize());
- }
-
- currentGame.setAge(GameAge.Mulligan);
- } catch (Exception e) {
- BugReporter.reportException(e);
+ if (useAnte) { // Deciding which cards go to ante
+ List> list = GameNew.chooseCardsForAnte(currentGame);
+ GameNew.moveCardsToAnte(list);
+ currentGame.getEvents().post(new CardsAntedEvent(list));
}
- final Player firstPlayer = determineFirstTurnPlayer(getLastGameOutcome(), currentGame);
-
// This code was run from EDT.
currentGame.getInputQueue().invokeGameAction(new Runnable() {
@Override
public void run() {
+ final Player firstPlayer = determineFirstTurnPlayer(getLastGameOutcome(), currentGame);
+
+ // Draw cards
+ for (final Player p1 : currentGame.getPlayers()) {
+ p1.drawCards(p1.getMaxHandSize());
+ }
+
+ currentGame.setAge(GameAge.Mulligan);
currentGame.getAction().mulligan(firstPlayer);
}
});
@@ -236,20 +232,15 @@ public class MatchController {
return 10;
}
- /**
- * TODO: Write javadoc for this method.
- * @param match
- * @param game
- */
+
private Player determineFirstTurnPlayer(final GameOutcome lastGameOutcome, final GameState game) {
// Only cut/coin toss if it's the first game of the match
Player goesFirst = null;
- final String message;
- //Player humanPlayer = Singletons.getControl().getPlayer();
+
boolean isFirstGame = lastGameOutcome == null;
if (isFirstGame) {
- goesFirst = seeWhoPlaysFirstDice(game);
- message = goesFirst + " has won the coin toss.";
+ game.getEvents().post(new FlipCoinEvent()); // Play the Flip Coin sound
+ goesFirst = Aggregates.random(game.getPlayers());
} else {
for(Player p : game.getPlayers()) {
if(!lastGameOutcome.isWinner(p.getLobbyPlayer())) {
@@ -257,28 +248,10 @@ public class MatchController {
break;
}
}
- message = goesFirst + " lost the last game.";
}
-
- boolean willPlay = goesFirst.getController().getWillPlayOnFirstTurn(message);
+
+ boolean willPlay = goesFirst.getController().getWillPlayOnFirstTurn(isFirstGame);
goesFirst = willPlay ? goesFirst : goesFirst.getOpponent();
return goesFirst;
}
-
- // decides who goes first when starting another game, used by newGame()
- /**
- *
- * seeWhoPlaysFirstCoinToss.
- *
- * @return
- */
- private Player seeWhoPlaysFirstDice(final GameState game) {
-
- // Play the Flip Coin sound
- game.getEvents().post(new FlipCoinEvent());
-
- List allPlayers = game.getPlayers();
- return allPlayers.get(MyRandom.getRandom().nextInt(allPlayers.size()));
- }
-
}
diff --git a/src/main/java/forge/game/player/PlayerController.java b/src/main/java/forge/game/player/PlayerController.java
index 59e627e78b4..19cb937ca2e 100644
--- a/src/main/java/forge/game/player/PlayerController.java
+++ b/src/main/java/forge/game/player/PlayerController.java
@@ -118,7 +118,7 @@ public abstract class PlayerController {
public Card chooseSingleCardForEffect(List sourceList, SpellAbility sa, String title) { return chooseSingleCardForEffect(sourceList, sa, title, false); }
public abstract Card chooseSingleCardForEffect(List sourceList, SpellAbility sa, String title, boolean isOptional);
public abstract boolean confirmAction(SpellAbility sa, PlayerActionConfirmMode mode, String message);
- public abstract boolean getWillPlayOnFirstTurn(String message);
+ public abstract boolean getWillPlayOnFirstTurn(boolean isFirstGame);
public abstract boolean confirmStaticApplication(Card hostCard, GameEntity affected, String logic, String message);
public abstract List orderBlockers(Card attacker, List blockers);
diff --git a/src/main/java/forge/game/player/PlayerControllerAi.java b/src/main/java/forge/game/player/PlayerControllerAi.java
index e47cec4a10a..b310630b218 100644
--- a/src/main/java/forge/game/player/PlayerControllerAi.java
+++ b/src/main/java/forge/game/player/PlayerControllerAi.java
@@ -166,7 +166,7 @@ public class PlayerControllerAi extends PlayerController {
}
@Override
- public boolean getWillPlayOnFirstTurn(String message) {
+ public boolean getWillPlayOnFirstTurn(boolean isFirstGame) {
return true; // AI is brave :)
}
@Override
diff --git a/src/main/java/forge/game/player/PlayerControllerHuman.java b/src/main/java/forge/game/player/PlayerControllerHuman.java
index 50ff8918a89..2a653932297 100644
--- a/src/main/java/forge/game/player/PlayerControllerHuman.java
+++ b/src/main/java/forge/game/player/PlayerControllerHuman.java
@@ -12,6 +12,7 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import forge.Card;
+import forge.FThreads;
import forge.GameEntity;
import forge.card.mana.Mana;
import forge.card.replacement.ReplacementEffect;
@@ -24,8 +25,10 @@ import forge.control.input.InputBlock;
import forge.control.input.InputCleanup;
import forge.control.input.InputConfirmMulligan;
import forge.control.input.InputPassPriority;
+import forge.control.input.InputPlayOrDraw;
import forge.control.input.InputSelectCards;
import forge.control.input.InputSelectCardsFromList;
+import forge.control.input.InputSynchronized;
import forge.deck.CardPool;
import forge.deck.Deck;
import forge.deck.DeckSection;
@@ -275,14 +278,10 @@ public class PlayerControllerHuman extends PlayerController {
}
@Override
- public boolean getWillPlayOnFirstTurn(String message) {
- final String[] possibleValues = { "Play", "Draw" };
-
- final Object playDraw = JOptionPane.showOptionDialog(null, message + "\n\nWould you like to play or draw?",
- "Play or Draw?", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null,
- possibleValues, possibleValues[0]);
-
- return !playDraw.equals(1);
+ public boolean getWillPlayOnFirstTurn(boolean isFirstGame) {
+ InputPlayOrDraw inp = new InputPlayOrDraw(player, isFirstGame);
+ game.getInputQueue().setInputAndWait(inp);
+ return inp.isPlayingFirst();
}
@Override