package jrummikub.control; import jrummikub.model.GameState; import jrummikub.model.Hand; import jrummikub.util.IListener; import jrummikub.view.IView; /** * Controls a Game, at some point including all Rounds, starts new Rounds */ public class GameControl { private IView view; private RoundControl roundControl; /** * Constructor * * @param view * the 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); } }