GameControl tests, temporary handler in SettingsControl and small
fixes git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@288 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
63397e2f5f
commit
2d198820a9
6 changed files with 169 additions and 27 deletions
|
@ -19,7 +19,7 @@ import jrummikub.view.IView;
|
|||
public class GameControl {
|
||||
private GameSettings gameSettings;
|
||||
private IView view;
|
||||
private RoundControl roundControl;
|
||||
RoundControl roundControl;
|
||||
private GameState gameState;
|
||||
private List<Connection> connections = new ArrayList<Connection>();
|
||||
|
||||
|
@ -77,10 +77,23 @@ public class GameControl {
|
|||
endOfRound();
|
||||
}
|
||||
});
|
||||
|
||||
roundControl.getRestartRoundEvent().add(new IListener() {
|
||||
|
||||
@Override
|
||||
public void handle() {
|
||||
restartRound();
|
||||
}
|
||||
});
|
||||
|
||||
roundControl.startRound();
|
||||
}
|
||||
|
||||
private void restartRound() {
|
||||
roundControl = null;
|
||||
startRound();
|
||||
}
|
||||
|
||||
private void endOfRound() {
|
||||
roundControl = null;
|
||||
view.enableWinPanel(true);
|
||||
|
|
|
@ -27,7 +27,7 @@ import jrummikub.view.IView;
|
|||
* Controller that manages a single round of rummikub
|
||||
*/
|
||||
public class RoundControl {
|
||||
private IRoundState roundState;
|
||||
IRoundState roundState;
|
||||
private IView view;
|
||||
private ITable clonedTable;
|
||||
private Event restartRoundEvent = new Event();
|
||||
|
@ -70,12 +70,7 @@ public class RoundControl {
|
|||
}
|
||||
}));
|
||||
|
||||
connections.add(view.getPlayerPanel().getRedealEvent().add(new IListener() {
|
||||
@Override
|
||||
public void handle() {
|
||||
redeal();
|
||||
}
|
||||
}));
|
||||
|
||||
|
||||
prepareTurn();
|
||||
}
|
||||
|
@ -91,13 +86,20 @@ public class RoundControl {
|
|||
private void startTurn() {
|
||||
TurnControl turnControl = new TurnControl(roundState.getActivePlayer()
|
||||
.getHand(), clonedTable, view, roundState.getTurnNumber() < 1);
|
||||
connections.add(turnControl.getEndOfTurnEvent().add(new IListener() {
|
||||
turnControl.getEndOfTurnEvent().add(new IListener() {
|
||||
|
||||
@Override
|
||||
public void handle() {
|
||||
endOfTurn();
|
||||
}
|
||||
}));
|
||||
});
|
||||
|
||||
turnControl.getRedealEvent().add(new IListener() {
|
||||
@Override
|
||||
public void handle() {
|
||||
redeal();
|
||||
}
|
||||
});
|
||||
|
||||
turnControl.startTurn();
|
||||
}
|
||||
|
@ -322,7 +324,7 @@ public class RoundControl {
|
|||
}
|
||||
|
||||
private void redeal() {
|
||||
for (Connection c : connections) {
|
||||
for (Connection c : new ArrayList<Connection>(connections)) {
|
||||
c.remove();
|
||||
}
|
||||
restartRoundEvent.emit();
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
package jrummikub.control;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
import jrummikub.model.GameSettings;
|
||||
import jrummikub.model.PlayerSettings;
|
||||
import jrummikub.util.Event1;
|
||||
import jrummikub.util.IEvent1;
|
||||
import jrummikub.util.IListener;
|
||||
import jrummikub.util.IListener1;
|
||||
import jrummikub.view.IView;
|
||||
|
||||
|
@ -31,7 +35,17 @@ public class SettingsControl {
|
|||
* @Override public void handle(GameSettings settings) {
|
||||
* startGame(settings); } });
|
||||
*/
|
||||
|
||||
// TODO vvv this is just a temp. fix
|
||||
view.getSettingsPanel().getStartGameEvent().add(new IListener() {
|
||||
|
||||
@Override
|
||||
public void handle() {
|
||||
GameSettings defaultSettings = new GameSettings();
|
||||
defaultSettings.getPlayerList().add(new PlayerSettings("Foo", new Color(1.0f, 0, 0)));
|
||||
defaultSettings.getPlayerList().add(new PlayerSettings("Bar", new Color(0, 1.0f, 0)));
|
||||
startGame(defaultSettings);
|
||||
}
|
||||
});
|
||||
view.showSettingsPanel(true);
|
||||
}
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@ public class TurnControl {
|
|||
private List<Stone> selectedStones = new ArrayList<Stone>();
|
||||
|
||||
private Event endOfTurnEvent = new Event();
|
||||
private Event redealEvent = new Event();
|
||||
private List<Connection> connections = new ArrayList<Connection>();
|
||||
|
||||
private boolean inspectOnly;
|
||||
|
@ -77,12 +78,19 @@ public class TurnControl {
|
|||
|
||||
@Override
|
||||
public void handle() {
|
||||
endOfTurn();
|
||||
endOfTurn(false);
|
||||
}
|
||||
};
|
||||
connections.add(timer.getTimeRunOutEvent().add(endOfTurnListener));
|
||||
connections.add(view.getPlayerPanel().getEndTurnEvent()
|
||||
.add(endOfTurnListener));
|
||||
|
||||
connections.add(view.getPlayerPanel().getRedealEvent().add(new IListener() {
|
||||
@Override
|
||||
public void handle() {
|
||||
endOfTurn(true);
|
||||
}
|
||||
}));
|
||||
|
||||
addHandPanelHandlers();
|
||||
addStoneCollectionHandlers();
|
||||
|
@ -441,9 +449,13 @@ public class TurnControl {
|
|||
view.setSelectedStones(selectedStones);
|
||||
}
|
||||
|
||||
private void endOfTurn() {
|
||||
private void endOfTurn(boolean redeal) {
|
||||
timer.stopTimer();
|
||||
endOfTurnEvent.emit();
|
||||
if (redeal) {
|
||||
redealEvent.emit();
|
||||
} else {
|
||||
endOfTurnEvent.emit();
|
||||
}
|
||||
for (Connection c : connections) {
|
||||
c.remove();
|
||||
}
|
||||
|
@ -549,5 +561,14 @@ public class TurnControl {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Emitted when the round is aborted and needs to be restarted
|
||||
*
|
||||
* @return the event
|
||||
*/
|
||||
public Event getRedealEvent() {
|
||||
return redealEvent;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Reference in a new issue