changed MAX_TEST_MODE_DURATION back to 10000 and made is configurable with a set method, put showValidChoices in a try block to catch error that occurs if X windows is not available
parent
3a0d32b75a
commit
d90c2f3274
|
@ -140,6 +140,7 @@ public class DeckStrCal {
|
||||||
while (!testTournament.isFinished()) {
|
while (!testTournament.isFinished()) {
|
||||||
final MagicGame game=testTournament.nextGame(false);
|
final MagicGame game=testTournament.nextGame(false);
|
||||||
final GameController controller=new GameController(null,game);
|
final GameController controller=new GameController(null,game);
|
||||||
|
controller.setMaxTestGameDuration(Long.MAX_VALUE);
|
||||||
controller.runGame();
|
controller.runGame();
|
||||||
if (testTournament.getGamesPlayed() > played) {
|
if (testTournament.getGamesPlayed() > played) {
|
||||||
System.out.println(
|
System.out.println(
|
||||||
|
|
|
@ -30,7 +30,7 @@ import magic.ui.viewer.GameViewer;
|
||||||
|
|
||||||
public class GameController {
|
public class GameController {
|
||||||
|
|
||||||
private static final long MAX_TEST_MODE_DURATION=100000;
|
private static long MAX_TEST_MODE_DURATION=10000;
|
||||||
|
|
||||||
private final GamePanel gamePanel;
|
private final GamePanel gamePanel;
|
||||||
private final MagicGame game;
|
private final MagicGame game;
|
||||||
|
@ -144,6 +144,10 @@ public class GameController {
|
||||||
return choiceClicked;
|
return choiceClicked;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setMaxTestGameDuration(final long duration) {
|
||||||
|
MAX_TEST_MODE_DURATION = duration;
|
||||||
|
}
|
||||||
|
|
||||||
public void setCardViewer(final CardViewer cardViewer) {
|
public void setCardViewer(final CardViewer cardViewer) {
|
||||||
|
|
||||||
this.cardViewer=cardViewer;
|
this.cardViewer=cardViewer;
|
||||||
|
@ -212,7 +216,6 @@ public class GameController {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void viewInfoRight(final MagicCardDefinition cardDefinition,final int index,final Rectangle rect) {
|
public void viewInfoRight(final MagicCardDefinition cardDefinition,final int index,final Rectangle rect) {
|
||||||
|
|
||||||
final Dimension size=gamePanel.getSize();
|
final Dimension size=gamePanel.getSize();
|
||||||
final Point pointOnScreen=gamePanel.getLocationOnScreen();
|
final Point pointOnScreen=gamePanel.getLocationOnScreen();
|
||||||
rect.x-=pointOnScreen.x;
|
rect.x-=pointOnScreen.x;
|
||||||
|
@ -231,12 +234,10 @@ public class GameController {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void hideInfo() {
|
public void hideInfo() {
|
||||||
|
|
||||||
DelayedViewersThread.getInstance().hideViewer(imageCardViewer);
|
DelayedViewersThread.getInstance().hideViewer(imageCardViewer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSourceCardDefinition(final MagicSource source) {
|
public void setSourceCardDefinition(final MagicSource source) {
|
||||||
|
|
||||||
if (source!=null) {
|
if (source!=null) {
|
||||||
sourceCardDefinition=source.getCardDefinition();
|
sourceCardDefinition=source.getCardDefinition();
|
||||||
} else {
|
} else {
|
||||||
|
@ -245,73 +246,64 @@ public class GameController {
|
||||||
}
|
}
|
||||||
|
|
||||||
public MagicCardDefinition getSourceCardDefinition() {
|
public MagicCardDefinition getSourceCardDefinition() {
|
||||||
|
|
||||||
return sourceCardDefinition;
|
return sourceCardDefinition;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void focusViewers(final int handGraveyard,final int stackCombat) {
|
public void focusViewers(final int handGraveyard,final int stackCombat) {
|
||||||
|
|
||||||
gamePanel.focusViewers(handGraveyard,stackCombat);
|
gamePanel.focusViewers(handGraveyard,stackCombat);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerChoiceViewer(final ChoiceViewer choiceViewer) {
|
public void registerChoiceViewer(final ChoiceViewer choiceViewer) {
|
||||||
|
|
||||||
choiceViewers.add(choiceViewer);
|
choiceViewers.add(choiceViewer);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showValidChoices() {
|
private void showValidChoices() {
|
||||||
|
try {
|
||||||
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
|
||||||
SwingUtilities.invokeLater(new Runnable() {
|
for (final ChoiceViewer choiceViewer : choiceViewers) {
|
||||||
|
|
||||||
public void run() {
|
choiceViewer.showValidChoices(validChoices);
|
||||||
|
}
|
||||||
for (final ChoiceViewer choiceViewer : choiceViewers) {
|
}
|
||||||
|
});
|
||||||
choiceViewer.showValidChoices(validChoices);
|
} catch (Error err) {
|
||||||
}
|
//there will be an error if X windows is not present on Linux
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isCombatChoice() {
|
public boolean isCombatChoice() {
|
||||||
|
|
||||||
return combatChoice;
|
return combatChoice;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearValidChoices() {
|
public void clearValidChoices() {
|
||||||
|
|
||||||
validChoices=Collections.emptySet();
|
validChoices=Collections.emptySet();
|
||||||
combatChoice=false;
|
combatChoice=false;
|
||||||
showValidChoices();
|
showValidChoices();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setValidChoices(final Set<Object> validChoices,final boolean combatChoice) {
|
public void setValidChoices(final Set<Object> validChoices,final boolean combatChoice) {
|
||||||
|
|
||||||
this.validChoices=validChoices;
|
this.validChoices=validChoices;
|
||||||
this.combatChoice=combatChoice;
|
this.combatChoice=combatChoice;
|
||||||
showValidChoices();
|
showValidChoices();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<Object> getValidChoices() {
|
public Set<Object> getValidChoices() {
|
||||||
|
|
||||||
return validChoices;
|
return validChoices;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update() {
|
public void update() {
|
||||||
|
hideInfo();
|
||||||
hideInfo();
|
gamePanel.updateInfo();
|
||||||
gamePanel.updateInfo();
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
SwingUtilities.invokeLater(new Runnable() {
|
public void run() {
|
||||||
|
gamePanel.update();
|
||||||
public void run() {
|
}
|
||||||
|
});
|
||||||
gamePanel.update();
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMessageWithSource(final MagicSource source,final String message) {
|
public String getMessageWithSource(final MagicSource source,final String message) {
|
||||||
|
|
||||||
if (source==null) {
|
if (source==null) {
|
||||||
return message;
|
return message;
|
||||||
} else {
|
} else {
|
||||||
|
@ -320,22 +312,16 @@ public class GameController {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showMessage(final MagicSource source,final String message) {
|
public void showMessage(final MagicSource source,final String message) {
|
||||||
|
|
||||||
SwingUtilities.invokeLater(new Runnable() {
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
gameViewer.showMessage(getMessageWithSource(source,message));
|
gameViewer.showMessage(getMessageWithSource(source,message));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showComponent(final JComponent content) {
|
public void showComponent(final JComponent content) {
|
||||||
|
|
||||||
SwingUtilities.invokeLater(new Runnable() {
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
gameViewer.showComponent(content);
|
gameViewer.showComponent(content);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -355,7 +341,6 @@ public class GameController {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object[] getPlayerNextEventChoiceResults(final MagicEvent event) {
|
private Object[] getPlayerNextEventChoiceResults(final MagicEvent event) {
|
||||||
|
|
||||||
final MagicSource source=event.getSource();
|
final MagicSource source=event.getSource();
|
||||||
setSourceCardDefinition(source);
|
setSourceCardDefinition(source);
|
||||||
final Object choiceResults[]=event.getChoice().getPlayerChoiceResults(this,game,event.getPlayer(),source);
|
final Object choiceResults[]=event.getChoice().getPlayerChoiceResults(this,game,event.getPlayer(),source);
|
||||||
|
@ -365,7 +350,6 @@ public class GameController {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void executeNextEventWithChoices(final MagicEvent event) {
|
private void executeNextEventWithChoices(final MagicEvent event) {
|
||||||
|
|
||||||
final Object[] choiceResults;
|
final Object[] choiceResults;
|
||||||
if (testMode||event.getPlayer().getPlayerDefinition().isArtificial()) {
|
if (testMode||event.getPlayer().getPlayerDefinition().isArtificial()) {
|
||||||
choiceResults=getArtificialNextEventChoiceResults(event);
|
choiceResults=getArtificialNextEventChoiceResults(event);
|
||||||
|
@ -383,7 +367,6 @@ public class GameController {
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void resetGame() {
|
public synchronized void resetGame() {
|
||||||
|
|
||||||
if (game.hasUndoPoints()) {
|
if (game.hasUndoPoints()) {
|
||||||
resetGame=true;
|
resetGame=true;
|
||||||
undoClicked();
|
undoClicked();
|
||||||
|
@ -391,7 +374,6 @@ public class GameController {
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void concede() {
|
public synchronized void concede() {
|
||||||
|
|
||||||
if (!gameConceded&&!game.isFinished()) {
|
if (!gameConceded&&!game.isFinished()) {
|
||||||
game.setLosingPlayer(game.getPlayer(0));
|
game.setLosingPlayer(game.getPlayer(0));
|
||||||
game.clearUndoPoints();
|
game.clearUndoPoints();
|
||||||
|
@ -402,7 +384,6 @@ public class GameController {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void performUndo() {
|
public void performUndo() {
|
||||||
|
|
||||||
if (resetGame) {
|
if (resetGame) {
|
||||||
resetGame=false;
|
resetGame=false;
|
||||||
while (game.hasUndoPoints()) {
|
while (game.hasUndoPoints()) {
|
||||||
|
@ -415,7 +396,6 @@ public class GameController {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void haltGame() {
|
public void haltGame() {
|
||||||
|
|
||||||
running.set(false);
|
running.set(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -466,13 +446,13 @@ public class GameController {
|
||||||
game.getPhase().executePhase(game);
|
game.getPhase().executePhase(game);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (testMode) {
|
if (testMode) {
|
||||||
if (System.currentTimeMillis()-startTime>MAX_TEST_MODE_DURATION) {
|
if (System.currentTimeMillis() - startTime > MAX_TEST_MODE_DURATION) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
running.set(false);
|
running.set(false);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue