package lab.games; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; /** * The controller of the GUI. */ public class Controller implements ActionListener { private Model model; private View view; private boolean finished; // once the game has finished, button presses have no impact any more /** * Initializes this controller. */ public Controller() { this.setFinished(false); } /** * Updates the model and the view for each event. An * event corresponds to the player selecting a column * to drop a coin. If the player selects a column that * is filled, the message "You cannot drop a coin in this * column" is printed. Otherwise, the model and view * are updated to reflect the dropping of the coin. * If at this point the player has won, the message * "You have won" is printed. Otherwise, the computer * selects a column to drop a coin. Next, the model and * view are updated to reflect the dropping of the coin. * If at this point the computer has won, the message * "You have lost" is printed. If all slots are filled, * the message "It is a tie" is printed. */ public void actionPerformed(ActionEvent event) { // implement this method } /** * Returns the model. * * @return the model. */ private Model getModel() { return this.model; } /** * Returns the view. * * @return the view. */ private View getView() { return this.view; } /** * Tests whether the game is finished. * * @return true if the game is finished, false otherwise. */ private boolean isFinished() { return this.finished; } /** * Sets the model to the given model. * * @param model the model. * @pre. model != null */ public void setModel(Model model) { this.model = model; } /** * Sets the view to the given view. * * @param view the view. * @pre. view != null */ public void setView(View view) { this.view = view; } /** * Sets whether the game is finished. * * @param finished whether the game is finished. */ private void setFinished(boolean finished) { this.finished = finished; } }