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

71 lines
1.3 KiB
Java
Raw Normal View History

package jrummikub.control;
import jrummikub.model.GameState;
import jrummikub.util.IListener;
import jrummikub.view.IView;
/**
* Controls a Game, at some point including all Rounds, starts new Rounds
*/
public class GameControl {
final static int HAND_HEIGHT = 2;
final static int HAND_WIDTH = 14;
private IView view;
private RoundControl roundControl;
/**
* Constructor
*
* @param view
*/
public GameControl(IView view) {
this.view = view;
view.getPlayerPanel().getHandPanel().setHandHeight(HAND_HEIGHT);
view.getPlayerPanel().getHandPanel().setHandWidth(HAND_WIDTH);
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;
}
GameState gameState = new GameState();
roundControl = new RoundControl(gameState, view);
roundControl.getEndRoundEvent().add(new IListener() {
@Override
public void handle() {
roundControl = null;
}
});
roundControl.startRound();
}
private void quitProgram() {
System.exit(0);
}
}