Package oop13.space.controller

Source Code of oop13.space.controller.GameOverController

package oop13.space.controller;

import oop13.space.model.IModel;
import oop13.space.utilities.GameStrings;
import oop13.space.views.GameOver.GameOverObserver;
import oop13.space.views.GameOverInterface;
import oop13.space.views.GamePanel;
import oop13.space.views.MainFrameInterface;
import oop13.space.views.SubmitScore;


/**
* Controller handling the interaction with the
* {@link oop13.space.views.GameOver} view.
*
* @author Manuel Bottazzi
*/
public class GameOverController implements GameOverObserver {

  private MainFrameInterface mainFrame;
  private GameOverInterface gameOver;
  private IModel model;

  /**
   * Creates a new GameOverController with the parameters
   * provided in input.
   *
   * @param mainFrame - The {@link oop13.space.views.MainFrameInterface} to use
   * for changing the current panel displayed.
   *
   * @param model - The data used by the controller.
   */
  public GameOverController(MainFrameInterface mainFrame, IModel model) {
    this.mainFrame = mainFrame;
    this.model = model;
  }

  /**
   * Sets the {@link oop13.space.views.GameOverInterface} view
   * the controller has to observe.
   *
   * @param gameOver - The {@link oop13.space.views.GameOverInterface} to observe.
   */
  public void setView(GameOverInterface gameOver) {
    this.gameOver = gameOver;
    this.gameOver.attachObserver(this);
    this.gameOver.getScoreLabel().setText(GameStrings.SCORE + this.model.getStatistics().getScore());
  }

  @Override
  public void playAgain() {
    this.model.resetGame();
    this.model.getStatistics().resetStatistics();
    this.model.initIndividuals();
    GameController gameController = new GameController(this.mainFrame, this.model);
    GamePanel gamePanel = new GamePanel(this.model.getList());
    gamePanel.getScoreLabel().setText(GameStrings.SCORE + model.getStatistics().getScore());
    gamePanel.getLivesLabel().setText(GameStrings.LIVES + model.getShip().getLives());
    gameController.setView(gamePanel);
    gamePanel.requestFocusInWindow();
    gamePanel.addKeyListener(new ShipController(this.model));
    this.mainFrame.replacePanel(gamePanel);
  }

  @Override
  public void submitScore() {
    SubmitScoreController submitScoreController = new SubmitScoreController(this.gameOver, this.model);
    SubmitScore subScore = new SubmitScore(model.getStatistics().getScore());
    submitScoreController.setView(subScore);
  }

  @Override
  public void comeBackToMenu() {
    this.mainFrame.replacePanel(mainFrame.getMainMenu());
  }

}
TOP

Related Classes of oop13.space.controller.GameOverController

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.