mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 10:48:00 +00:00
PlayOrDraw converted to input that appears before opening hand is drawn
This commit is contained in:
1
.gitattributes
vendored
1
.gitattributes
vendored
@@ -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
|
||||
|
||||
78
src/main/java/forge/control/input/InputPlayOrDraw.java
Normal file
78
src/main/java/forge/control/input/InputPlayOrDraw.java
Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.control.input;
|
||||
|
||||
import forge.game.player.Player;
|
||||
import forge.view.ButtonUtil;
|
||||
/**
|
||||
* <p>
|
||||
* InputMulligan class.
|
||||
* </p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id: InputConfirmMulligan.java 21647 2013-05-24 22:31:11Z Max mtg $
|
||||
*/
|
||||
public class InputPlayOrDraw extends InputSyncronizedBase {
|
||||
/** Constant <code>serialVersionUID=-8112954303001155622L</code>. */
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -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<Pair<Player, Card>> list = GameNew.chooseCardsForAnte(currentGame);
|
||||
GameNew.moveCardsToAnte(list);
|
||||
currentGame.getEvents().post(new CardsAntedEvent(list));
|
||||
}
|
||||
|
||||
// Draw <handsize> 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<Pair<Player, Card>> 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 <handsize> 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()
|
||||
/**
|
||||
* <p>
|
||||
* seeWhoPlaysFirstCoinToss.
|
||||
* </p>
|
||||
* @return
|
||||
*/
|
||||
private Player seeWhoPlaysFirstDice(final GameState game) {
|
||||
|
||||
// Play the Flip Coin sound
|
||||
game.getEvents().post(new FlipCoinEvent());
|
||||
|
||||
List<Player> allPlayers = game.getPlayers();
|
||||
return allPlayers.get(MyRandom.getRandom().nextInt(allPlayers.size()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ public abstract class PlayerController {
|
||||
public Card chooseSingleCardForEffect(List<Card> sourceList, SpellAbility sa, String title) { return chooseSingleCardForEffect(sourceList, sa, title, false); }
|
||||
public abstract Card chooseSingleCardForEffect(List<Card> 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<Card> orderBlockers(Card attacker, List<Card> blockers);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user