This repository has been archived on 2025-03-02. You can view files and clone it, but cannot push or open issues or pull requests.
JRummikub/src/jrummikub/control/GameControl.java
Jannis Harder 2446671f7a Cleaned up RoundControl tests
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@260 72836036-5685-4462-b002-a69064685172
2011-05-24 01:51:49 +02:00

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);
}
}