mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 20:28:00 +00:00
untied InputControl from AllZone (mostly, except for display)
This commit is contained in:
@@ -53,7 +53,7 @@ public final class AllZone implements NewConstants {
|
|||||||
private static CardFactoryInterface cardFactory = null;
|
private static CardFactoryInterface cardFactory = null;
|
||||||
|
|
||||||
/** Constant <code>inputControl</code>. */
|
/** Constant <code>inputControl</code>. */
|
||||||
private static final InputControl INPUT_CONTROL = new InputControl();
|
private static final InputControl INPUT_CONTROL = new InputControl(Singletons.getModel());
|
||||||
|
|
||||||
/** Game state observer <code>gameInfo</code> collects statistics and players' performance. */
|
/** Game state observer <code>gameInfo</code> collects statistics and players' performance. */
|
||||||
private static GameSummary gameInfo = new GameSummary();
|
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
|
//initialized at Runtime since it has to be the last object constructed
|
||||||
|
|
||||||
/** Global <code>computer</code>. */
|
|
||||||
private static ComputerAI_Input computer;
|
|
||||||
|
|
||||||
//shared between Input_Attack, Input_Block, Input_CombatDamage , InputState_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();
|
return Singletons.getModel().getGameState().getTriggerHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>getComputer.</p>
|
|
||||||
*
|
|
||||||
* @return a {@link forge.ComputerAI_Input} object.
|
|
||||||
* @since 1.0.15
|
|
||||||
*/
|
|
||||||
public static ComputerAI_Input getComputer() {
|
|
||||||
return computer;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>setComputer.</p>
|
|
||||||
*
|
|
||||||
* @param input a {@link forge.ComputerAI_Input} object.
|
|
||||||
* @since 1.0.15
|
|
||||||
*/
|
|
||||||
public static void setComputer(final ComputerAI_Input input) {
|
|
||||||
computer = input;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>getCombat.</p>
|
* <p>getCombat.</p>
|
||||||
|
|||||||
@@ -1,10 +1,16 @@
|
|||||||
package forge.gui.input;
|
package forge.gui.input;
|
||||||
|
|
||||||
import forge.*;
|
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.Stack;
|
import java.util.Stack;
|
||||||
|
|
||||||
|
import forge.ComputerAI_Input;
|
||||||
|
import forge.Constant;
|
||||||
|
import forge.MyObservable;
|
||||||
|
import forge.Phase;
|
||||||
|
import forge.Player;
|
||||||
|
import forge.model.FModel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>InputControl class.</p>
|
* <p>InputControl class.</p>
|
||||||
*
|
*
|
||||||
@@ -22,13 +28,24 @@ public class InputControl extends MyObservable implements java.io.Serializable {
|
|||||||
private Stack<Input> resolvingStack = new Stack<Input>();
|
private Stack<Input> resolvingStack = new Stack<Input>();
|
||||||
private LinkedList<Input> resolvingQueue = new LinkedList<Input>();
|
private LinkedList<Input> resolvingQueue = new LinkedList<Input>();
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Setter for the field <code>input</code>.</p>
|
* <p>Setter for the field <code>input</code>.</p>
|
||||||
*
|
*
|
||||||
* @param in a {@link forge.gui.input.Input} object.
|
* @param in a {@link forge.gui.input.Input} object.
|
||||||
*/
|
*/
|
||||||
public void setInput(final Input in) {
|
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);
|
inputStack.add(in);
|
||||||
else
|
else
|
||||||
input = in;
|
input = in;
|
||||||
@@ -106,9 +123,9 @@ public class InputControl extends MyObservable implements java.io.Serializable {
|
|||||||
* @return a {@link forge.gui.input.Input} object.
|
* @return a {@link forge.gui.input.Input} object.
|
||||||
*/
|
*/
|
||||||
public Input updateInput() {
|
public Input updateInput() {
|
||||||
final String phase = AllZone.getPhase().getPhase();
|
final String phase = model.getGameState().getPhase().getPhase();
|
||||||
final Player playerTurn = AllZone.getPhase().getPlayerTurn();
|
final Player playerTurn = model.getGameState().getPhase().getPlayerTurn();
|
||||||
final Player priority = AllZone.getPhase().getPriorityPlayer();
|
final Player priority = model.getGameState().getPhase().getPriorityPlayer();
|
||||||
|
|
||||||
// TODO: this resolving portion needs more work, but fixes Death Cloud issues
|
// TODO: this resolving portion needs more work, but fixes Death Cloud issues
|
||||||
if (resolvingStack.size() > 0) {
|
if (resolvingStack.size() > 0) {
|
||||||
@@ -121,7 +138,7 @@ public class InputControl extends MyObservable implements java.io.Serializable {
|
|||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (AllZone.getStack().getResolving())
|
if (model.getGameState().getStack().getResolving())
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
|
||||||
@@ -133,55 +150,59 @@ public class InputControl extends MyObservable implements java.io.Serializable {
|
|||||||
return input;
|
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
|
// Handle begin phase stuff, then start back from the top
|
||||||
AllZone.getPhase().handleBeginPhase();
|
model.getGameState().getPhase().handleBeginPhase();
|
||||||
return updateInput();
|
return updateInput();
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the Phase we're in doesn't allow for Priority, return null to move to next phase
|
// 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;
|
return null;
|
||||||
|
|
||||||
// Special Inputs needed for the following phases:
|
// Special Inputs needed for the following phases:
|
||||||
if (phase.equals(Constant.Phase.Combat_Declare_Attackers)) {
|
if (phase.equals(Constant.Phase.Combat_Declare_Attackers)) {
|
||||||
AllZone.getStack().freezeStack();
|
model.getGameState().getStack().freezeStack();
|
||||||
|
|
||||||
if (playerTurn.isHuman())
|
if (playerTurn.isHuman())
|
||||||
return new Input_Attack();
|
return new Input_Attack();
|
||||||
} else if (phase.equals(Constant.Phase.Combat_Declare_Blockers)) {
|
} else if (phase.equals(Constant.Phase.Combat_Declare_Blockers)) {
|
||||||
AllZone.getStack().freezeStack();
|
model.getGameState().getStack().freezeStack();
|
||||||
if (playerTurn.isHuman()) {
|
if (playerTurn.isHuman()) {
|
||||||
AllZone.getComputer().getComputer().declare_blockers();
|
aiInput.getComputer().declare_blockers();
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
if (AllZone.getCombat().getAttackers().length == 0) {
|
if (model.getGameState().getCombat().getAttackers().length == 0) {
|
||||||
// no active attackers, skip the Blocking phase
|
// no active attackers, skip the Blocking phase
|
||||||
AllZone.getPhase().setNeedToNextPhase(true);
|
model.getGameState().getPhase().setNeedToNextPhase(true);
|
||||||
return null;
|
return null;
|
||||||
} else
|
} else
|
||||||
return new Input_Block();
|
return new Input_Block();
|
||||||
}
|
}
|
||||||
} else if (phase.equals(Constant.Phase.Cleanup)) // Player needs to discard
|
} 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();
|
return new Input_Cleanup();
|
||||||
|
|
||||||
// *********************
|
// *********************
|
||||||
// Special phases handled above, everything else is handled simply by priority
|
// Special phases handled above, everything else is handled simply by priority
|
||||||
|
|
||||||
if (priority.isHuman()) {
|
if (priority.isHuman()) {
|
||||||
boolean skip = AllZone.getPhase().doSkipPhase();
|
boolean skip = model.getGameState().getPhase().doSkipPhase();
|
||||||
AllZone.getPhase().setSkipPhase(false);
|
model.getGameState().getPhase().setSkipPhase(false);
|
||||||
if (AllZone.getStack().size() == 0 && !AllZone.getDisplay().stopAtPhase(playerTurn, phase) && skip) {
|
if (model.getGameState().getStack().size() == 0 && !forge.AllZone.getDisplay().stopAtPhase(playerTurn, phase) && skip) {
|
||||||
AllZone.getPhase().passPriority();
|
model.getGameState().getPhase().passPriority();
|
||||||
return null;
|
return null;
|
||||||
} else
|
} else
|
||||||
return new Input_PassPriority();
|
return new Input_PassPriority();
|
||||||
} else if (playerTurn.isComputer())
|
} else if (playerTurn.isComputer())
|
||||||
return AllZone.getComputer();
|
return aiInput;
|
||||||
else {
|
else {
|
||||||
AllZone.getComputer().getComputer().stack_not_empty();
|
aiInput.getComputer().stack_not_empty();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}//getInput()
|
}//getInput()
|
||||||
|
|
||||||
|
public void setComputer(ComputerAI_Input computerAI_Input) {
|
||||||
|
aiInput = computerAI_Input;
|
||||||
|
}
|
||||||
}//InputControl
|
}//InputControl
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ public class ApplicationView implements FView {
|
|||||||
Constant.Runtime.gameType = GameType.Constructed;
|
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
|
SwingUtilities.invokeLater(new Runnable() { // NOPMD by Braids on 8/7/11 1:07 PM: this isn't a web app
|
||||||
public void run() {
|
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
|
// Enable only one of the following two lines. The second
|
||||||
// is useful for debugging.
|
// is useful for debugging.
|
||||||
|
|||||||
Reference in New Issue
Block a user