diff --git a/src/fr/enssat/BoulderDash/controllers/GameController.java b/src/fr/enssat/BoulderDash/controllers/GameController.java
index 2a921c9c..64e5745f 100644
--- a/src/fr/enssat/BoulderDash/controllers/GameController.java
+++ b/src/fr/enssat/BoulderDash/controllers/GameController.java
@@ -2,7 +2,6 @@ package fr.enssat.BoulderDash.controllers;
import fr.enssat.BoulderDash.models.LevelModel;
import fr.enssat.BoulderDash.helpers.AudioLoadHelper;
-import fr.enssat.BoulderDash.controllers.NavigationBetweenViewController;
import fr.enssat.BoulderDash.views.MenuView;
import fr.enssat.BoulderDash.views.GameView;
@@ -12,108 +11,114 @@ import java.awt.event.ActionListener;
/**
* GameController
- *
+ *
* This system creates the view.
* The game loop is also handled there.
*
- * @author Colin Leverger
- * @since 2015-06-19
+ * @author Colin Leverger
+ * @since 2015-06-19
*/
public class GameController implements ActionListener {
- private LevelModel levelModel;
- private AudioLoadHelper audioLoadHelper;
- private boolean firstClickOnPause;
- private MenuView menuView;
- private GameView gameView;
- private NavigationBetweenViewController navigationBetweenViewController;
-
- /**
- * Class constructor
- *
- * @param levelModel Level model
- * @param navigationBetweenViewController
- */
- public GameController(LevelModel levelModel, AudioLoadHelper audioLoadHelper, NavigationBetweenViewController navigationBetweenViewController) {
- this.firstClickOnPause = true;
-
- this.navigationBetweenViewController = navigationBetweenViewController;
-
- this.levelModel = levelModel;
- this.audioLoadHelper = audioLoadHelper;
- this.gameView = new GameView(this, levelModel);
- this.menuView = navigationBetweenViewController.getMenuView();
+ private LevelModel levelModel;
+ private AudioLoadHelper audioLoadHelper;
+ private boolean firstClickOnPause;
+ private MenuView menuView;
+ private GameView gameView;
+ private NavigationBetweenViewController navigationBetweenViewController;
- this.getAudioLoadHelper().stopMusic();
- this.getAudioLoadHelper().playSound("new");
- }
+ /**
+ * Class constructor
+ *
+ * @param levelModel Level model
+ * @param navigationBetweenViewController
+ */
+ public GameController(LevelModel levelModel, AudioLoadHelper audioLoadHelper, NavigationBetweenViewController navigationBetweenViewController) {
+ this.firstClickOnPause = true;
- /**
- * Handles the 'action performed' event
- *
- * @param event Action event
- */
- public void actionPerformed(ActionEvent event) {
- switch(event.getActionCommand()) {
- case "pause":
- if(this.firstClickOnPause) {
- this.levelModel.setGamePaused(true);
- } else if(!this.firstClickOnPause) {
- this.levelModel.setGamePaused(false);
- }
+ this.navigationBetweenViewController = navigationBetweenViewController;
- this.firstClickOnPause = !this.firstClickOnPause;
- this.gameView.getGameFieldView().grabFocus();
- break;
+ this.levelModel = levelModel;
+ this.audioLoadHelper = audioLoadHelper;
+ this.gameView = new GameView(this, levelModel);
+ this.menuView = navigationBetweenViewController.getMenuView();
- case "restart":
- this.resetGame("restart");
- this.getAudioLoadHelper().playSound("new");
- this.gameView.getGameFieldView().grabFocus();
- break;
-
- case "menu":
- this.menuView.setVisible(true);
- this.getAudioLoadHelper().startMusic("game");
- this.resetGame("menu");
- break;
+ this.getAudioLoadHelper().stopMusic();
+ this.getAudioLoadHelper().playSound("new");
+ }
+
+ /**
+ * Handles the 'action performed' event
+ *
+ * @param event Action event
+ */
+ public void actionPerformed(ActionEvent event) {
+ switch (event.getActionCommand()) {
+ case "pause":
+ if (this.firstClickOnPause) {
+ this.levelModel.setGamePaused(true);
+ } else if (!this.firstClickOnPause) {
+ this.levelModel.setGamePaused(false);
}
- }
- /**
- * Function to reset the game
- */
- private void resetGame(String source) {
- this.gameView.dispose();
-
- if(source.equals("restart")){
- this.levelModel = new LevelModel(this.navigationBetweenViewController.getPickedLevelIdentifier(), audioLoadHelper);
- this.gameView = new GameView(this, levelModel);
- this.gameView.setVisible(true);
- }
- }
+ this.firstClickOnPause = !this.firstClickOnPause;
+ this.gameView.getGameFieldView().grabFocus();
+ break;
- /**
- * Gets the audio load helper instance
- *
- * @return Audio load helper instance
- */
- public AudioLoadHelper getAudioLoadHelper() {
- return this.audioLoadHelper;
+ case "restart":
+ this.reset();
+ this.getAudioLoadHelper().playSound("new");
+ this.gameView.getGameFieldView().grabFocus();
+ break;
+
+ case "menu":
+ this.menuView.setVisible(true);
+ this.getAudioLoadHelper().startMusic("game");
+ this.dispose();
+ break;
}
+ }
- /**
- * Return the game view
- * @return gameView
- */
- public GameView getGameView() {
- return gameView;
- }
+ /**
+ * Reset the game
+ */
+ private void reset() {
+ String pickedLevel = levelModel.getLevelName();
+ dispose();
- /**
- * Set the gameView
- * @param gameView
- */
- public void setGameView(GameView gameView) {
- this.gameView = gameView;
- }
+ // Recreate game
+ this.levelModel = new LevelModel(pickedLevel, audioLoadHelper);
+ this.gameView = new GameView(this, levelModel);
+ this.gameView.setVisible(true);
+ }
+
+ /**
+ * Dispose the game
+ */
+ private void dispose() {
+ this.gameView.dispose();
+ }
+
+ /**
+ * Gets the audio load helper instance
+ *
+ * @return Audio load helper instance
+ */
+ public AudioLoadHelper getAudioLoadHelper() {
+ return this.audioLoadHelper;
+ }
+
+ /**
+ * Return the game view
+ *
+ * @return gameView
+ */
+ public GameView getGameView() {
+ return gameView;
+ }
+
+ // dead code
+ //
+ //public void setGameView(GameView gameView) {
+ // this.gameView = gameView;
+ //}
}
\ No newline at end of file
diff --git a/src/fr/enssat/BoulderDash/controllers/NavigationBetweenViewController.java b/src/fr/enssat/BoulderDash/controllers/NavigationBetweenViewController.java
index e2ca1da0..ebd25084 100644
--- a/src/fr/enssat/BoulderDash/controllers/NavigationBetweenViewController.java
+++ b/src/fr/enssat/BoulderDash/controllers/NavigationBetweenViewController.java
@@ -104,23 +104,15 @@ public class NavigationBetweenViewController implements ActionListener {
// return menuView;
//}
- /**
- * Get the pickedLevel
- *
- * @return pickedLevelIdentifier Picked level identifier
- */
- public String getPickedLevelIdentifier() {
- return pickedLevelIdentifier;
- }
-
- /**
- * Set the pickedLevelIdentifier
- *
- * @param pickedLevelIdentifier Picked level identifier
- */
- public void setPickedLevelIdentifier(String pickedLevelIdentifier) {
- this.pickedLevelIdentifier = pickedLevelIdentifier;
- }
-
+ // Replaced with LevelModel.getLevelName()
+ //
+ //public String getPickedLevelIdentifier() {
+ // return pickedLevelIdentifier;
+ //}
+ // dead code
+ //
+ //public void setPickedLevelIdentifier(String pickedLevelIdentifier) {
+ // this.pickedLevelIdentifier = pickedLevelIdentifier;
+ //}
}
diff --git a/src/fr/enssat/BoulderDash/models/LevelModel.java b/src/fr/enssat/BoulderDash/models/LevelModel.java
index cbb5415a..cd46951e 100644
--- a/src/fr/enssat/BoulderDash/models/LevelModel.java
+++ b/src/fr/enssat/BoulderDash/models/LevelModel.java
@@ -125,6 +125,10 @@ public class LevelModel extends Observable implements Runnable {
this.createLimits();
}
+ public String getLevelName() {
+ return levelName;
+ }
+
/**
* Initializes the animator thread
*/