diff --git a/src/fr/enssat/BoulderDash/controllers/BoulderAndDiamondController.java b/src/fr/enssat/BoulderDash/controllers/BoulderAndDiamondController.java index f292660f..d06354c9 100644 --- a/src/fr/enssat/BoulderDash/controllers/BoulderAndDiamondController.java +++ b/src/fr/enssat/BoulderDash/controllers/BoulderAndDiamondController.java @@ -3,7 +3,8 @@ package fr.enssat.BoulderDash.controllers; import fr.enssat.BoulderDash.models.LevelModel; import fr.enssat.BoulderDash.models.DirtModel; import fr.enssat.BoulderDash.models.DisplayableElementModel; -import fr.enssat.BoulderDash.helpers.AudioLoadHelper; + +import static fr.enssat.BoulderDash.helpers.AudioLoadHelper.AUDIO_LOAD_HELPER; /** * ElementPositionUpdateHelper @@ -16,7 +17,6 @@ import fr.enssat.BoulderDash.helpers.AudioLoadHelper; * @since 2015-06-19 */ public class BoulderAndDiamondController extends AbstractLevelController implements Runnable { - private AudioLoadHelper audioLoadHelper; private Thread elementMovingThread; /** @@ -24,9 +24,8 @@ public class BoulderAndDiamondController extends AbstractLevelController impleme * * @param levelModel Level model */ - public BoulderAndDiamondController(LevelModel levelModel, AudioLoadHelper audioLoadHelper) { + public BoulderAndDiamondController(LevelModel levelModel) { super(levelModel); - this.audioLoadHelper = audioLoadHelper; // Start thread this.elementMovingThread = new Thread(this); @@ -131,7 +130,7 @@ public class BoulderAndDiamondController extends AbstractLevelController impleme } else if (spriteNameBelow == "rockford" && this.levelModel.getGroundLevelModel()[x][y].isFalling()) { this.levelModel.exploseGround(x, y + 1); - this.audioLoadHelper.playSound("die"); + AUDIO_LOAD_HELPER.playSound("die"); try { Thread.sleep(25); diff --git a/src/fr/enssat/BoulderDash/controllers/GameController.java b/src/fr/enssat/BoulderDash/controllers/GameController.java index dc95a881..79e37f9f 100644 --- a/src/fr/enssat/BoulderDash/controllers/GameController.java +++ b/src/fr/enssat/BoulderDash/controllers/GameController.java @@ -1,13 +1,14 @@ package fr.enssat.BoulderDash.controllers; import fr.enssat.BoulderDash.models.LevelModel; -import fr.enssat.BoulderDash.helpers.AudioLoadHelper; import fr.enssat.BoulderDash.views.MenuView; import fr.enssat.BoulderDash.views.GameView; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import static fr.enssat.BoulderDash.helpers.AudioLoadHelper.AUDIO_LOAD_HELPER; + /** * GameController @@ -19,7 +20,6 @@ import java.awt.event.ActionListener; * @since 2015-06-19 */ public class GameController extends AbstractLevelController implements ActionListener { - private AudioLoadHelper audioLoadHelper; private boolean firstClickOnPause; private MenuView menuView; private GameView gameView; @@ -31,19 +31,18 @@ public class GameController extends AbstractLevelController implements ActionLis * @param levelModel Level model * @param navigationBetweenViewController */ - public GameController(LevelModel levelModel, AudioLoadHelper audioLoadHelper, NavigationBetweenViewController navigationBetweenViewController) { + public GameController(LevelModel levelModel, NavigationBetweenViewController navigationBetweenViewController) { super(levelModel); this.firstClickOnPause = true; this.navigationBetweenViewController = navigationBetweenViewController; - this.audioLoadHelper = audioLoadHelper; this.gameView = new GameView(this, levelModel); this.menuView = navigationBetweenViewController.getMenuView(); - this.getAudioLoadHelper().stopMusic(); - this.getAudioLoadHelper().playSound("new"); + AUDIO_LOAD_HELPER.stopMusic(); + AUDIO_LOAD_HELPER.playSound("new"); } /** @@ -66,13 +65,13 @@ public class GameController extends AbstractLevelController implements ActionLis case "restart": this.resetGame("restart"); - this.getAudioLoadHelper().playSound("new"); + AUDIO_LOAD_HELPER.playSound("new"); this.gameView.getGameFieldView().grabFocus(); break; case "menu": this.menuView.setVisible(true); - this.getAudioLoadHelper().startMusic("game"); + AUDIO_LOAD_HELPER.startMusic("game"); this.resetGame("menu"); break; } @@ -85,21 +84,12 @@ public class GameController extends AbstractLevelController implements ActionLis this.gameView.dispose(); if (source.equals("restart")) { - this.levelModel = new LevelModel(this.navigationBetweenViewController.getPickedLevelIdentifier(), audioLoadHelper); + this.levelModel = new LevelModel(this.navigationBetweenViewController.getPickedLevelIdentifier()); this.gameView = new GameView(this, levelModel); this.gameView.setVisible(true); } } - /** - * Gets the audio load helper instance - * - * @return Audio load helper instance - */ - public AudioLoadHelper getAudioLoadHelper() { - return this.audioLoadHelper; - } - /** * Return the game view * @@ -109,12 +99,9 @@ public class GameController extends AbstractLevelController implements ActionLis return gameView; } - /** - * Set the gameView - * - * @param gameView - */ - public void setGameView(GameView gameView) { - this.gameView = 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/GameKeyController.java b/src/fr/enssat/BoulderDash/controllers/GameKeyController.java index f5b7c141..45fb0b0e 100644 --- a/src/fr/enssat/BoulderDash/controllers/GameKeyController.java +++ b/src/fr/enssat/BoulderDash/controllers/GameKeyController.java @@ -2,7 +2,6 @@ package fr.enssat.BoulderDash.controllers; import fr.enssat.BoulderDash.models.DisplayableElementModel; import fr.enssat.BoulderDash.models.LevelModel; -import fr.enssat.BoulderDash.helpers.AudioLoadHelper; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; @@ -24,9 +23,9 @@ public class GameKeyController extends AbstractLevelController implements KeyLis * * @param levelModel Level model */ - public GameKeyController(LevelModel levelModel, AudioLoadHelper audioLoadHelper) { + public GameKeyController(LevelModel levelModel) { super(levelModel); - new BoulderAndDiamondController(levelModel, audioLoadHelper); + new BoulderAndDiamondController(levelModel); this.updatePosRockford = new RockfordUpdateController(levelModel); } diff --git a/src/fr/enssat/BoulderDash/controllers/LevelEditorController.java b/src/fr/enssat/BoulderDash/controllers/LevelEditorController.java index 7a1ed34f..2f2130cc 100644 --- a/src/fr/enssat/BoulderDash/controllers/LevelEditorController.java +++ b/src/fr/enssat/BoulderDash/controllers/LevelEditorController.java @@ -12,6 +12,8 @@ import fr.enssat.BoulderDash.views.LevelEditorView; import javax.swing.*; +import static fr.enssat.BoulderDash.helpers.AudioLoadHelper.AUDIO_LOAD_HELPER; + /** * LevelEditorController *
@@ -34,7 +36,7 @@ public class LevelEditorController extends AbstractLevelController implements Ac this.levelModel.setShowCursor(true); this.nav = nav; - this.nav.getAudioLoadHelper().stopMusic(); + AUDIO_LOAD_HELPER.stopMusic(); this.levelEditorView = new LevelEditorView(this, levelModel, nav); @@ -52,7 +54,7 @@ public class LevelEditorController extends AbstractLevelController implements Ac case "menu": this.levelEditorView.setVisible(false); this.nav.setMenuView(); - this.nav.getAudioLoadHelper().startMusic("game"); + AUDIO_LOAD_HELPER.startMusic("game"); break; @@ -119,23 +121,17 @@ public class LevelEditorController extends AbstractLevelController implements Ac return levelEditorView; } - /** - * Gets level model - * - * @return Level model - */ - public LevelModel getLevelModel() { - return this.levelModel; - } + // dead code + // + //public LevelModel getLevelModel() { + // return this.levelModel; + //} - /** - * Sets the level editor view - * - * @param levelEditorView Level editor view - */ - public void setLevelEditorView(LevelEditorView levelEditorView) { - this.levelEditorView = levelEditorView; - } + // dead code + // + //public void setLevelEditorView(LevelEditorView levelEditorView) { + // this.levelEditorView = levelEditorView; + //} } \ 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 6034e896..86a14673 100644 --- a/src/fr/enssat/BoulderDash/controllers/NavigationBetweenViewController.java +++ b/src/fr/enssat/BoulderDash/controllers/NavigationBetweenViewController.java @@ -3,11 +3,10 @@ package fr.enssat.BoulderDash.controllers; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import fr.enssat.BoulderDash.helpers.AudioLoadHelper; import fr.enssat.BoulderDash.models.LevelModel; import fr.enssat.BoulderDash.views.MenuView; -import fr.enssat.BoulderDash.controllers.LevelEditorController; -import fr.enssat.BoulderDash.controllers.GameController; + +import static fr.enssat.BoulderDash.helpers.AudioLoadHelper.AUDIO_LOAD_HELPER; /** * Controller to navigate between the different views @@ -17,7 +16,6 @@ import fr.enssat.BoulderDash.controllers.GameController; public class NavigationBetweenViewController implements ActionListener { private LevelEditorController levelEditorController; private MenuView menuView; - private AudioLoadHelper audioLoadHelper; private GameController gameController; private String pickedLevelIdentifier; @@ -25,10 +23,8 @@ public class NavigationBetweenViewController implements ActionListener { * Class constructor */ public NavigationBetweenViewController() { - this.audioLoadHelper = new AudioLoadHelper(); - // Play game music - this.getAudioLoadHelper().startMusic("game"); + AUDIO_LOAD_HELPER.startMusic("game"); // Creation of the first view this.menuView = new MenuView(this); @@ -48,7 +44,7 @@ public class NavigationBetweenViewController implements ActionListener { case "editor": // New blank model for editor - LevelModel levelModelForEditor = new LevelModel(audioLoadHelper); + LevelModel levelModelForEditor = new LevelModel(); this.levelEditorController = new LevelEditorController(levelModelForEditor, this); this.levelEditorController.getLevelEditorView().setVisible(true); @@ -64,8 +60,8 @@ public class NavigationBetweenViewController implements ActionListener { // Reinit the levelModelForGame... pickedLevelIdentifier = this.menuView.getLevelIdentifier(); - LevelModel levelModelForGame = new LevelModel(pickedLevelIdentifier, audioLoadHelper); - this.gameController = new GameController(levelModelForGame, audioLoadHelper, this); + LevelModel levelModelForGame = new LevelModel(pickedLevelIdentifier); + this.gameController = new GameController(levelModelForGame, this); if (levelEditorController != null) { this.levelEditorController.getLevelEditorView().setVisible(false); @@ -80,15 +76,6 @@ public class NavigationBetweenViewController implements ActionListener { this.menuView.setVisible(false); } - /** - * Get the audio load helper - * - * @return Audio load helper - */ - public AudioLoadHelper getAudioLoadHelper() { - return this.audioLoadHelper; - } - /** * Get the first view * @@ -100,8 +87,6 @@ public class NavigationBetweenViewController implements ActionListener { /** * Set the first view - * - * @param menuView */ public MenuView setMenuView() { this.menuView = new MenuView(this); @@ -117,14 +102,11 @@ public class NavigationBetweenViewController implements ActionListener { return pickedLevelIdentifier; } - /** - * Set the pickedLevelIdentifier - * - * @param pickedLevelIdentifier Picked level identifier - */ - public void setPickedLevelIdentifier(String pickedLevelIdentifier) { - this.pickedLevelIdentifier = pickedLevelIdentifier; - } + // dead code + // + //public void setPickedLevelIdentifier(String pickedLevelIdentifier) { + // this.pickedLevelIdentifier = pickedLevelIdentifier; + //} } diff --git a/src/fr/enssat/BoulderDash/helpers/AudioLoadHelper.java b/src/fr/enssat/BoulderDash/helpers/AudioLoadHelper.java index bcfc6435..6c6f18e8 100644 --- a/src/fr/enssat/BoulderDash/helpers/AudioLoadHelper.java +++ b/src/fr/enssat/BoulderDash/helpers/AudioLoadHelper.java @@ -8,14 +8,18 @@ import java.util.HashMap; /** * AudioLoadHelper - * + *
* Manages audio
*
* @author Valerian Saliou
* Levels are loaded from XML file. The view knows the model, the controller is
* going to modify the model in function of the game panel. The model notifies
* the view when there are changes on it.
@@ -31,799 +22,792 @@ import java.util.Observable;
* @since 2015-06-19
*/
public class LevelModel extends Observable implements Runnable {
- private DisplayableElementModel[][] groundGrid;
- private String levelName;
- private AudioLoadHelper audioLoadHelper;
- private int sizeWidth = 0;
- private int sizeHeight = 0;
- private int cursorXPosition = 0;
- private int cursorYPosition = 0;
- private boolean showCursor = false;
- private CursorModel cursorModel;
- private LevelLoadHelper levelLoadHelper;
- private RockfordModel rockford;
- private GameInformationModel gameInformationModel;
- private int rockfordPositionX, rockfordPositionY;
- private boolean gameRunning;
- private boolean gamePaused;
- // Are we in editor or game mode ?
- private String mode;
+ private DisplayableElementModel[][] groundGrid;
+ private String levelName;
+ private int sizeWidth = 0;
+ private int sizeHeight = 0;
+ private int cursorXPosition = 0;
+ private int cursorYPosition = 0;
+ private boolean showCursor = false;
+ private CursorModel cursorModel;
+ private LevelLoadHelper levelLoadHelper;
+ private RockfordModel rockford;
+ private GameInformationModel gameInformationModel;
+ private int rockfordPositionX, rockfordPositionY;
+ private boolean gameRunning;
+ private boolean gamePaused;
+ // Are we in editor or game mode ?
+ private String mode;
- /**
- * Sprite animation thread
- */
- private Thread spriteAnimator;
+ /**
+ * Sprite animation thread
+ */
+ private Thread spriteAnimator;
- /**
- * Animation speed
- */
- private final int DELAY = 25;
+ /**
+ * Animation speed
+ */
+ private final int DELAY = 25;
- /**
- * Class constructor
- *
- * @param levelName Level name
- * @param audioLoadHelper Audio load helper
- * @param mode Instance mode
- */
- public LevelModel(String levelName, AudioLoadHelper audioLoadHelper, String mode) {
- this.levelName = levelName;
- this.audioLoadHelper = audioLoadHelper;
- this.gamePaused = false;
- this.gameRunning = true;
- this.mode = mode;
+ /**
+ * Class constructor
+ *
+ * @param levelName Level name
+ * @param mode Instance mode
+ */
+ public LevelModel(String levelName, String mode) {
+ this.levelName = levelName;
+ this.gamePaused = false;
+ this.gameRunning = true;
+ this.mode = mode;
- this.levelLoadHelper = new LevelLoadHelper(this.levelName);
+ this.levelLoadHelper = new LevelLoadHelper(this.levelName);
- this.groundGrid = this.levelLoadHelper.getGroundGrid();
- this.sizeWidth = this.levelLoadHelper.getWidthSizeValue();
- this.sizeHeight = this.levelLoadHelper.getHeightSizeValue();
+ this.groundGrid = this.levelLoadHelper.getGroundGrid();
+ this.sizeWidth = this.levelLoadHelper.getWidthSizeValue();
+ this.sizeHeight = this.levelLoadHelper.getHeightSizeValue();
- this.cursorModel = new CursorModel();
- this.gameInformationModel = new GameInformationModel(this.levelLoadHelper.getDiamondsToCatch());
+ this.cursorModel = new CursorModel();
+ this.gameInformationModel = new GameInformationModel(this.levelLoadHelper.getDiamondsToCatch());
- this.createLimits();
+ this.createLimits();
- if(this.mode.equals("game")) {
- this.initRockford();
- this.initThreadAnimator();
- }
- }
+ if (this.mode.equals("game")) {
+ this.initRockford();
+ this.initThreadAnimator();
+ }
+ }
- /**
- * Class constructor
- *
- * @param levelName Level name
- * @param audioLoadHelper Audio load helper
- */
- public LevelModel(String levelName, AudioLoadHelper audioLoadHelper) {
- this(levelName, audioLoadHelper, "game");
+ /**
+ * Class constructor
+ *
+ * @param levelName Level name
+ */
+ public LevelModel(String levelName) {
+ this(levelName, "game");
+ }
+
+ /**
+ * Class constructor (editor mode)
+ */
+ public LevelModel() {
+ this.gameRunning = false;
+ this.mode = "editor";
+
+ this.sizeWidth = 25 + 2;
+ this.sizeHeight = 25 + 2;
+
+ // Generate dirt
+ this.groundGrid = new DisplayableElementModel[this.sizeWidth][this.sizeHeight];
+
+ for (int x = 0; x < this.sizeWidth; x++) {
+ for (int y = 0; y < this.sizeHeight; y++) {
+ this.groundGrid[x][y] = new DirtModel();
+ }
}
- /**
- * Class constructor (editor mode)
- *
- * @param audioLoadHelper Audio load helper
- */
- public LevelModel(AudioLoadHelper audioLoadHelper) {
- this.audioLoadHelper = audioLoadHelper;
- this.gameRunning = false;
- this.mode = "editor";
+ this.createLimits();
+ }
- this.sizeWidth = 25 + 2;
- this.sizeHeight = 25 + 2;
+ /**
+ * Initializes the animator thread
+ */
+ private void initThreadAnimator() {
+ this.spriteAnimator = new Thread(this);
+ this.spriteAnimator.start();
+ }
- // Generate dirt
- this.groundGrid = new DisplayableElementModel[this.sizeWidth][this.sizeHeight];
+ /**
+ * Initializes the Rockford position attributes
+ */
+ private void initRockford() {
+ this.rockfordPositionX = this.levelLoadHelper.getRockfordPositionX();
+ this.rockfordPositionY = this.levelLoadHelper.getRockfordPositionY();
+ this.rockford = this.levelLoadHelper.getRockfordInstance();
+ }
- for (int x = 0; x < this.sizeWidth; x++) {
- for (int y = 0; y < this.sizeHeight; y++) {
- this.groundGrid[x][y] = new DirtModel();
- }
- }
+ /**
+ * Creates the limits Puts steel walls all around the game panel
+ */
+ private void createLimits() {
+ int maxWidth = this.sizeWidth - 1;
+ int maxHeight = this.sizeHeight - 1;
- this.createLimits();
- }
+ for (int x = 0; x < this.sizeWidth; x++) {
+ this.groundGrid[x][0] = new SteelWallModel();
+ this.groundGrid[x][maxHeight] = new SteelWallModel();
+ }
+ for (int y = 0; y < this.sizeHeight; y++) {
+ this.groundGrid[0][y] = new SteelWallModel();
+ this.groundGrid[maxWidth][y] = new SteelWallModel();
+ }
+ }
- /**
- * Initializes the animator thread
- */
- private void initThreadAnimator() {
- this.spriteAnimator = new Thread(this);
- this.spriteAnimator.start();
- }
+ public void resetLevelModel() {
+ this.groundGrid = this.levelLoadHelper.getGroundGrid();
+ this.gameRunning = true;
+ this.gameInformationModel.resetInformations();
+ }
- /**
- * Initializes the Rockford position attributes
- */
- private void initRockford() {
- this.rockfordPositionX = this.levelLoadHelper.getRockfordPositionX();
- this.rockfordPositionY = this.levelLoadHelper.getRockfordPositionY();
- this.rockford = this.levelLoadHelper.getRockfordInstance();
- }
+ /**
+ * Updates the horizontal & vertical positions of Rockford in the model
+ *
+ * @param posX Horizontal position of Rockford
+ * @param posY Vertical position of Rockford
+ */
+ public void updateRockfordPosition(int posX, int posY) {
+ this.rockfordPositionY = posY;
+ this.rockfordPositionX = posX;
+ }
- /**
- * Creates the limits Puts steel walls all around the game panel
- */
- private void createLimits() {
- int maxWidth = this.sizeWidth - 1;
- int maxHeight = this.sizeHeight - 1;
-
- for (int x = 0; x < this.sizeWidth; x++) {
- this.groundGrid[x][0] = new SteelWallModel();
- this.groundGrid[x][maxHeight] = new SteelWallModel();
- }
- for (int y = 0; y < this.sizeHeight; y++) {
- this.groundGrid[0][y] = new SteelWallModel();
- this.groundGrid[maxWidth][y] = new SteelWallModel();
- }
- }
-
- public void resetLevelModel() {
- this.groundGrid = this.levelLoadHelper.getGroundGrid();
- this.gameRunning = true;
- this.gameInformationModel.resetInformations();
- }
-
- /**
- * Updates the horizontal & vertical positions of Rockford in the model
- *
- * @param posX Horizontal position of Rockford
- * @param posY Vertical position of Rockford
- */
- public void updateRockfordPosition(int posX, int posY) {
- this.rockfordPositionY = posY;
- this.rockfordPositionX = posX;
- }
-
- /**
- * Checks whether position is out-of-bounds or not
- *
- * @param posX Horizontal position
- * @param posY Vertical position
- */
- private boolean isOutOfBounds(int posX, int posY) {
- if (posX > 0 && posY > 0 && posX < this.getLevelLoadHelper().getHeightSizeValue() && posY < this.getLevelLoadHelper().getWidthSizeValue()) {
- return false;
- }
-
- return true;
- }
-
- /**
- * Plays collision sound
- */
- private void playCollisionSound(int posX, int posY) {
- String collisionSound = null;
-
- if (this.getRockford().isCollisionDone() == false) {
- // Out of bounds?
- if (this.isOutOfBounds(posX, posY) == true) {
- collisionSound = "touch";
- } else {
- DisplayableElementModel nextElement = this.groundGrid[posX][posY];
- collisionSound = nextElement.getCollideSound();
- }
-
- this.getRockford().setCollisionDone(true);
- }
-
- if (collisionSound != null) {
- this.audioLoadHelper.playSound(collisionSound);
- }
- }
-
- /**
- * Gets the horizontal position of Rockford from the model
- *
- * @return Horizontal position of Rockford
- */
- public int getRockfordPositionX() {
- return this.rockfordPositionX;
- }
-
- /**
- * Sets the new Rockford position
- *
- * @param posX Next horizontal position on the grid
- * @param posY Next vertical position on the grid
- */
- public void setPositionOfRockford(int posX, int posY) {
- int oldX = this.getRockfordPositionX();
- int oldY = this.getRockfordPositionY();
-
- if (this.groundGrid[posX][posY].getSpriteName() == "diamond") {
- this.gameInformationModel.incrementScore();
- this.gameInformationModel.decrementRemainingsDiamonds();
- if (this.gameInformationModel.getRemainingsDiamonds() == 0) {
- this.spawnExit();
- }
- }
- if (this.groundGrid[posX][posY].getSpriteName() == "door") {
- this.gameRunning = false;
- }
-
- this.playCollisionSound(posX, posY);
-
- // Check that we are not out of bound...
- if (this.isOutOfBounds(posX, posY) == false) {
- // Create a new empty model in the old pos of Rockford
- this.groundGrid[oldX][oldY] = new EmptyModel();
-
- // Save the x / y pos of Rockford in the levelModel only
- this.updateRockfordPosition(posX, posY);
-
- this.groundGrid[posX][posY] = this.getRockford();
- }
- }
-
- /**
- * When there is no more diamonds to catch, spawn a exit door randomly in
- * the game
- */
- private void spawnExit() {
- int x = (int) (Math.random() * (this.getSizeHeight() - 2));
- int y = (int) (Math.random() * (this.getSizeWidth() - 2));
- this.groundGrid[x + 1][y + 1] = new DoorModel();
- }
-
- /**
- * Trigger block change with provided value
- *
- * @param blockValue New value
- */
- public void triggerBlockChange(String blockValue) {
- // No block value?
- if(blockValue == null || blockValue.isEmpty()) {
- return;
- }
-
- // Cancel if Rockford is already in model
- if((blockValue.equals("Rockford") || blockValue.equals("rockford")) && this.isRockfordInModel()) {
- return;
- }
-
- // Grab model value
- ModelConvertHelper modelConverter = new ModelConvertHelper();
- DisplayableElementModel targetModel;
- int xPos, yPos;
-
- xPos = this.getCursorXPosition();
- yPos = this.getCursorYPosition();
-
- try {
- targetModel = modelConverter.toModel(blockValue, false);
-
- // Apply new model in place of cursor
- this.groundGrid[xPos + 1][yPos + 1] = targetModel;
-
- // Disable cursor (important)
- //this.setShowCursor(false);
- } catch (UnknownModelException e) {
- e.printStackTrace();
- }
- }
-
- /**
- * Gets the vertical position of Rockford from the model
- *
- * @return Vertical position of Rockford
- */
- public int getRockfordPositionY() {
- return this.rockfordPositionY;
- }
-
- /**
- * Gets the Rockford object instance
- *
- * @return Rockford object
- */
- public RockfordModel getRockford() {
- return this.rockford;
- }
-
- /**
- * Gets the displayable element at given positions
- *
- * @param x Block horizontal position
- * @param y Block vertical position
- * @return Displayable element at given positions
- */
- public DisplayableElementModel getDisplayableElement(int x, int y) {
- return this.groundGrid[x][y];
- }
-
- /**
- * Gets the image at given positions
- *
- * @param x Block horizontal position
- * @param y Block vertical position
- * @return Image at given positions
- */
- public BufferedImage getImage(int x, int y) {
- DisplayableElementModel elementModel = this.getDisplayableElement(x, y);
-
- if(elementModel == null) {
- return new DirtModel().getSprite();
- }
-
- return elementModel.getSprite();
- }
-
- /**
- * Gets the cursor image image
- *
- * @return Cursor image
- */
- public BufferedImage getCursorImage() {
-
- if (this.cursorModel == null) {
- this.cursorModel = new CursorModel();
- }
-
- return this.cursorModel.getSprite();
- }
-
- /**
- * Return whether rockford is in model or not
- * Notice: not optimized, be careful
- *
- * @return Whether rockford is in model or not
- */
- public boolean isRockfordInModel() {
- boolean isInModel = false;
-
- // Iterate and catch it!
- for (int x = 0; x < this.getSizeWidth() && !isInModel; x++) {
- for (int y = 0; y < this.getSizeHeight() && !isInModel; y++) {
- if(this.groundGrid[x][y] != null && this.groundGrid[x][y].getSpriteName() == "rockford") {
- isInModel = true;
- }
- }
- }
-
- return isInModel;
+ /**
+ * Checks whether position is out-of-bounds or not
+ *
+ * @param posX Horizontal position
+ * @param posY Vertical position
+ */
+ private boolean isOutOfBounds(int posX, int posY) {
+ if (posX > 0 && posY > 0 && posX < this.getLevelLoadHelper().getHeightSizeValue() && posY < this.getLevelLoadHelper().getWidthSizeValue()) {
+ return false;
}
- /**
- * Returns number of diamonds
- *
- * @return Number of diamonds
- */
- public int countDiamonds() {
- int numberOfDiamonds = 0;
+ return true;
+ }
- // Iterate and catch it!
+ /**
+ * Plays collision sound
+ */
+ private void playCollisionSound(int posX, int posY) {
+ String collisionSound = null;
+
+ if (this.getRockford().isCollisionDone() == false) {
+ // Out of bounds?
+ if (this.isOutOfBounds(posX, posY) == true) {
+ collisionSound = "touch";
+ } else {
+ DisplayableElementModel nextElement = this.groundGrid[posX][posY];
+ collisionSound = nextElement.getCollideSound();
+ }
+
+ this.getRockford().setCollisionDone(true);
+ }
+
+ if (collisionSound != null) {
+ AUDIO_LOAD_HELPER.playSound(collisionSound);
+ }
+ }
+
+ /**
+ * Gets the horizontal position of Rockford from the model
+ *
+ * @return Horizontal position of Rockford
+ */
+ public int getRockfordPositionX() {
+ return this.rockfordPositionX;
+ }
+
+ /**
+ * Sets the new Rockford position
+ *
+ * @param posX Next horizontal position on the grid
+ * @param posY Next vertical position on the grid
+ */
+ public void setPositionOfRockford(int posX, int posY) {
+ int oldX = this.getRockfordPositionX();
+ int oldY = this.getRockfordPositionY();
+
+ if (this.groundGrid[posX][posY].getSpriteName() == "diamond") {
+ this.gameInformationModel.incrementScore();
+ this.gameInformationModel.decrementRemainingsDiamonds();
+ if (this.gameInformationModel.getRemainingsDiamonds() == 0) {
+ this.spawnExit();
+ }
+ }
+ if (this.groundGrid[posX][posY].getSpriteName() == "door") {
+ this.gameRunning = false;
+ }
+
+ this.playCollisionSound(posX, posY);
+
+ // Check that we are not out of bound...
+ if (this.isOutOfBounds(posX, posY) == false) {
+ // Create a new empty model in the old pos of Rockford
+ this.groundGrid[oldX][oldY] = new EmptyModel();
+
+ // Save the x / y pos of Rockford in the levelModel only
+ this.updateRockfordPosition(posX, posY);
+
+ this.groundGrid[posX][posY] = this.getRockford();
+ }
+ }
+
+ /**
+ * When there is no more diamonds to catch, spawn a exit door randomly in
+ * the game
+ */
+ private void spawnExit() {
+ int x = (int) (Math.random() * (this.getSizeHeight() - 2));
+ int y = (int) (Math.random() * (this.getSizeWidth() - 2));
+ this.groundGrid[x + 1][y + 1] = new DoorModel();
+ }
+
+ /**
+ * Trigger block change with provided value
+ *
+ * @param blockValue New value
+ */
+ public void triggerBlockChange(String blockValue) {
+ // No block value?
+ if (blockValue == null || blockValue.isEmpty()) {
+ return;
+ }
+
+ // Cancel if Rockford is already in model
+ if ((blockValue.equals("Rockford") || blockValue.equals("rockford")) && this.isRockfordInModel()) {
+ return;
+ }
+
+ // Grab model value
+ ModelConvertHelper modelConverter = new ModelConvertHelper();
+ DisplayableElementModel targetModel;
+ int xPos, yPos;
+
+ xPos = this.getCursorXPosition();
+ yPos = this.getCursorYPosition();
+
+ try {
+ targetModel = modelConverter.toModel(blockValue, false);
+
+ // Apply new model in place of cursor
+ this.groundGrid[xPos + 1][yPos + 1] = targetModel;
+
+ // Disable cursor (important)
+ //this.setShowCursor(false);
+ } catch (UnknownModelException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Gets the vertical position of Rockford from the model
+ *
+ * @return Vertical position of Rockford
+ */
+ public int getRockfordPositionY() {
+ return this.rockfordPositionY;
+ }
+
+ /**
+ * Gets the Rockford object instance
+ *
+ * @return Rockford object
+ */
+ public RockfordModel getRockford() {
+ return this.rockford;
+ }
+
+ /**
+ * Gets the displayable element at given positions
+ *
+ * @param x Block horizontal position
+ * @param y Block vertical position
+ * @return Displayable element at given positions
+ */
+ public DisplayableElementModel getDisplayableElement(int x, int y) {
+ return this.groundGrid[x][y];
+ }
+
+ /**
+ * Gets the image at given positions
+ *
+ * @param x Block horizontal position
+ * @param y Block vertical position
+ * @return Image at given positions
+ */
+ public BufferedImage getImage(int x, int y) {
+ DisplayableElementModel elementModel = this.getDisplayableElement(x, y);
+
+ if (elementModel == null) {
+ return new DirtModel().getSprite();
+ }
+
+ return elementModel.getSprite();
+ }
+
+ /**
+ * Gets the cursor image image
+ *
+ * @return Cursor image
+ */
+ public BufferedImage getCursorImage() {
+
+ if (this.cursorModel == null) {
+ this.cursorModel = new CursorModel();
+ }
+
+ return this.cursorModel.getSprite();
+ }
+
+ /**
+ * Return whether rockford is in model or not
+ * Notice: not optimized, be careful
+ *
+ * @return Whether rockford is in model or not
+ */
+ public boolean isRockfordInModel() {
+ boolean isInModel = false;
+
+ // Iterate and catch it!
+ for (int x = 0; x < this.getSizeWidth() && !isInModel; x++) {
+ for (int y = 0; y < this.getSizeHeight() && !isInModel; y++) {
+ if (this.groundGrid[x][y] != null && this.groundGrid[x][y].getSpriteName() == "rockford") {
+ isInModel = true;
+ }
+ }
+ }
+
+ return isInModel;
+ }
+
+ /**
+ * Returns number of diamonds
+ *
+ * @return Number of diamonds
+ */
+ public int countDiamonds() {
+ int numberOfDiamonds = 0;
+
+ // Iterate and catch it!
+ for (int x = 0; x < this.getSizeWidth(); x++) {
+ for (int y = 0; y < this.getSizeHeight(); y++) {
+ if (this.groundGrid[x][y] != null && this.groundGrid[x][y].getSpriteName() == "diamond") {
+ numberOfDiamonds += 1;
+ }
+ }
+ }
+
+ return numberOfDiamonds;
+ }
+
+ /**
+ * Returns whether constraints on model are respected or not
+ */
+ public void checkConstraints() throws LevelConstraintNotRespectedException {
+ // Diamonds number?
+ if (this.countDiamonds() < 3) {
+ throw new LevelConstraintNotRespectedException("Add at least 3 diamonds!");
+ }
+
+ // Rockford in model?
+ if (!this.isRockfordInModel()) {
+ throw new LevelConstraintNotRespectedException("Add Rockford on the map!");
+ }
+ }
+
+ /**
+ * Gets the level horizontal size
+ *
+ * @return Horizontal size
+ */
+ public int getSizeWidth() {
+ return this.sizeWidth;
+ }
+
+ /**
+ * Sets the level horizontal size
+ *
+ * @param sizeWidth Horizontal size
+ */
+ public void setSizeWidth(int sizeWidth) {
+ this.sizeWidth = sizeWidth;
+ }
+
+ /**
+ * Gets the level vertical size
+ *
+ * @return Vertical size
+ */
+ public int getSizeHeight() {
+ return this.sizeHeight;
+ }
+
+ /**
+ * Sets the level vertical size
+ *
+ * @return sizeHeight Vertical size
+ */
+ public void setSizeHeight(int sizeHeight) {
+ this.sizeHeight = sizeHeight;
+ }
+
+ /**
+ * Gets the ground level model
+ *
+ * @return Ground level model
+ */
+ public DisplayableElementModel[][] getGroundLevelModel() {
+ return groundGrid;
+ }
+
+ /**
+ * Notify observers about a model change
+ */
+ private void localNotifyObservers() {
+ this.notifyObservers();
+ this.setChanged();
+ }
+
+ /**
+ * Update the current sprite Notifies the observers
+ *
+ * @param x Sprite block horizontal position
+ * @param y Sprite block vertical position
+ */
+ public void updateSprites(int x, int y) {
+ if (groundGrid[x][y] == null) {
+ groundGrid[x][y] = new DirtModel();
+ }
+
+ groundGrid[x][y].update(System.currentTimeMillis());
+ this.localNotifyObservers();
+ }
+
+ /**
+ * Update all the sprites So that they can be animated
+ */
+ public void run() {
+ while (gameRunning) {
+ if (!gamePaused) {
for (int x = 0; x < this.getSizeWidth(); x++) {
- for (int y = 0; y < this.getSizeHeight(); y++) {
- if(this.groundGrid[x][y] != null && this.groundGrid[x][y].getSpriteName() == "diamond") {
- numberOfDiamonds += 1;
- }
- }
+ for (int y = 0; y < this.getSizeHeight(); y++) {
+ this.updateSprites(x, y);
+ }
}
+ }
- return numberOfDiamonds;
+ try {
+ Thread.sleep(DELAY);
+ } catch (InterruptedException e) {
+ System.out.println("Interrupted: " + e.getMessage());
+ }
+ }
+ }
+
+ /**
+ * Increments the user score
+ */
+ public void incrementScore() {
+ this.gameInformationModel.incrementScore();
+ }
+
+ /**
+ * Gets the associated level load helper
+ *
+ * @return Level load helper
+ */
+ public LevelLoadHelper getLevelLoadHelper() {
+ return this.levelLoadHelper;
+ }
+
+ /**
+ * Gets the cursor position X value
+ *
+ * @return Cursor position X value
+ */
+ public int getCursorXPosition() {
+ return this.cursorXPosition;
+ }
+
+ /**
+ * Gets the cursor position Y value
+ *
+ * @return Cursor position Y value
+ */
+ public int getCursorYPosition() {
+ return this.cursorYPosition;
+ }
+
+ /**
+ * Increaments the cursor position X value
+ *
+ * @return Cursor position new X value
+ */
+ public int incrementCursorXPosition() {
+ if (this.cursorXPosition < (this.getSizeWidth() - 1 - 2)) {
+ this.cursorXPosition = this.cursorXPosition + 1;
}
- /**
- * Returns whether constraints on model are respected or not
- */
- public void checkConstraints() throws LevelConstraintNotRespectedException {
- // Diamonds number?
- if(this.countDiamonds() < 3) {
- throw new LevelConstraintNotRespectedException("Add at least 3 diamonds!");
- }
+ this.localNotifyObservers();
+ return this.getCursorXPosition();
+ }
- // Rockford in model?
- if(!this.isRockfordInModel()) {
- throw new LevelConstraintNotRespectedException("Add Rockford on the map!");
- }
+ /**
+ * Decrements the cursor position X value
+ *
+ * @return Cursor position new X value
+ */
+ public int decrementCursorXPosition() {
+ if (this.cursorXPosition > 0) {
+ this.cursorXPosition = this.cursorXPosition - 1;
}
- /**
- * Gets the level horizontal size
- *
- * @return Horizontal size
- */
- public int getSizeWidth() {
- return this.sizeWidth;
- }
+ this.localNotifyObservers();
+ return this.getCursorXPosition();
+ }
- /**
- * Sets the level horizontal size
- *
- * @param sizeWidth Horizontal size
- */
- public void setSizeWidth(int sizeWidth) {
- this.sizeWidth = sizeWidth;
- }
+ /**
+ * Increaments the cursor position Y value
+ *
+ * @return Cursor position new Y value
+ */
+ public int incrementCursorYPosition() {
+ if (this.cursorYPosition < (this.getSizeHeight() - 1 - 2)) {
+ this.cursorYPosition = this.cursorYPosition + 1;
+ }
- /**
- * Gets the level vertical size
- *
- * @return Vertical size
- */
- public int getSizeHeight() {
- return this.sizeHeight;
- }
+ this.localNotifyObservers();
+ return this.getCursorYPosition();
+ }
- /**
- * Sets the level vertical size
- *
- * @return sizeHeight Vertical size
- */
- public void setSizeHeight(int sizeHeight) {
- this.sizeHeight = sizeHeight;
- }
+ /**
+ * Decrements the cursor position Y value
+ *
+ * @return Cursor position new Y value
+ */
+ public int decrementCursorYPosition() {
+ if (this.cursorYPosition > 0) {
+ this.cursorYPosition = this.cursorYPosition - 1;
+ }
- /**
- * Gets the ground level model
- *
- * @return Ground level model
- */
- public DisplayableElementModel[][] getGroundLevelModel() {
- return groundGrid;
- }
+ this.localNotifyObservers();
+ return this.getCursorYPosition();
+ }
- /**
- * Notify observers about a model change
- */
- private void localNotifyObservers() {
- this.notifyObservers();
- this.setChanged();
- }
+ /**
+ * sets the game to a defined state
+ *
+ * @param gameRunning Whether game is running or not
+ */
+ public void setGameRunning(boolean gameRunning) {
+ this.gameRunning = gameRunning;
+ // Timer to refresh the view properly...
+ try {
+ Thread.sleep(200);
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ this.localNotifyObservers();
+ }
- /**
- * Update the current sprite Notifies the observers
- *
- * @param x Sprite block horizontal position
- * @param y Sprite block vertical position
- */
- public void updateSprites(int x, int y) {
- if(groundGrid[x][y] == null) {
- groundGrid[x][y] = new DirtModel();
- }
+ /**
+ * tells if the game is running
+ *
+ * @return whether the game is running or not
+ */
+ public boolean isGameRunning() {
+ return gameRunning;
+ }
- groundGrid[x][y].update(System.currentTimeMillis());
- this.localNotifyObservers();
- }
+ /**
+ * Gets whether cursor is to be shown or not
+ *
+ * @return whether cursor needs to be shown or not
+ */
+ public boolean getShowCursor() {
+ return this.showCursor;
+ }
- /**
- * Update all the sprites So that they can be animated
- */
- public void run() {
- while (gameRunning) {
- if (!gamePaused) {
- for (int x = 0; x < this.getSizeWidth(); x++) {
- for (int y = 0; y < this.getSizeHeight(); y++) {
- this.updateSprites(x, y);
- }
- }
- }
+ /**
+ * Sets whether cursor is to be shown or not
+ *
+ * @param showCursor whether cursor needs to be shown or not
+ */
+ public void setShowCursor(boolean showCursor) {
+ this.showCursor = showCursor;
+ }
- try {
- Thread.sleep(DELAY);
- } catch (InterruptedException e) {
- System.out.println("Interrupted: " + e.getMessage());
- }
- }
- }
+ /**
+ * When a boulder is falling on Rockford there is an explosion around him
+ *
+ * @param x Object horizontal position
+ * @param y Object vertical position
+ */
+ public void exploseGround(int x, int y) {
+ this.groundGrid[x][y] = new EmptyModel();
+ this.groundGrid[x + 1][y] = new EmptyModel();
+ this.groundGrid[x - 1][y] = new EmptyModel();
+ this.groundGrid[x][y + 1] = new EmptyModel();
+ this.groundGrid[x + 1][y + 1] = new EmptyModel();
+ this.groundGrid[x - 1][y + 1] = new EmptyModel();
+ this.groundGrid[x][y - 1] = new EmptyModel();
+ this.groundGrid[x + 1][y - 1] = new EmptyModel();
+ this.groundGrid[x - 1][y - 1] = new EmptyModel();
+ this.rockford.setHasExplosed(true);
- /**
- * Increments the user score
- */
- public void incrementScore() {
- this.gameInformationModel.incrementScore();
- }
+ // Again a sleep to notify the observers properly
+ try {
+ Thread.sleep(50);
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ this.localNotifyObservers();
+ }
- /**
- * Gets the associated level load helper
- *
- * @return Level load helper
- */
- public LevelLoadHelper getLevelLoadHelper() {
- return this.levelLoadHelper;
- }
+ /**
+ * Makes the DisplayableElement[x][y] fall one box down
+ *
+ * @param x Object horizontal position
+ * @param y Object vertical position
+ */
+ public void makeThisDisplayableElementFall(int x, int y) {
+ this.groundGrid[x][y].setFalling(true);
+ this.groundGrid[x][y + 1] = this.groundGrid[x][y];
+ this.groundGrid[x][y] = new EmptyModel();
+ }
- /**
- * Gets the cursor position X value
- *
- * @return Cursor position X value
- */
- public int getCursorXPosition() {
- return this.cursorXPosition;
- }
+ /**
+ * Makes the BoulderModel[x][y] slide left
+ *
+ * @param x Object horizontal position
+ * @param y Object vertical position
+ */
+ public void makeThisBoulderSlideLeft(int x, int y) {
+ this.groundGrid[x][y].setFalling(true);
+ this.groundGrid[x - 1][y + 1] = this.groundGrid[x][y];
+ this.groundGrid[x][y] = new EmptyModel();
+ }
- /**
- * Gets the cursor position Y value
- *
- * @return Cursor position Y value
- */
- public int getCursorYPosition() {
- return this.cursorYPosition;
- }
+ /**
+ * Makes the BoulderModel[x][y] slide right
+ *
+ * @param x Object horizontal position
+ * @param y Object vertical position
+ */
+ public void makeThisBoulderSlideRight(int x, int y) {
+ this.groundGrid[x][y].setFalling(true);
+ this.groundGrid[x + 1][y + 1] = this.groundGrid[x][y];
+ this.groundGrid[x][y] = new EmptyModel();
+ }
- /**
- * Increaments the cursor position X value
- *
- * @return Cursor position new X value
- */
- public int incrementCursorXPosition() {
- if (this.cursorXPosition < (this.getSizeWidth() - 1 - 2)) {
- this.cursorXPosition = this.cursorXPosition + 1;
- }
+ /**
+ * Makes the BoulderModel[x][y] transform into a diamond
+ *
+ * @param x Object horizontal position
+ * @param y Object vertical position
+ */
+ public void transformThisBoulderIntoADiamond(int x, int y) {
+ this.groundGrid[x][y + 2] = new DiamondModel();
+ this.groundGrid[x][y] = new EmptyModel();
+ }
- this.localNotifyObservers();
- return this.getCursorXPosition();
- }
+ /**
+ * Makes the BoulderModel[x][y] moving to right
+ *
+ * @param x Object horizontal position
+ * @param y Object vertical position
+ */
+ public void moveThisBoulderToRight(int x, int y) {
+ this.groundGrid[x + 1][y] = this.groundGrid[x][y];
+ this.groundGrid[x][y] = new EmptyModel();
+ }
- /**
- * Decrements the cursor position X value
- *
- * @return Cursor position new X value
- */
- public int decrementCursorXPosition() {
- if (this.cursorXPosition > 0) {
- this.cursorXPosition = this.cursorXPosition - 1;
- }
+ /**
+ * Makes the BoulderModel[x][y] moving to left
+ *
+ * @param x Object horizontal position
+ * @param y Object vertical position
+ */
+ public void moveThisBoulderToLeft(int x, int y) {
+ this.groundGrid[x - 1][y] = this.groundGrid[x][y];
+ this.groundGrid[x][y] = new EmptyModel();
+ }
- this.localNotifyObservers();
- return this.getCursorXPosition();
- }
+ /**
+ * Deletes the BoulderModel[x][y]
+ *
+ * @param x Object horizontal position
+ * @param y Object vertical position
+ */
+ public void deleteThisBoulder(int x, int y) {
+ this.groundGrid[x][y] = new EmptyModel();
+ }
- /**
- * Increaments the cursor position Y value
- *
- * @return Cursor position new Y value
- */
- public int incrementCursorYPosition() {
- if (this.cursorYPosition < (this.getSizeHeight() - 1 - 2)) {
- this.cursorYPosition = this.cursorYPosition + 1;
- }
+ /**
+ * Gets gameInformationModel
+ *
+ * @return gameInfos like score, remainings Diamonds etc
+ */
+ public GameInformationModel getGameInformationModel() {
+ return this.gameInformationModel;
+ }
- this.localNotifyObservers();
- return this.getCursorYPosition();
- }
+ /**
+ * Explose the brick wall
+ *
+ * @param x
+ * @param y
+ */
+ public void exploseThisBrickWall(int x, int y) {
+ this.groundGrid[x][y] = new EmptyModel();
+ this.groundGrid[x][y + 1] = new EmptyModel();
+ }
- /**
- * Decrements the cursor position Y value
- *
- * @return Cursor position new Y value
- */
- public int decrementCursorYPosition() {
- if (this.cursorYPosition > 0) {
- this.cursorYPosition = this.cursorYPosition - 1;
- }
+ /**
+ * Expand the ExpandingWallModel to left
+ *
+ * @param x
+ * @param y
+ */
+ public void expandThisWallToLeft(int x, int y) {
+ this.groundGrid[x - 1][y] = new ExpandingWallModel();
+ }
- this.localNotifyObservers();
- return this.getCursorYPosition();
- }
+ /**
+ * Expand the ExpandingWallModel to right
+ *
+ * @param x
+ * @param y
+ */
+ public void expandThisWallToRight(int x, int y) {
+ this.groundGrid[x + 1][y] = new ExpandingWallModel();
+ }
- /**
- * sets the game to a defined state
- *
- * @param gameRunning Whether game is running or not
- */
- public void setGameRunning(boolean gameRunning) {
- this.gameRunning = gameRunning;
- // Timer to refresh the view properly...
- try {
- Thread.sleep(200);
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- this.localNotifyObservers();
- }
+ /**
+ * Set the gamePaused variable
+ *
+ * @param gamePaused
+ */
+ public void setGamePaused(boolean gamePaused) {
+ this.gamePaused = gamePaused;
+ }
- /**
- * tells if the game is running
- *
- * @return whether the game is running or not
- */
- public boolean isGameRunning() {
- return gameRunning;
- }
+ /**
+ * Get the gamePaused variable
+ *
+ * @return gamePaused
+ */
+ public boolean getGamePaused() {
+ return this.gamePaused;
+ }
- /**
- * Gets whether cursor is to be shown or not
- *
- * @return whether cursor needs to be shown or not
- */
- public boolean getShowCursor() {
- return this.showCursor;
- }
+ /**
+ * Get the mode where this levelModel is used
+ *
+ * @return mode
+ */
+ public String getMode() {
+ return mode;
+ }
- /**
- * Sets whether cursor is to be shown or not
- *
- * @param showCursor whether cursor needs to be shown or not
- */
- public void setShowCursor(boolean showCursor) {
- this.showCursor = showCursor;
- }
-
- /**
- * When a boulder is falling on Rockford there is an explosion around him
- *
- * @param x Object horizontal position
- * @param y Object vertical position
- */
- public void exploseGround(int x, int y) {
- this.groundGrid[x][y] = new EmptyModel();
- this.groundGrid[x + 1][y] = new EmptyModel();
- this.groundGrid[x - 1][y] = new EmptyModel();
- this.groundGrid[x][y + 1] = new EmptyModel();
- this.groundGrid[x + 1][y + 1] = new EmptyModel();
- this.groundGrid[x - 1][y + 1] = new EmptyModel();
- this.groundGrid[x][y - 1] = new EmptyModel();
- this.groundGrid[x + 1][y - 1] = new EmptyModel();
- this.groundGrid[x - 1][y - 1] = new EmptyModel();
- this.rockford.setHasExplosed(true);
-
- // Again a sleep to notify the observers properly
- try {
- Thread.sleep(50);
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- this.localNotifyObservers();
- }
-
- /**
- * Makes the DisplayableElement[x][y] fall one box down
- *
- * @param x Object horizontal position
- * @param y Object vertical position
- */
- public void makeThisDisplayableElementFall(int x, int y) {
- this.groundGrid[x][y].setFalling(true);
- this.groundGrid[x][y + 1] = this.groundGrid[x][y];
- this.groundGrid[x][y] = new EmptyModel();
- }
-
- /**
- * Makes the BoulderModel[x][y] slide left
- *
- * @param x Object horizontal position
- * @param y Object vertical position
- */
- public void makeThisBoulderSlideLeft(int x, int y) {
- this.groundGrid[x][y].setFalling(true);
- this.groundGrid[x - 1][y + 1] = this.groundGrid[x][y];
- this.groundGrid[x][y] = new EmptyModel();
- }
-
- /**
- * Makes the BoulderModel[x][y] slide right
- *
- * @param x Object horizontal position
- * @param y Object vertical position
- */
- public void makeThisBoulderSlideRight(int x, int y) {
- this.groundGrid[x][y].setFalling(true);
- this.groundGrid[x + 1][y + 1] = this.groundGrid[x][y];
- this.groundGrid[x][y] = new EmptyModel();
- }
-
- /**
- * Makes the BoulderModel[x][y] transform into a diamond
- *
- * @param x Object horizontal position
- * @param y Object vertical position
- */
- public void transformThisBoulderIntoADiamond(int x, int y) {
- this.groundGrid[x][y + 2] = new DiamondModel();
- this.groundGrid[x][y] = new EmptyModel();
- }
-
- /**
- * Makes the BoulderModel[x][y] moving to right
- *
- * @param x Object horizontal position
- * @param y Object vertical position
- */
- public void moveThisBoulderToRight(int x, int y) {
- this.groundGrid[x + 1][y] = this.groundGrid[x][y];
- this.groundGrid[x][y] = new EmptyModel();
- }
-
- /**
- * Makes the BoulderModel[x][y] moving to left
- *
- * @param x Object horizontal position
- * @param y Object vertical position
- */
- public void moveThisBoulderToLeft(int x, int y) {
- this.groundGrid[x - 1][y] = this.groundGrid[x][y];
- this.groundGrid[x][y] = new EmptyModel();
- }
-
- /**
- * Deletes the BoulderModel[x][y]
- *
- * @param x Object horizontal position
- * @param y Object vertical position
- */
- public void deleteThisBoulder(int x, int y) {
- this.groundGrid[x][y] = new EmptyModel();
- }
-
- /**
- * Gets gameInformationModel
- *
- * @return gameInfos like score, remainings Diamonds etc
- */
- public GameInformationModel getGameInformationModel() {
- return this.gameInformationModel;
- }
-
- /**
- * Explose the brick wall
- *
- * @param x
- * @param y
- */
- public void exploseThisBrickWall(int x, int y) {
- this.groundGrid[x][y] = new EmptyModel();
- this.groundGrid[x][y + 1] = new EmptyModel();
- }
-
- /**
- * Expand the ExpandingWallModel to left
- *
- * @param x
- * @param y
- */
- public void expandThisWallToLeft(int x, int y) {
- this.groundGrid[x - 1][y] = new ExpandingWallModel();
- }
-
- /**
- * Expand the ExpandingWallModel to right
- *
- * @param x
- * @param y
- */
- public void expandThisWallToRight(int x, int y) {
- this.groundGrid[x + 1][y] = new ExpandingWallModel();
- }
-
- /**
- * Set the gamePaused variable
- *
- * @param gamePaused
- */
- public void setGamePaused(boolean gamePaused) {
- this.gamePaused = gamePaused;
- }
-
- /**
- * Get the gamePaused variable
- *
- * @return gamePaused
- */
- public boolean getGamePaused() {
- return this.gamePaused;
- }
-
- /**
- * Get the mode where this levelModel is used
- *
- * @return mode
- */
- public String getMode() {
- return mode;
- }
-
- /**
- * Set the mode where this levelModel is used
- *
- * @param mode
- */
- public void setMode(String mode) {
- this.mode = mode;
- }
+ /**
+ * Set the mode where this levelModel is used
+ *
+ * @param mode
+ */
+ public void setMode(String mode) {
+ this.mode = mode;
+ }
}
\ No newline at end of file
diff --git a/src/fr/enssat/BoulderDash/views/GameGroundView.java b/src/fr/enssat/BoulderDash/views/GameGroundView.java
index 640e7fd2..1251083c 100644
--- a/src/fr/enssat/BoulderDash/views/GameGroundView.java
+++ b/src/fr/enssat/BoulderDash/views/GameGroundView.java
@@ -31,7 +31,7 @@ public class GameGroundView extends GroundView {
this.gameController = gameController;
- this.addKeyListener(new GameKeyController(this.levelModel, this.gameController.getAudioLoadHelper()));
+ this.addKeyListener(new GameKeyController(this.levelModel));
this.setBorder(BorderFactory.createLineBorder(Color.black));
this.setFocusable(true);
diff --git a/src/fr/enssat/BoulderDash/views/LevelEditorView.java b/src/fr/enssat/BoulderDash/views/LevelEditorView.java
index d6e5557a..277d9d73 100644
--- a/src/fr/enssat/BoulderDash/views/LevelEditorView.java
+++ b/src/fr/enssat/BoulderDash/views/LevelEditorView.java
@@ -169,10 +169,10 @@ public class LevelEditorView extends JFrame implements Observer {
if(selectedLevelValue != null && !selectedLevelValue.isEmpty()) {
// Load existing model
- pickedLevelModel = new LevelModel(selectedLevelValue, this.nav.getAudioLoadHelper(), "editor");
+ pickedLevelModel = new LevelModel(selectedLevelValue, "editor");
} else {
// New blank model for editor
- pickedLevelModel = new LevelModel(this.nav.getAudioLoadHelper());
+ pickedLevelModel = new LevelModel();
}
pickedLevelModel.setShowCursor(true);