
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@260 72836036-5685-4462-b002-a69064685172
72 lines
1.3 KiB
Java
72 lines
1.3 KiB
Java
package jrummikub.control;
|
|
|
|
import jrummikub.model.GameSettings;
|
|
import jrummikub.model.RoundState;
|
|
import jrummikub.util.IListener;
|
|
import jrummikub.view.IView;
|
|
|
|
/**
|
|
* Controls a Game, at some point including all Rounds, starts new Rounds
|
|
*/
|
|
public class GameControl {
|
|
private GameSettings gameSettings;
|
|
private IView view;
|
|
private RoundControl roundControl;
|
|
|
|
/**
|
|
* Constructor
|
|
*
|
|
* @param gameSettings
|
|
* the game settings
|
|
* @param view
|
|
* the view
|
|
*/
|
|
public GameControl(GameSettings gameSettings, IView view) {
|
|
this.gameSettings = gameSettings;
|
|
this.view = view;
|
|
|
|
view.getNewGameEvent().add(new IListener() {
|
|
@Override
|
|
public void handle() {
|
|
startRound();
|
|
}
|
|
});
|
|
view.getQuitEvent().add(new IListener() {
|
|
@Override
|
|
public void handle() {
|
|
quitProgram();
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Game gets started by initializing the first Round
|
|
*/
|
|
public void startGame() {
|
|
startRound();
|
|
}
|
|
|
|
private void startRound() {
|
|
if (roundControl != null) {
|
|
return;
|
|
}
|
|
|
|
RoundState roundState = new RoundState(gameSettings);
|
|
|
|
roundControl = new RoundControl(roundState, view);
|
|
roundControl.getEndRoundEvent().add(new IListener() {
|
|
|
|
@Override
|
|
public void handle() {
|
|
roundControl = null;
|
|
}
|
|
});
|
|
|
|
roundControl.startRound();
|
|
}
|
|
|
|
private void quitProgram() {
|
|
System.exit(0);
|
|
}
|
|
|
|
}
|