diff --git a/src/main/java/forge/AllZone.java b/src/main/java/forge/AllZone.java index 57fee057a7b..15756459743 100644 --- a/src/main/java/forge/AllZone.java +++ b/src/main/java/forge/AllZone.java @@ -53,7 +53,7 @@ public final class AllZone implements NewConstants { private static CardFactoryInterface cardFactory = null; /** Constant inputControl. */ - private static final InputControl INPUT_CONTROL = new InputControl(); + private static final InputControl INPUT_CONTROL = new InputControl(Singletons.getModel()); /** Game state observer gameInfo collects statistics and players' performance. */ private static GameSummary gameInfo = new GameSummary(); @@ -65,8 +65,6 @@ public final class AllZone implements NewConstants { //initialized at Runtime since it has to be the last object constructed - /** Global computer. */ - private static ComputerAI_Input computer; //shared between Input_Attack, Input_Block, Input_CombatDamage , InputState_Computer @@ -318,25 +316,6 @@ public final class AllZone implements NewConstants { return Singletons.getModel().getGameState().getTriggerHandler(); } - /** - *

getComputer.

- * - * @return a {@link forge.ComputerAI_Input} object. - * @since 1.0.15 - */ - public static ComputerAI_Input getComputer() { - return computer; - } - - /** - *

setComputer.

- * - * @param input a {@link forge.ComputerAI_Input} object. - * @since 1.0.15 - */ - public static void setComputer(final ComputerAI_Input input) { - computer = input; - } /** *

getCombat.

diff --git a/src/main/java/forge/gui/input/InputControl.java b/src/main/java/forge/gui/input/InputControl.java index 15955403562..fbdd4db2529 100644 --- a/src/main/java/forge/gui/input/InputControl.java +++ b/src/main/java/forge/gui/input/InputControl.java @@ -1,10 +1,16 @@ package forge.gui.input; -import forge.*; import java.util.LinkedList; import java.util.Stack; +import forge.ComputerAI_Input; +import forge.Constant; +import forge.MyObservable; +import forge.Phase; +import forge.Player; +import forge.model.FModel; + /** *

InputControl class.

* @@ -22,13 +28,24 @@ public class InputControl extends MyObservable implements java.io.Serializable { private Stack resolvingStack = new Stack(); private LinkedList resolvingQueue = new LinkedList(); + private final FModel model; + private ComputerAI_Input aiInput; // initialized at runtime to be the latest object created + + /** + * TODO: Write javadoc for Constructor. + * @param model + */ + public InputControl(FModel fModel) { + model = fModel; + } + /** *

Setter for the field input.

* * @param in a {@link forge.gui.input.Input} object. */ public void setInput(final Input in) { - if (AllZone.getStack().getResolving() || !(input == null || input instanceof Input_PassPriority)) + if (model.getGameState().getStack().getResolving() || !(input == null || input instanceof Input_PassPriority)) inputStack.add(in); else input = in; @@ -106,9 +123,9 @@ public class InputControl extends MyObservable implements java.io.Serializable { * @return a {@link forge.gui.input.Input} object. */ public Input updateInput() { - final String phase = AllZone.getPhase().getPhase(); - final Player playerTurn = AllZone.getPhase().getPlayerTurn(); - final Player priority = AllZone.getPhase().getPriorityPlayer(); + final String phase = model.getGameState().getPhase().getPhase(); + final Player playerTurn = model.getGameState().getPhase().getPlayerTurn(); + final Player priority = model.getGameState().getPhase().getPriorityPlayer(); // TODO: this resolving portion needs more work, but fixes Death Cloud issues if (resolvingStack.size() > 0) { @@ -121,7 +138,7 @@ public class InputControl extends MyObservable implements java.io.Serializable { return input; } - if (AllZone.getStack().getResolving()) + if (model.getGameState().getStack().getResolving()) return null; @@ -133,55 +150,59 @@ public class InputControl extends MyObservable implements java.io.Serializable { return input; } - if (Phase.getGameBegins() != 0 && AllZone.getPhase().doPhaseEffects()) { + if (Phase.getGameBegins() != 0 && model.getGameState().getPhase().doPhaseEffects()) { // Handle begin phase stuff, then start back from the top - AllZone.getPhase().handleBeginPhase(); + model.getGameState().getPhase().handleBeginPhase(); return updateInput(); } // If the Phase we're in doesn't allow for Priority, return null to move to next phase - if (AllZone.getPhase().isNeedToNextPhase()) + if (model.getGameState().getPhase().isNeedToNextPhase()) return null; // Special Inputs needed for the following phases: if (phase.equals(Constant.Phase.Combat_Declare_Attackers)) { - AllZone.getStack().freezeStack(); + model.getGameState().getStack().freezeStack(); if (playerTurn.isHuman()) return new Input_Attack(); } else if (phase.equals(Constant.Phase.Combat_Declare_Blockers)) { - AllZone.getStack().freezeStack(); + model.getGameState().getStack().freezeStack(); if (playerTurn.isHuman()) { - AllZone.getComputer().getComputer().declare_blockers(); + aiInput.getComputer().declare_blockers(); return null; } else { - if (AllZone.getCombat().getAttackers().length == 0) { + if (model.getGameState().getCombat().getAttackers().length == 0) { // no active attackers, skip the Blocking phase - AllZone.getPhase().setNeedToNextPhase(true); + model.getGameState().getPhase().setNeedToNextPhase(true); return null; } else return new Input_Block(); } } else if (phase.equals(Constant.Phase.Cleanup)) // Player needs to discard - if (AllZone.getStack().size() == 0) // fall through to resolve things like Madness + if (model.getGameState().getStack().size() == 0) // fall through to resolve things like Madness return new Input_Cleanup(); // ********************* // Special phases handled above, everything else is handled simply by priority if (priority.isHuman()) { - boolean skip = AllZone.getPhase().doSkipPhase(); - AllZone.getPhase().setSkipPhase(false); - if (AllZone.getStack().size() == 0 && !AllZone.getDisplay().stopAtPhase(playerTurn, phase) && skip) { - AllZone.getPhase().passPriority(); + boolean skip = model.getGameState().getPhase().doSkipPhase(); + model.getGameState().getPhase().setSkipPhase(false); + if (model.getGameState().getStack().size() == 0 && !forge.AllZone.getDisplay().stopAtPhase(playerTurn, phase) && skip) { + model.getGameState().getPhase().passPriority(); return null; } else return new Input_PassPriority(); } else if (playerTurn.isComputer()) - return AllZone.getComputer(); + return aiInput; else { - AllZone.getComputer().getComputer().stack_not_empty(); + aiInput.getComputer().stack_not_empty(); return null; } }//getInput() + + public void setComputer(ComputerAI_Input computerAI_Input) { + aiInput = computerAI_Input; + } }//InputControl diff --git a/src/main/java/forge/view/swing/ApplicationView.java b/src/main/java/forge/view/swing/ApplicationView.java index 8cf580f3d5f..e680ab7b7b1 100644 --- a/src/main/java/forge/view/swing/ApplicationView.java +++ b/src/main/java/forge/view/swing/ApplicationView.java @@ -127,7 +127,7 @@ public class ApplicationView implements FView { Constant.Runtime.gameType = GameType.Constructed; SwingUtilities.invokeLater(new Runnable() { // NOPMD by Braids on 8/7/11 1:07 PM: this isn't a web app public void run() { - AllZone.setComputer(new ComputerAI_Input(new ComputerAI_General())); + AllZone.getInputControl().setComputer(new ComputerAI_Input(new ComputerAI_General())); // Enable only one of the following two lines. The second // is useful for debugging.