From 99db8d4956bb1219292f9771a0a0adaaec54a08b Mon Sep 17 00:00:00 2001 From: Daniel Langbein Date: Thu, 7 Nov 2024 13:27:15 +0100 Subject: [PATCH 1/7] idea --- .idea/misc.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.idea/misc.xml b/.idea/misc.xml index 4b09d600..291e70f5 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,5 +1,8 @@ + + From f896028199ec630b455aeb611bd30c6689b37d59 Mon Sep 17 00:00:00 2001 From: Daniel Langbein Date: Thu, 7 Nov 2024 15:30:55 +0100 Subject: [PATCH 2/7] mv levelModel field up to superclass --- .../controllers/AbstractLevelController.java | 11 + .../BoulderAndDiamondController.java | 267 +++++++++--------- .../controllers/GameController.java | 183 ++++++------ .../controllers/GameKeyController.java | 170 ++++++----- .../controllers/LevelEditorController.java | 210 +++++++------- .../controllers/LevelEditorKeyController.java | 155 +++++----- .../NavigationBetweenViewController.java | 192 +++++++------ .../controllers/RockfordUpdateController.java | 95 +++---- 8 files changed, 643 insertions(+), 640 deletions(-) create mode 100644 src/fr/enssat/BoulderDash/controllers/AbstractLevelController.java diff --git a/src/fr/enssat/BoulderDash/controllers/AbstractLevelController.java b/src/fr/enssat/BoulderDash/controllers/AbstractLevelController.java new file mode 100644 index 00000000..0268d147 --- /dev/null +++ b/src/fr/enssat/BoulderDash/controllers/AbstractLevelController.java @@ -0,0 +1,11 @@ +package fr.enssat.BoulderDash.controllers; + +import fr.enssat.BoulderDash.models.LevelModel; + +public abstract class AbstractLevelController { + protected LevelModel levelModel; + + public AbstractLevelController(LevelModel levelModel) { + this.levelModel = levelModel; + } +} diff --git a/src/fr/enssat/BoulderDash/controllers/BoulderAndDiamondController.java b/src/fr/enssat/BoulderDash/controllers/BoulderAndDiamondController.java index 656481ff..f292660f 100644 --- a/src/fr/enssat/BoulderDash/controllers/BoulderAndDiamondController.java +++ b/src/fr/enssat/BoulderDash/controllers/BoulderAndDiamondController.java @@ -7,7 +7,7 @@ import fr.enssat.BoulderDash.helpers.AudioLoadHelper; /** * ElementPositionUpdateHelper - * + *

* Updates position of all elements displayed on the map, according to their * next potential position. Each object has a weight, which is used to compare * their power to destroy in the food chain. Sorry for that Darwinism. @@ -15,150 +15,149 @@ import fr.enssat.BoulderDash.helpers.AudioLoadHelper; * @author Colin Leverger * @since 2015-06-19 */ -public class BoulderAndDiamondController implements Runnable { - private LevelModel levelModel; - private AudioLoadHelper audioLoadHelper; - private Thread elementMovingThread; +public class BoulderAndDiamondController extends AbstractLevelController implements Runnable { + private AudioLoadHelper audioLoadHelper; + private Thread elementMovingThread; - /** - * Class constructor - * - * @param levelModel Level model - */ - public BoulderAndDiamondController(LevelModel levelModel, AudioLoadHelper audioLoadHelper) { - this.levelModel = levelModel; - this.audioLoadHelper = audioLoadHelper; + /** + * Class constructor + * + * @param levelModel Level model + */ + public BoulderAndDiamondController(LevelModel levelModel, AudioLoadHelper audioLoadHelper) { + super(levelModel); + this.audioLoadHelper = audioLoadHelper; - // Start thread - this.elementMovingThread = new Thread(this); - this.elementMovingThread.start(); - } + // Start thread + this.elementMovingThread = new Thread(this); + this.elementMovingThread.start(); + } - /** - * Watches for elements to be moved - */ - public void run() { - while (this.levelModel.isGameRunning()) { - if(!this.levelModel.getGamePaused()){ - this.manageFallingObject(); - } - try { - Thread.sleep(250); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - } + /** + * Watches for elements to be moved + */ + public void run() { + while (this.levelModel.isGameRunning()) { + if (!this.levelModel.getGamePaused()) { + this.manageFallingObject(); + } + try { + Thread.sleep(250); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } - /** - * Scan the ground to detect the boulders & the diamonds, then make them - * fall if necessary - * Note: scan of the ground upside down: we want things to fall slowly ! - */ - private void manageFallingObject() { - for (int x = this.levelModel.getSizeWidth() - 1; x >= 0; x--) { - for (int y = this.levelModel.getSizeHeight() - 1; y >= 0; y--) { - // Gets the spriteName of actual DisplayableElementModel object scanned - DisplayableElementModel elementModel = this.levelModel.getGroundLevelModel()[x][y]; + /** + * Scan the ground to detect the boulders & the diamonds, then make them + * fall if necessary + * Note: scan of the ground upside down: we want things to fall slowly ! + */ + private void manageFallingObject() { + for (int x = this.levelModel.getSizeWidth() - 1; x >= 0; x--) { + for (int y = this.levelModel.getSizeHeight() - 1; y >= 0; y--) { + // Gets the spriteName of actual DisplayableElementModel object scanned + DisplayableElementModel elementModel = this.levelModel.getGroundLevelModel()[x][y]; - if(elementModel == null) { - elementModel = new DirtModel(); - } + if (elementModel == null) { + elementModel = new DirtModel(); + } - String spriteName = elementModel.getSpriteName(); - - // If it is a boulder or a diamond... - if (spriteName == "boulder" || spriteName == "diamond") { - this.manageFall(x, y); - } else if(spriteName == "expandingwall"){ - if(this.expandWall(x,y).equals("left")){ - x -= 1; - } - } - } - } - } + String spriteName = elementModel.getSpriteName(); - /** - * Expand the wall at left & right - * - * @param x Horizontal position - * @param y Vertical position - */ - private String expandWall(int x, int y) { - DisplayableElementModel elementLeft = this.levelModel.getGroundLevelModel()[x - 1][y]; - DisplayableElementModel elementRight = this.levelModel.getGroundLevelModel()[x + 1][y]; - String spriteNameLeft = elementLeft.getSpriteName(); - String spriteNameRight = elementRight.getSpriteName(); - - String way = ""; - if(spriteNameLeft == "black"){ - this.levelModel.expandThisWallToLeft(x,y); - way = "left"; - } - if(spriteNameRight == "black"){ - this.levelModel.expandThisWallToRight(x,y); - way = "right"; - } - return way; - } + // If it is a boulder or a diamond... + if (spriteName == "boulder" || spriteName == "diamond") { + this.manageFall(x, y); + } else if (spriteName == "expandingwall") { + if (this.expandWall(x, y).equals("left")) { + x -= 1; + } + } + } + } + } - /** - * Manages the fall of elements - * - * @param x Horizontal position - * @param y Vertical position - */ - private void manageFall(int x, int y) { - // Get informed about Rockford surroundings - DisplayableElementModel elementBelow = this.levelModel.getGroundLevelModel()[x][y + 1]; - DisplayableElementModel elementLeft = this.levelModel.getGroundLevelModel()[x - 1][y]; - DisplayableElementModel elementRight = this.levelModel.getGroundLevelModel()[x + 1][y]; + /** + * Expand the wall at left & right + * + * @param x Horizontal position + * @param y Vertical position + */ + private String expandWall(int x, int y) { + DisplayableElementModel elementLeft = this.levelModel.getGroundLevelModel()[x - 1][y]; + DisplayableElementModel elementRight = this.levelModel.getGroundLevelModel()[x + 1][y]; + String spriteNameLeft = elementLeft.getSpriteName(); + String spriteNameRight = elementRight.getSpriteName(); - String spriteNameBelow = elementBelow.getSpriteName(); - String spriteNameLeft = elementLeft.getSpriteName(); - String spriteNameRight = elementRight.getSpriteName(); + String way = ""; + if (spriteNameLeft == "black") { + this.levelModel.expandThisWallToLeft(x, y); + way = "left"; + } + if (spriteNameRight == "black") { + this.levelModel.expandThisWallToRight(x, y); + way = "right"; + } + return way; + } - // Then, process in case of the surrounding - if (spriteNameBelow == "black") { - this.levelModel.makeThisDisplayableElementFall(x, y); - } else if (spriteNameBelow == "boulder") { - // Boulders have to roll if they hit another boulder - if (this.levelModel.getGroundLevelModel()[x - 1][y + 1].getSpriteName() == "black") { - this.levelModel.makeThisBoulderSlideLeft(x, y); - } else if (this.levelModel.getGroundLevelModel()[x + 1][y + 1].getSpriteName() == "black") { - this.levelModel.makeThisBoulderSlideRight(x, y); - } - } else if (spriteNameBelow == "rockford" && this.levelModel.getGroundLevelModel()[x][y].isFalling()) { - this.levelModel.exploseGround(x, y + 1); + /** + * Manages the fall of elements + * + * @param x Horizontal position + * @param y Vertical position + */ + private void manageFall(int x, int y) { + // Get informed about Rockford surroundings + DisplayableElementModel elementBelow = this.levelModel.getGroundLevelModel()[x][y + 1]; + DisplayableElementModel elementLeft = this.levelModel.getGroundLevelModel()[x - 1][y]; + DisplayableElementModel elementRight = this.levelModel.getGroundLevelModel()[x + 1][y]; - this.audioLoadHelper.playSound("die"); + String spriteNameBelow = elementBelow.getSpriteName(); + String spriteNameLeft = elementLeft.getSpriteName(); + String spriteNameRight = elementRight.getSpriteName(); - try { - Thread.sleep(25); - } catch (InterruptedException e) { - e.printStackTrace(); - } + // Then, process in case of the surrounding + if (spriteNameBelow == "black") { + this.levelModel.makeThisDisplayableElementFall(x, y); + } else if (spriteNameBelow == "boulder") { + // Boulders have to roll if they hit another boulder + if (this.levelModel.getGroundLevelModel()[x - 1][y + 1].getSpriteName() == "black") { + this.levelModel.makeThisBoulderSlideLeft(x, y); + } else if (this.levelModel.getGroundLevelModel()[x + 1][y + 1].getSpriteName() == "black") { + this.levelModel.makeThisBoulderSlideRight(x, y); + } + } else if (spriteNameBelow == "rockford" && this.levelModel.getGroundLevelModel()[x][y].isFalling()) { + this.levelModel.exploseGround(x, y + 1); - this.levelModel.setGameRunning(false); - } else if (spriteNameBelow == "magicwall") { - if (this.levelModel.getGroundLevelModel()[x][y].getSpriteName() == "boulder" - && (this.levelModel.getGroundLevelModel()[x][y+2].getSpriteName() == "dirt" || - this.levelModel.getGroundLevelModel()[x][y+2].getSpriteName() == "black")) { - if(this.levelModel.getGroundLevelModel()[x][y].isConvertible()) { - this.levelModel.transformThisBoulderIntoADiamond(x, y); - } else { - this.levelModel.deleteThisBoulder(x, y); - } - } - } else if (elementBelow.isDestructible() && spriteNameBelow != "dirt" && this.levelModel.getGroundLevelModel()[x][y].isFalling()) { - this.levelModel.exploseThisBrickWall(x, y); - } else if (spriteNameLeft == "rockford" && this.levelModel.getRockford().isRunningRight() && this.levelModel.getGroundLevelModel()[x + 1][y].getSpriteName() == "black") { - this.levelModel.moveThisBoulderToRight(x, y); - } else if (spriteNameRight == "rockford" && this.levelModel.getRockford().isRunningLeft() && this.levelModel.getGroundLevelModel()[x - 1][y].getSpriteName() == "black") { - this.levelModel.moveThisBoulderToLeft(x, y); - } else { - this.levelModel.getGroundLevelModel()[x][y].setFalling(false); - } - } + this.audioLoadHelper.playSound("die"); + + try { + Thread.sleep(25); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + this.levelModel.setGameRunning(false); + } else if (spriteNameBelow == "magicwall") { + if (this.levelModel.getGroundLevelModel()[x][y].getSpriteName() == "boulder" + && (this.levelModel.getGroundLevelModel()[x][y + 2].getSpriteName() == "dirt" || + this.levelModel.getGroundLevelModel()[x][y + 2].getSpriteName() == "black")) { + if (this.levelModel.getGroundLevelModel()[x][y].isConvertible()) { + this.levelModel.transformThisBoulderIntoADiamond(x, y); + } else { + this.levelModel.deleteThisBoulder(x, y); + } + } + } else if (elementBelow.isDestructible() && spriteNameBelow != "dirt" && this.levelModel.getGroundLevelModel()[x][y].isFalling()) { + this.levelModel.exploseThisBrickWall(x, y); + } else if (spriteNameLeft == "rockford" && this.levelModel.getRockford().isRunningRight() && this.levelModel.getGroundLevelModel()[x + 1][y].getSpriteName() == "black") { + this.levelModel.moveThisBoulderToRight(x, y); + } else if (spriteNameRight == "rockford" && this.levelModel.getRockford().isRunningLeft() && this.levelModel.getGroundLevelModel()[x - 1][y].getSpriteName() == "black") { + this.levelModel.moveThisBoulderToLeft(x, y); + } else { + this.levelModel.getGroundLevelModel()[x][y].setFalling(false); + } + } } diff --git a/src/fr/enssat/BoulderDash/controllers/GameController.java b/src/fr/enssat/BoulderDash/controllers/GameController.java index 2a921c9c..dc95a881 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,110 @@ 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(); +public class GameController extends AbstractLevelController implements ActionListener { + 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) { + super(levelModel); - /** - * 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.firstClickOnPause = true; - this.firstClickOnPause = !this.firstClickOnPause; - this.gameView.getGameFieldView().grabFocus(); - break; + this.navigationBetweenViewController = navigationBetweenViewController; - 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.audioLoadHelper = audioLoadHelper; + this.gameView = new GameView(this, levelModel); + this.menuView = navigationBetweenViewController.getMenuView(); + + 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.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; } + } - /** - * Return the game view - * @return gameView - */ - public GameView getGameView() { - return gameView; - } + /** + * Function to reset the game + */ + private void resetGame(String source) { + this.gameView.dispose(); - /** - * Set the gameView - * @param gameView - */ - public void setGameView(GameView gameView) { - this.gameView = gameView; - } + if (source.equals("restart")) { + this.levelModel = new LevelModel(this.navigationBetweenViewController.getPickedLevelIdentifier(), audioLoadHelper); + 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 + * + * @return gameView + */ + public GameView getGameView() { + return gameView; + } + + /** + * Set the gameView + * + * @param gameView + */ + 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 a7821b1d..f5b7c141 100644 --- a/src/fr/enssat/BoulderDash/controllers/GameKeyController.java +++ b/src/fr/enssat/BoulderDash/controllers/GameKeyController.java @@ -2,8 +2,6 @@ package fr.enssat.BoulderDash.controllers; import fr.enssat.BoulderDash.models.DisplayableElementModel; import fr.enssat.BoulderDash.models.LevelModel; -import fr.enssat.BoulderDash.controllers.RockfordUpdateController; -import fr.enssat.BoulderDash.controllers.BoulderAndDiamondController; import fr.enssat.BoulderDash.helpers.AudioLoadHelper; import java.awt.event.KeyEvent; @@ -12,98 +10,98 @@ import java.awt.event.KeyListener; /** * GameKeyController - * + *

* Manages the key events controller. * - * @author Colin Leverger - * @since 2015-06-19 + * @author Colin Leverger + * @since 2015-06-19 */ -public class GameKeyController implements KeyListener { - private LevelModel levelModel; - private RockfordUpdateController updatePosRockford; - /** - * Class constructor - * - * @param levelModel Level model - */ - public GameKeyController(LevelModel levelModel, AudioLoadHelper audioLoadHelper) { - this.levelModel = levelModel; - new BoulderAndDiamondController(levelModel, audioLoadHelper); - this.updatePosRockford = new RockfordUpdateController(levelModel); - } +public class GameKeyController extends AbstractLevelController implements KeyListener { + private RockfordUpdateController updatePosRockford; - /** - * Handles the 'key pressed' event - * - * @param e Key event - */ - public void keyPressed(KeyEvent e) { - int keyCode = e.getKeyCode(); + /** + * Class constructor + * + * @param levelModel Level model + */ + public GameKeyController(LevelModel levelModel, AudioLoadHelper audioLoadHelper) { + super(levelModel); + new BoulderAndDiamondController(levelModel, audioLoadHelper); + this.updatePosRockford = new RockfordUpdateController(levelModel); + } - switch (keyCode) { - // Direction: UP - case KeyEvent.VK_UP: - DisplayableElementModel upElement = levelModel.getGroundLevelModel()[levelModel.getRockfordPositionX()][levelModel.getRockfordPositionY() - 1]; + /** + * Handles the 'key pressed' event + * + * @param e Key event + */ + public void keyPressed(KeyEvent e) { + int keyCode = e.getKeyCode(); - if (upElement.getPriority() < levelModel.getRockford().getPriority()) { - this.updatePosRockford.moveRockford(levelModel.getRockfordPositionX(), levelModel.getRockfordPositionY() - 1); - this.levelModel.getRockford().startRunningUp(); - } + switch (keyCode) { + // Direction: UP + case KeyEvent.VK_UP: + DisplayableElementModel upElement = levelModel.getGroundLevelModel()[levelModel.getRockfordPositionX()][levelModel.getRockfordPositionY() - 1]; - break; - - // Direction: DOWN - case KeyEvent.VK_DOWN: - DisplayableElementModel downElement = levelModel.getGroundLevelModel()[levelModel.getRockfordPositionX()][levelModel.getRockfordPositionY() + 1]; - - if (downElement.getPriority() < levelModel.getRockford().getPriority()) { - this.updatePosRockford.moveRockford(levelModel.getRockfordPositionX(), levelModel.getRockfordPositionY() + 1); - this.levelModel.getRockford().startRunningDown(); - } - - break; - - // Direction: LEFT - case KeyEvent.VK_LEFT: - DisplayableElementModel leftElement = levelModel.getGroundLevelModel()[levelModel.getRockfordPositionX() - 1][levelModel.getRockfordPositionY()]; - - if (leftElement.getPriority() < levelModel.getRockford().getPriority()) { - this.updatePosRockford.moveRockford(levelModel.getRockfordPositionX() - 1, levelModel.getRockfordPositionY()); - this.levelModel.getRockford().startRunningLeft(); - } - - break; - - // Direction: RIGHT - case KeyEvent.VK_RIGHT: - DisplayableElementModel rightElement = levelModel.getGroundLevelModel()[levelModel.getRockfordPositionX() + 1][levelModel.getRockfordPositionY()]; - - if (rightElement.getPriority() < levelModel.getRockford().getPriority()) { - this.updatePosRockford.moveRockford(levelModel.getRockfordPositionX() + 1, levelModel.getRockfordPositionY()); - this.levelModel.getRockford().startRunningRight(); - } - - break; + if (upElement.getPriority() < levelModel.getRockford().getPriority()) { + this.updatePosRockford.moveRockford(levelModel.getRockfordPositionX(), levelModel.getRockfordPositionY() - 1); + this.levelModel.getRockford().startRunningUp(); } - } - /** - * Handles the 'key released' event - * - * @param e Key event - */ - @Override - public void keyReleased(KeyEvent e) { - this.levelModel.getRockford().startStaying(); - } + break; - /** - * Handles the 'key typed' event - * - * @param e Key event - */ - @Override - public void keyTyped(KeyEvent e) { - // Do nothing. - } + // Direction: DOWN + case KeyEvent.VK_DOWN: + DisplayableElementModel downElement = levelModel.getGroundLevelModel()[levelModel.getRockfordPositionX()][levelModel.getRockfordPositionY() + 1]; + + if (downElement.getPriority() < levelModel.getRockford().getPriority()) { + this.updatePosRockford.moveRockford(levelModel.getRockfordPositionX(), levelModel.getRockfordPositionY() + 1); + this.levelModel.getRockford().startRunningDown(); + } + + break; + + // Direction: LEFT + case KeyEvent.VK_LEFT: + DisplayableElementModel leftElement = levelModel.getGroundLevelModel()[levelModel.getRockfordPositionX() - 1][levelModel.getRockfordPositionY()]; + + if (leftElement.getPriority() < levelModel.getRockford().getPriority()) { + this.updatePosRockford.moveRockford(levelModel.getRockfordPositionX() - 1, levelModel.getRockfordPositionY()); + this.levelModel.getRockford().startRunningLeft(); + } + + break; + + // Direction: RIGHT + case KeyEvent.VK_RIGHT: + DisplayableElementModel rightElement = levelModel.getGroundLevelModel()[levelModel.getRockfordPositionX() + 1][levelModel.getRockfordPositionY()]; + + if (rightElement.getPriority() < levelModel.getRockford().getPriority()) { + this.updatePosRockford.moveRockford(levelModel.getRockfordPositionX() + 1, levelModel.getRockfordPositionY()); + this.levelModel.getRockford().startRunningRight(); + } + + break; + } + } + + /** + * Handles the 'key released' event + * + * @param e Key event + */ + @Override + public void keyReleased(KeyEvent e) { + this.levelModel.getRockford().startStaying(); + } + + /** + * Handles the 'key typed' event + * + * @param e Key event + */ + @Override + public void keyTyped(KeyEvent e) { + // Do nothing. + } } diff --git a/src/fr/enssat/BoulderDash/controllers/LevelEditorController.java b/src/fr/enssat/BoulderDash/controllers/LevelEditorController.java index c5a7a410..7a1ed34f 100644 --- a/src/fr/enssat/BoulderDash/controllers/LevelEditorController.java +++ b/src/fr/enssat/BoulderDash/controllers/LevelEditorController.java @@ -9,135 +9,133 @@ import fr.enssat.BoulderDash.helpers.LevelSaveHelper; import fr.enssat.BoulderDash.models.LevelModel; import fr.enssat.BoulderDash.views.HelpView; import fr.enssat.BoulderDash.views.LevelEditorView; -import fr.enssat.BoulderDash.controllers.NavigationBetweenViewController; import javax.swing.*; /** * LevelEditorController - * + *

* Manages the level editor controller. * - * @author Valerian Saliou - * @since 2015-06-19 + * @author Valerian Saliou + * @since 2015-06-19 */ -public class LevelEditorController implements ActionListener { - private LevelModel levelModel; - private LevelEditorView levelEditorView; - private NavigationBetweenViewController nav; +public class LevelEditorController extends AbstractLevelController implements ActionListener { + private LevelEditorView levelEditorView; + private NavigationBetweenViewController nav; - /** - * Class constructor' - * - * @param levelModel Level model - */ - public LevelEditorController(LevelModel levelModel, NavigationBetweenViewController nav) { - this.levelModel = levelModel; - this.levelModel.setShowCursor(true); + /** + * Class constructor' + * + * @param levelModel Level model + */ + public LevelEditorController(LevelModel levelModel, NavigationBetweenViewController nav) { + super(levelModel); + this.levelModel.setShowCursor(true); - this.nav = nav; - this.nav.getAudioLoadHelper().stopMusic(); - - this.levelEditorView = new LevelEditorView(this, levelModel, nav); + this.nav = nav; + this.nav.getAudioLoadHelper().stopMusic(); - // Pre-bind event watcher (hack to fix a Java issue) - this.levelModel.decrementCursorXPosition(); - } + this.levelEditorView = new LevelEditorView(this, levelModel, nav); - /** - * Handles the 'action performed' event - * - * @param event Action event - */ - public void actionPerformed(ActionEvent event) { - switch(event.getActionCommand()) { - case "menu": - this.levelEditorView.setVisible(false); - this.nav.setMenuView(); - this.nav.getAudioLoadHelper().startMusic("game"); + // Pre-bind event watcher (hack to fix a Java issue) + this.levelModel.decrementCursorXPosition(); + } - break; + /** + * Handles the 'action performed' event + * + * @param event Action event + */ + public void actionPerformed(ActionEvent event) { + switch (event.getActionCommand()) { + case "menu": + this.levelEditorView.setVisible(false); + this.nav.setMenuView(); + this.nav.getAudioLoadHelper().startMusic("game"); - case "save": - // Check constraints - try { - this.levelModel.checkConstraints(); + break; - // Save action (direct save) - String levelId = this.levelEditorView.getSelectedLevel(); - LevelSaveHelper levelSave; + case "save": + // Check constraints + try { + this.levelModel.checkConstraints(); - if(levelId == null || levelId.isEmpty()) { - // Create a new level - levelSave = new LevelSaveHelper(levelModel.getGroundLevelModel()); - } else { - // Overwrite existing level - levelSave = new LevelSaveHelper(levelId, levelModel.getGroundLevelModel()); - } + // Save action (direct save) + String levelId = this.levelEditorView.getSelectedLevel(); + LevelSaveHelper levelSave; - JFrame frameDialog = new JFrame("Info"); - JOptionPane.showMessageDialog(frameDialog, "Level saved"); + if (levelId == null || levelId.isEmpty()) { + // Create a new level + levelSave = new LevelSaveHelper(levelModel.getGroundLevelModel()); + } else { + // Overwrite existing level + levelSave = new LevelSaveHelper(levelId, levelModel.getGroundLevelModel()); + } - this.levelEditorView.openedLevelChange(levelSave.getLevelId()); - } catch(LevelConstraintNotRespectedException e) { - JFrame frameDialog = new JFrame("Error"); - JOptionPane.showMessageDialog(frameDialog, e.getMessage()); - } + JFrame frameDialog = new JFrame("Info"); + JOptionPane.showMessageDialog(frameDialog, "Level saved"); - break; - - case "delete": - String levelId = this.levelEditorView.getSelectedLevel(); - JFrame frameDialog = new JFrame("Info"); - - if(levelId == null || levelId.isEmpty()) { - JOptionPane.showMessageDialog(frameDialog, "Level not yet saved, no need to delete it!"); - } else { - new LevelRemoveHelper(levelId); - JOptionPane.showMessageDialog(frameDialog, "Level deleted!"); - - this.levelEditorView.openedLevelChange(null); - } - break; - - case "help": - new HelpView(); - break; - - case "new": - this.levelEditorView.openedLevelChange(null); - break; + this.levelEditorView.openedLevelChange(levelSave.getLevelId()); + } catch (LevelConstraintNotRespectedException e) { + JFrame frameDialog = new JFrame("Error"); + JOptionPane.showMessageDialog(frameDialog, e.getMessage()); } - this.getLevelEditorView().getLevelEditorGroundView().grabFocus(); + break; + + case "delete": + String levelId = this.levelEditorView.getSelectedLevel(); + JFrame frameDialog = new JFrame("Info"); + + if (levelId == null || levelId.isEmpty()) { + JOptionPane.showMessageDialog(frameDialog, "Level not yet saved, no need to delete it!"); + } else { + new LevelRemoveHelper(levelId); + JOptionPane.showMessageDialog(frameDialog, "Level deleted!"); + + this.levelEditorView.openedLevelChange(null); + } + break; + + case "help": + new HelpView(); + break; + + case "new": + this.levelEditorView.openedLevelChange(null); + break; } - /** - * Gets the level editor view - * - * @return Level editor view - */ - public LevelEditorView getLevelEditorView() { - return levelEditorView; - } + this.getLevelEditorView().getLevelEditorGroundView().grabFocus(); + } + + /** + * Gets the level editor view + * + * @return Level editor view + */ + public LevelEditorView getLevelEditorView() { + return levelEditorView; + } + + /** + * Gets level model + * + * @return Level model + */ + public LevelModel getLevelModel() { + return this.levelModel; + } + + /** + * Sets the level editor view + * + * @param levelEditorView Level editor view + */ + public void setLevelEditorView(LevelEditorView levelEditorView) { + this.levelEditorView = levelEditorView; + } - /** - * Gets level model - * - * @return Level model - */ - public LevelModel getLevelModel() { - return this.levelModel; - } - /** - * Sets the level editor view - * - * @param levelEditorView Level editor view - */ - public void setLevelEditorView(LevelEditorView levelEditorView) { - this.levelEditorView = levelEditorView; - } - - } \ No newline at end of file diff --git a/src/fr/enssat/BoulderDash/controllers/LevelEditorKeyController.java b/src/fr/enssat/BoulderDash/controllers/LevelEditorKeyController.java index 78f98d3f..6308b6eb 100644 --- a/src/fr/enssat/BoulderDash/controllers/LevelEditorKeyController.java +++ b/src/fr/enssat/BoulderDash/controllers/LevelEditorKeyController.java @@ -9,91 +9,90 @@ import java.awt.event.KeyListener; /** * LevelEditorKeyController - * + *

* Manages the key events controller. * - * @author Valerian Saliou - * @since 2015-06-21 + * @author Valerian Saliou + * @since 2015-06-21 */ -public class LevelEditorKeyController implements KeyListener { - private LevelModel levelModel; - private LevelEditorView levelEditorView; - private boolean capLocks; +public class LevelEditorKeyController extends AbstractLevelController implements KeyListener { + private LevelEditorView levelEditorView; + private boolean capLocks; - /** - * Class constructor - * - * @param levelModel Level model - * @param levelEditorView Level editor view - */ - public LevelEditorKeyController(LevelModel levelModel, LevelEditorView levelEditorView) { - this.levelModel = levelModel; - this.capLocks = false; - this.levelEditorView = levelEditorView; + /** + * Class constructor + * + * @param levelModel Level model + * @param levelEditorView Level editor view + */ + public LevelEditorKeyController(LevelModel levelModel, LevelEditorView levelEditorView) { + super(levelModel); + this.capLocks = false; + this.levelEditorView = levelEditorView; + } + + /** + * Handles the 'key pressed' event + * + * @param e Key event + */ + public void keyPressed(KeyEvent e) { + int keyCode = e.getKeyCode(); + + switch (keyCode) { + // Direction: UP + case KeyEvent.VK_UP: + this.levelModel.decrementCursorYPosition(); + break; + + // Direction: DOWN + case KeyEvent.VK_DOWN: + this.levelModel.incrementCursorYPosition(); + break; + + // Direction: LEFT + case KeyEvent.VK_LEFT: + this.levelModel.decrementCursorXPosition(); + break; + + // Direction: RIGHT + case KeyEvent.VK_RIGHT: + this.levelModel.incrementCursorXPosition(); + break; + + // Key: SPACE + case KeyEvent.VK_SPACE: + this.levelModel.triggerBlockChange(this.levelEditorView.getPickedBlockValue()); + break; + + case 16: + this.capLocks = !capLocks; + break; } - /** - * Handles the 'key pressed' event - * - * @param e Key event - */ - public void keyPressed(KeyEvent e) { - int keyCode = e.getKeyCode(); - - switch (keyCode) { - // Direction: UP - case KeyEvent.VK_UP: - this.levelModel.decrementCursorYPosition(); - break; - - // Direction: DOWN - case KeyEvent.VK_DOWN: - this.levelModel.incrementCursorYPosition(); - break; - - // Direction: LEFT - case KeyEvent.VK_LEFT: - this.levelModel.decrementCursorXPosition(); - break; - - // Direction: RIGHT - case KeyEvent.VK_RIGHT: - this.levelModel.incrementCursorXPosition(); - break; - - // Key: SPACE - case KeyEvent.VK_SPACE: - this.levelModel.triggerBlockChange(this.levelEditorView.getPickedBlockValue()); - break; - - case 16: - this.capLocks = !capLocks; - break; - } - - // Hold block change (quick edit) - if(capLocks) { - this.levelModel.triggerBlockChange(this.levelEditorView.getPickedBlockValue()); - } + // Hold block change (quick edit) + if (capLocks) { + this.levelModel.triggerBlockChange(this.levelEditorView.getPickedBlockValue()); } + } - /** - * Handles the 'key released' event - * - * @param e Key event - */ - @Override - public void keyReleased(KeyEvent e) { - // Do nothing. - } + /** + * Handles the 'key released' event + * + * @param e Key event + */ + @Override + public void keyReleased(KeyEvent e) { + // Do nothing. + } - /** - * Handles the 'key typed' event - * - * @param e Key event - */ - @Override - public void keyTyped(KeyEvent e) { - // Do nothing. - } + /** + * Handles the 'key typed' event + * + * @param e Key event + */ + @Override + public void keyTyped(KeyEvent e) { + // Do nothing. + } } diff --git a/src/fr/enssat/BoulderDash/controllers/NavigationBetweenViewController.java b/src/fr/enssat/BoulderDash/controllers/NavigationBetweenViewController.java index db190f48..6034e896 100644 --- a/src/fr/enssat/BoulderDash/controllers/NavigationBetweenViewController.java +++ b/src/fr/enssat/BoulderDash/controllers/NavigationBetweenViewController.java @@ -11,122 +11,120 @@ import fr.enssat.BoulderDash.controllers.GameController; /** * Controller to navigate between the different views - * - * @author Colin Leverger * + * @author Colin Leverger */ public class NavigationBetweenViewController implements ActionListener { - private LevelEditorController levelEditorController; - private MenuView menuView; - private AudioLoadHelper audioLoadHelper; - private LevelModel levelModelForGame, levelModelForEditor; - private GameController gameController; - private String pickedLevelIdentifier; + private LevelEditorController levelEditorController; + private MenuView menuView; + private AudioLoadHelper audioLoadHelper; + private GameController gameController; + private String pickedLevelIdentifier; - /** - * Class constructor - */ - public NavigationBetweenViewController() { - this.audioLoadHelper = new AudioLoadHelper(); + /** + * Class constructor + */ + public NavigationBetweenViewController() { + this.audioLoadHelper = new AudioLoadHelper(); - // Play game music - this.getAudioLoadHelper().startMusic("game"); + // Play game music + this.getAudioLoadHelper().startMusic("game"); - // Creation of the first view - this.menuView = new MenuView(this); - } + // Creation of the first view + this.menuView = new MenuView(this); + } - /** - * Action performed event handler - * - * @param event Action event - */ - @Override - public void actionPerformed(ActionEvent event) { - switch (event.getActionCommand()) { - case "quit": - System.exit(0); - break; + /** + * Action performed event handler + * + * @param event Action event + */ + @Override + public void actionPerformed(ActionEvent event) { + switch (event.getActionCommand()) { + case "quit": + System.exit(0); + break; - case "editor": - // New blank model for editor - this.levelModelForEditor = new LevelModel(audioLoadHelper); - this.levelEditorController = new LevelEditorController(this.levelModelForEditor, this); + case "editor": + // New blank model for editor + LevelModel levelModelForEditor = new LevelModel(audioLoadHelper); + this.levelEditorController = new LevelEditorController(levelModelForEditor, this); - this.levelEditorController.getLevelEditorView().setVisible(true); - this.levelEditorController.getLevelEditorView().getLevelEditorGroundView().grabFocus(); + this.levelEditorController.getLevelEditorView().setVisible(true); + this.levelEditorController.getLevelEditorView().getLevelEditorGroundView().grabFocus(); - if (gameController != null) { - this.gameController.getGameView().setVisible(false); - } + if (gameController != null) { + this.gameController.getGameView().setVisible(false); + } - break; + break; - case "game": - // Reinit the levelModelForGame... - pickedLevelIdentifier = this.menuView.getLevelIdentifier(); + case "game": + // Reinit the levelModelForGame... + pickedLevelIdentifier = this.menuView.getLevelIdentifier(); - this.levelModelForGame = new LevelModel(pickedLevelIdentifier, audioLoadHelper); - this.gameController = new GameController(levelModelForGame, audioLoadHelper, this); + LevelModel levelModelForGame = new LevelModel(pickedLevelIdentifier, audioLoadHelper); + this.gameController = new GameController(levelModelForGame, audioLoadHelper, this); - if (levelEditorController != null) { - this.levelEditorController.getLevelEditorView().setVisible(false); - } + if (levelEditorController != null) { + this.levelEditorController.getLevelEditorView().setVisible(false); + } - this.gameController.getGameView().setVisible(true); - this.gameController.getGameView().getGameFieldView().grabFocus(); + this.gameController.getGameView().setVisible(true); + this.gameController.getGameView().getGameFieldView().grabFocus(); - break; - } - - this.menuView.setVisible(false); - } - - /** - * Get the audio load helper - * - * @return Audio load helper - */ - public AudioLoadHelper getAudioLoadHelper() { - return this.audioLoadHelper; + break; } - /** - * Get the first view - * - * @return First view - */ - public MenuView getMenuView() { - return this.menuView; - } + this.menuView.setVisible(false); + } - /** - * Set the first view - * - * @param menuView - */ - public MenuView setMenuView() { - this.menuView = new MenuView(this); - return menuView; - } + /** + * Get the audio load helper + * + * @return Audio load helper + */ + public AudioLoadHelper getAudioLoadHelper() { + return this.audioLoadHelper; + } + + /** + * Get the first view + * + * @return First view + */ + public MenuView getMenuView() { + return this.menuView; + } + + /** + * Set the first view + * + * @param menuView + */ + public MenuView setMenuView() { + this.menuView = new MenuView(this); + 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; + } - /** - * 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; - } - - } diff --git a/src/fr/enssat/BoulderDash/controllers/RockfordUpdateController.java b/src/fr/enssat/BoulderDash/controllers/RockfordUpdateController.java index c4ecd1ba..40a7b707 100644 --- a/src/fr/enssat/BoulderDash/controllers/RockfordUpdateController.java +++ b/src/fr/enssat/BoulderDash/controllers/RockfordUpdateController.java @@ -4,7 +4,7 @@ import fr.enssat.BoulderDash.models.LevelModel; /** * ElementPositionUpdateHelper - * + *

* Updates position of all elements displayed on the map, according to their * next potential position. Each object has a weight, which is used to compare * their power to destroy in the food chain. Sorry for that Darwinism. @@ -12,53 +12,52 @@ import fr.enssat.BoulderDash.models.LevelModel; * @author Colin Leverger * @since 2015-06-19 */ -public class RockfordUpdateController implements Runnable { - private LevelModel levelModel; - private Thread elementMovingThread; - private int rockfordPositionX; - private int rockfordPositionY; - private boolean rockfordHasMoved; +public class RockfordUpdateController extends AbstractLevelController implements Runnable { + private Thread elementMovingThread; + private int rockfordPositionX; + private int rockfordPositionY; + private boolean rockfordHasMoved; - /** - * Class constructor - * - * @param levelModel Level model - */ - public RockfordUpdateController(LevelModel levelModel) { - this.levelModel = levelModel; - this.elementMovingThread = new Thread(this); - this.elementMovingThread.start(); - this.rockfordHasMoved = false; - } + /** + * Class constructor + * + * @param levelModel Level model + */ + public RockfordUpdateController(LevelModel levelModel) { + super(levelModel); + this.elementMovingThread = new Thread(this); + this.elementMovingThread.start(); + this.rockfordHasMoved = false; + } - /** - * Watches for elements to be moved - */ - public void run() { - while (this.levelModel.isGameRunning()) { - if(!this.levelModel.getGamePaused()){ - if (this.rockfordHasMoved) { - this.levelModel.setPositionOfRockford(rockfordPositionX, rockfordPositionY); - this.rockfordHasMoved = false; - } - } - try { - Thread.sleep(100); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - } - - /** - * Moves Rockford - * - * @param rockfordPositionX Next horizontal position on the grid - * @param rockfordPositionY Next vertical position on the grid - */ - public void moveRockford(int rockfordPositionX, int rockfordPositionY) { - this.rockfordPositionX = rockfordPositionX; - this.rockfordPositionY = rockfordPositionY; - this.rockfordHasMoved = true; - } + /** + * Watches for elements to be moved + */ + public void run() { + while (this.levelModel.isGameRunning()) { + if (!this.levelModel.getGamePaused()) { + if (this.rockfordHasMoved) { + this.levelModel.setPositionOfRockford(rockfordPositionX, rockfordPositionY); + this.rockfordHasMoved = false; + } + } + try { + Thread.sleep(100); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + + /** + * Moves Rockford + * + * @param rockfordPositionX Next horizontal position on the grid + * @param rockfordPositionY Next vertical position on the grid + */ + public void moveRockford(int rockfordPositionX, int rockfordPositionY) { + this.rockfordPositionX = rockfordPositionX; + this.rockfordPositionY = rockfordPositionY; + this.rockfordHasMoved = true; + } } From f40b8b4492e7c4d3e5a4d1afbb19886f37b0dd07 Mon Sep 17 00:00:00 2001 From: Daniel Langbein Date: Thu, 7 Nov 2024 16:17:42 +0100 Subject: [PATCH 3/7] AudioLoadHelper singleton --- .../BoulderAndDiamondController.java | 9 +- .../controllers/GameController.java | 39 +- .../controllers/GameKeyController.java | 5 +- .../controllers/LevelEditorController.java | 32 +- .../NavigationBetweenViewController.java | 40 +- .../BoulderDash/helpers/AudioLoadHelper.java | 8 +- .../enssat/BoulderDash/models/LevelModel.java | 1488 ++++++++--------- .../BoulderDash/views/GameGroundView.java | 2 +- .../BoulderDash/views/LevelEditorView.java | 4 +- 9 files changed, 789 insertions(+), 838 deletions(-) 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 * @since 2015-06-19 */ public class AudioLoadHelper { - private static String pathToAudioStore = "./res/audio"; + private static final String pathToAudioStore = "./res/audio"; + /** + * Singleton + */ + public static final AudioLoadHelper AUDIO_LOAD_HELPER = new AudioLoadHelper(); private SoundJLayerBridge musicToPlay; private HashMap preloadedSounds; diff --git a/src/fr/enssat/BoulderDash/models/LevelModel.java b/src/fr/enssat/BoulderDash/models/LevelModel.java index cbb5415a..796a1798 100644 --- a/src/fr/enssat/BoulderDash/models/LevelModel.java +++ b/src/fr/enssat/BoulderDash/models/LevelModel.java @@ -3,26 +3,17 @@ package fr.enssat.BoulderDash.models; import fr.enssat.BoulderDash.exceptions.LevelConstraintNotRespectedException; import fr.enssat.BoulderDash.exceptions.UnknownModelException; import fr.enssat.BoulderDash.helpers.LevelLoadHelper; -import fr.enssat.BoulderDash.helpers.AudioLoadHelper; import fr.enssat.BoulderDash.helpers.ModelConvertHelper; -import fr.enssat.BoulderDash.models.DisplayableElementModel; -import fr.enssat.BoulderDash.models.RockfordModel; -import fr.enssat.BoulderDash.models.GameInformationModel; -import fr.enssat.BoulderDash.models.SteelWallModel; -import fr.enssat.BoulderDash.models.EmptyModel; -import fr.enssat.BoulderDash.models.DiamondModel; -import fr.enssat.BoulderDash.models.DoorModel; -import fr.enssat.BoulderDash.models.DirtModel; -import fr.enssat.BoulderDash.models.ExpandingWallModel; -import fr.enssat.BoulderDash.models.CursorModel; import java.awt.image.BufferedImage; import java.util.Observable; +import static fr.enssat.BoulderDash.helpers.AudioLoadHelper.AUDIO_LOAD_HELPER; + /** * LevelModel - * + *

* 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); From 2247c7f43de3f728c698a744f2162fded1b1c7d6 Mon Sep 17 00:00:00 2001 From: Daniel Langbein Date: Thu, 7 Nov 2024 18:20:47 +0100 Subject: [PATCH 4/7] mv nav field to superclass --- .../controllers/AbstractNavController.java | 14 ++++++++++++++ .../BoulderDash/controllers/GameController.java | 15 ++++++--------- .../controllers/LevelEditorController.java | 8 +++----- 3 files changed, 23 insertions(+), 14 deletions(-) create mode 100644 src/fr/enssat/BoulderDash/controllers/AbstractNavController.java diff --git a/src/fr/enssat/BoulderDash/controllers/AbstractNavController.java b/src/fr/enssat/BoulderDash/controllers/AbstractNavController.java new file mode 100644 index 00000000..7ae5cb96 --- /dev/null +++ b/src/fr/enssat/BoulderDash/controllers/AbstractNavController.java @@ -0,0 +1,14 @@ +package fr.enssat.BoulderDash.controllers; + +import fr.enssat.BoulderDash.models.LevelModel; + +import java.awt.event.ActionListener; + +public abstract class AbstractNavController extends AbstractLevelController implements ActionListener { + protected NavigationBetweenViewController nav; + + public AbstractNavController(LevelModel levelModel, NavigationBetweenViewController nav) { + super(levelModel); + this.nav = nav; + } +} diff --git a/src/fr/enssat/BoulderDash/controllers/GameController.java b/src/fr/enssat/BoulderDash/controllers/GameController.java index 79e37f9f..cb013fd0 100644 --- a/src/fr/enssat/BoulderDash/controllers/GameController.java +++ b/src/fr/enssat/BoulderDash/controllers/GameController.java @@ -19,27 +19,24 @@ import static fr.enssat.BoulderDash.helpers.AudioLoadHelper.AUDIO_LOAD_HELPER; * @author Colin Leverger * @since 2015-06-19 */ -public class GameController extends AbstractLevelController implements ActionListener { +public class GameController extends AbstractNavController { private boolean firstClickOnPause; private MenuView menuView; private GameView gameView; - private NavigationBetweenViewController navigationBetweenViewController; /** * Class constructor * * @param levelModel Level model - * @param navigationBetweenViewController + * @param nav */ - public GameController(LevelModel levelModel, NavigationBetweenViewController navigationBetweenViewController) { - super(levelModel); + public GameController(LevelModel levelModel, NavigationBetweenViewController nav) { + super(levelModel, nav); this.firstClickOnPause = true; - this.navigationBetweenViewController = navigationBetweenViewController; - this.gameView = new GameView(this, levelModel); - this.menuView = navigationBetweenViewController.getMenuView(); + this.menuView = nav.getMenuView(); AUDIO_LOAD_HELPER.stopMusic(); AUDIO_LOAD_HELPER.playSound("new"); @@ -84,7 +81,7 @@ public class GameController extends AbstractLevelController implements ActionLis this.gameView.dispose(); if (source.equals("restart")) { - this.levelModel = new LevelModel(this.navigationBetweenViewController.getPickedLevelIdentifier()); + this.levelModel = new LevelModel(this.nav.getPickedLevelIdentifier()); this.gameView = new GameView(this, levelModel); this.gameView.setVisible(true); } diff --git a/src/fr/enssat/BoulderDash/controllers/LevelEditorController.java b/src/fr/enssat/BoulderDash/controllers/LevelEditorController.java index 2f2130cc..1e3ef664 100644 --- a/src/fr/enssat/BoulderDash/controllers/LevelEditorController.java +++ b/src/fr/enssat/BoulderDash/controllers/LevelEditorController.java @@ -22,20 +22,18 @@ import static fr.enssat.BoulderDash.helpers.AudioLoadHelper.AUDIO_LOAD_HELPER; * @author Valerian Saliou * @since 2015-06-19 */ -public class LevelEditorController extends AbstractLevelController implements ActionListener { +public class LevelEditorController extends AbstractNavController { private LevelEditorView levelEditorView; - private NavigationBetweenViewController nav; /** - * Class constructor' + * Class constructor * * @param levelModel Level model */ public LevelEditorController(LevelModel levelModel, NavigationBetweenViewController nav) { - super(levelModel); + super(levelModel, nav); this.levelModel.setShowCursor(true); - this.nav = nav; AUDIO_LOAD_HELPER.stopMusic(); this.levelEditorView = new LevelEditorView(this, levelModel, nav); From 59a7ecff2edfb8523e31d10595c6d53bfbfe9915 Mon Sep 17 00:00:00 2001 From: Daniel Langbein Date: Thu, 7 Nov 2024 18:54:47 +0100 Subject: [PATCH 5/7] superclass implements KeyListener --- .../controllers/AbstractKeyController.java | 46 +++++++++ .../controllers/GameKeyController.java | 97 ++++++++----------- .../controllers/LevelEditorKeyController.java | 77 +++++++-------- 3 files changed, 124 insertions(+), 96 deletions(-) create mode 100644 src/fr/enssat/BoulderDash/controllers/AbstractKeyController.java diff --git a/src/fr/enssat/BoulderDash/controllers/AbstractKeyController.java b/src/fr/enssat/BoulderDash/controllers/AbstractKeyController.java new file mode 100644 index 00000000..aea60a86 --- /dev/null +++ b/src/fr/enssat/BoulderDash/controllers/AbstractKeyController.java @@ -0,0 +1,46 @@ +package fr.enssat.BoulderDash.controllers; + +import fr.enssat.BoulderDash.models.LevelModel; + +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; + +public abstract class AbstractKeyController extends AbstractLevelController implements KeyListener { + public AbstractKeyController(LevelModel levelModel) { + super(levelModel); + } + + /** + * Handles the 'key pressed' event + * + * @param e Key event + */ + public void keyPressed(KeyEvent e) { + handleKey(e.getKeyCode()); + additionalSteps(); + } + + protected abstract void handleKey(final int keyCode); + + protected void additionalSteps(){} + + /** + * Handles the 'key released' event + * + * @param e Key event + */ + @Override + public void keyReleased(KeyEvent e) { + // Do nothing. + } + + /** + * Handles the 'key typed' event + * + * @param e Key event + */ + @Override + public void keyTyped(KeyEvent e) { + // Do nothing. + } +} diff --git a/src/fr/enssat/BoulderDash/controllers/GameKeyController.java b/src/fr/enssat/BoulderDash/controllers/GameKeyController.java index 45fb0b0e..b791b5b8 100644 --- a/src/fr/enssat/BoulderDash/controllers/GameKeyController.java +++ b/src/fr/enssat/BoulderDash/controllers/GameKeyController.java @@ -15,7 +15,7 @@ import java.awt.event.KeyListener; * @author Colin Leverger * @since 2015-06-19 */ -public class GameKeyController extends AbstractLevelController implements KeyListener { +public class GameKeyController extends AbstractKeyController { private RockfordUpdateController updatePosRockford; /** @@ -29,61 +29,60 @@ public class GameKeyController extends AbstractLevelController implements KeyLis this.updatePosRockford = new RockfordUpdateController(levelModel); } - /** - * Handles the 'key pressed' event - * - * @param e Key event - */ - public void keyPressed(KeyEvent e) { - int keyCode = e.getKeyCode(); - + @Override + protected void handleKey(final int keyCode) { switch (keyCode) { - // Direction: UP case KeyEvent.VK_UP: - DisplayableElementModel upElement = levelModel.getGroundLevelModel()[levelModel.getRockfordPositionX()][levelModel.getRockfordPositionY() - 1]; - - if (upElement.getPriority() < levelModel.getRockford().getPriority()) { - this.updatePosRockford.moveRockford(levelModel.getRockfordPositionX(), levelModel.getRockfordPositionY() - 1); - this.levelModel.getRockford().startRunningUp(); - } - + up(); break; - - // Direction: DOWN case KeyEvent.VK_DOWN: - DisplayableElementModel downElement = levelModel.getGroundLevelModel()[levelModel.getRockfordPositionX()][levelModel.getRockfordPositionY() + 1]; - - if (downElement.getPriority() < levelModel.getRockford().getPriority()) { - this.updatePosRockford.moveRockford(levelModel.getRockfordPositionX(), levelModel.getRockfordPositionY() + 1); - this.levelModel.getRockford().startRunningDown(); - } - + down(); break; - - // Direction: LEFT case KeyEvent.VK_LEFT: - DisplayableElementModel leftElement = levelModel.getGroundLevelModel()[levelModel.getRockfordPositionX() - 1][levelModel.getRockfordPositionY()]; - - if (leftElement.getPriority() < levelModel.getRockford().getPriority()) { - this.updatePosRockford.moveRockford(levelModel.getRockfordPositionX() - 1, levelModel.getRockfordPositionY()); - this.levelModel.getRockford().startRunningLeft(); - } - + left(); break; - - // Direction: RIGHT case KeyEvent.VK_RIGHT: - DisplayableElementModel rightElement = levelModel.getGroundLevelModel()[levelModel.getRockfordPositionX() + 1][levelModel.getRockfordPositionY()]; - - if (rightElement.getPriority() < levelModel.getRockford().getPriority()) { - this.updatePosRockford.moveRockford(levelModel.getRockfordPositionX() + 1, levelModel.getRockfordPositionY()); - this.levelModel.getRockford().startRunningRight(); - } - + right(); break; } } + private void right() { + DisplayableElementModel rightElement = levelModel.getGroundLevelModel()[levelModel.getRockfordPositionX() + 1][levelModel.getRockfordPositionY()]; + + if (rightElement.getPriority() < levelModel.getRockford().getPriority()) { + this.updatePosRockford.moveRockford(levelModel.getRockfordPositionX() + 1, levelModel.getRockfordPositionY()); + this.levelModel.getRockford().startRunningRight(); + } + } + + private void left() { + DisplayableElementModel leftElement = levelModel.getGroundLevelModel()[levelModel.getRockfordPositionX() - 1][levelModel.getRockfordPositionY()]; + + if (leftElement.getPriority() < levelModel.getRockford().getPriority()) { + this.updatePosRockford.moveRockford(levelModel.getRockfordPositionX() - 1, levelModel.getRockfordPositionY()); + this.levelModel.getRockford().startRunningLeft(); + } + } + + private void down() { + DisplayableElementModel downElement = levelModel.getGroundLevelModel()[levelModel.getRockfordPositionX()][levelModel.getRockfordPositionY() + 1]; + + if (downElement.getPriority() < levelModel.getRockford().getPriority()) { + this.updatePosRockford.moveRockford(levelModel.getRockfordPositionX(), levelModel.getRockfordPositionY() + 1); + this.levelModel.getRockford().startRunningDown(); + } + } + + private void up() { + DisplayableElementModel upElement = levelModel.getGroundLevelModel()[levelModel.getRockfordPositionX()][levelModel.getRockfordPositionY() - 1]; + + if (upElement.getPriority() < levelModel.getRockford().getPriority()) { + this.updatePosRockford.moveRockford(levelModel.getRockfordPositionX(), levelModel.getRockfordPositionY() - 1); + this.levelModel.getRockford().startRunningUp(); + } + } + /** * Handles the 'key released' event * @@ -93,14 +92,4 @@ public class GameKeyController extends AbstractLevelController implements KeyLis public void keyReleased(KeyEvent e) { this.levelModel.getRockford().startStaying(); } - - /** - * Handles the 'key typed' event - * - * @param e Key event - */ - @Override - public void keyTyped(KeyEvent e) { - // Do nothing. - } } diff --git a/src/fr/enssat/BoulderDash/controllers/LevelEditorKeyController.java b/src/fr/enssat/BoulderDash/controllers/LevelEditorKeyController.java index 6308b6eb..3883cb95 100644 --- a/src/fr/enssat/BoulderDash/controllers/LevelEditorKeyController.java +++ b/src/fr/enssat/BoulderDash/controllers/LevelEditorKeyController.java @@ -15,7 +15,7 @@ import java.awt.event.KeyListener; * @author Valerian Saliou * @since 2015-06-21 */ -public class LevelEditorKeyController extends AbstractLevelController implements KeyListener { +public class LevelEditorKeyController extends AbstractKeyController { private LevelEditorView levelEditorView; private boolean capLocks; @@ -31,68 +31,61 @@ public class LevelEditorKeyController extends AbstractLevelController implements this.levelEditorView = levelEditorView; } - /** - * Handles the 'key pressed' event - * - * @param e Key event - */ - public void keyPressed(KeyEvent e) { - int keyCode = e.getKeyCode(); - + @Override + protected void handleKey(final int keyCode) { switch (keyCode) { - // Direction: UP case KeyEvent.VK_UP: - this.levelModel.decrementCursorYPosition(); + up(); break; - - // Direction: DOWN case KeyEvent.VK_DOWN: - this.levelModel.incrementCursorYPosition(); + down(); break; - - // Direction: LEFT case KeyEvent.VK_LEFT: - this.levelModel.decrementCursorXPosition(); + left(); break; - - // Direction: RIGHT case KeyEvent.VK_RIGHT: - this.levelModel.incrementCursorXPosition(); + right(); break; - - // Key: SPACE case KeyEvent.VK_SPACE: - this.levelModel.triggerBlockChange(this.levelEditorView.getPickedBlockValue()); + space(); break; - - case 16: - this.capLocks = !capLocks; + case KeyEvent.VK_SHIFT: + shift(); break; } + } + @Override + protected void additionalSteps() { // Hold block change (quick edit) if (capLocks) { this.levelModel.triggerBlockChange(this.levelEditorView.getPickedBlockValue()); } } - /** - * Handles the 'key released' event - * - * @param e Key event - */ - @Override - public void keyReleased(KeyEvent e) { - // Do nothing. + private void shift() { + this.capLocks = !capLocks; } - /** - * Handles the 'key typed' event - * - * @param e Key event - */ - @Override - public void keyTyped(KeyEvent e) { - // Do nothing. + private void space() { + this.levelModel.triggerBlockChange(this.levelEditorView.getPickedBlockValue()); } + + private void right() { + this.levelModel.incrementCursorXPosition(); + } + + private void left() { + this.levelModel.decrementCursorXPosition(); + } + + private void down() { + this.levelModel.incrementCursorYPosition(); + } + + private void up() { + this.levelModel.decrementCursorYPosition(); + return; + } + } From d350b1eb1cd263754ee73755f2c18e1da80f6044 Mon Sep 17 00:00:00 2001 From: Daniel Langbein Date: Thu, 7 Nov 2024 19:02:31 +0100 Subject: [PATCH 6/7] common key action methods --- .../controllers/AbstractKeyController.java | 45 +++++++++++- .../controllers/GameKeyController.java | 62 +++++++--------- .../controllers/LevelEditorKeyController.java | 71 +++++++------------ 3 files changed, 93 insertions(+), 85 deletions(-) diff --git a/src/fr/enssat/BoulderDash/controllers/AbstractKeyController.java b/src/fr/enssat/BoulderDash/controllers/AbstractKeyController.java index aea60a86..63b92619 100644 --- a/src/fr/enssat/BoulderDash/controllers/AbstractKeyController.java +++ b/src/fr/enssat/BoulderDash/controllers/AbstractKeyController.java @@ -20,9 +20,50 @@ public abstract class AbstractKeyController extends AbstractLevelController impl additionalSteps(); } - protected abstract void handleKey(final int keyCode); + protected void handleKey(final int keyCode) { + switch (keyCode) { + case KeyEvent.VK_UP: + up(); + break; + case KeyEvent.VK_DOWN: + down(); + break; + case KeyEvent.VK_LEFT: + left(); + break; + case KeyEvent.VK_RIGHT: + right(); + break; + case KeyEvent.VK_SPACE: + space(); + break; + case KeyEvent.VK_SHIFT: + shift(); + break; + } + } - protected void additionalSteps(){} + protected void up() { + } + + protected void down() { + } + + protected void left() { + } + + protected void right() { + } + + protected void space() { + } + + protected void shift() { + } + + + protected void additionalSteps() { + } /** * Handles the 'key released' event diff --git a/src/fr/enssat/BoulderDash/controllers/GameKeyController.java b/src/fr/enssat/BoulderDash/controllers/GameKeyController.java index b791b5b8..ac2d1069 100644 --- a/src/fr/enssat/BoulderDash/controllers/GameKeyController.java +++ b/src/fr/enssat/BoulderDash/controllers/GameKeyController.java @@ -30,42 +30,17 @@ public class GameKeyController extends AbstractKeyController { } @Override - protected void handleKey(final int keyCode) { - switch (keyCode) { - case KeyEvent.VK_UP: - up(); - break; - case KeyEvent.VK_DOWN: - down(); - break; - case KeyEvent.VK_LEFT: - left(); - break; - case KeyEvent.VK_RIGHT: - right(); - break; + protected void up() { + DisplayableElementModel upElement = levelModel.getGroundLevelModel()[levelModel.getRockfordPositionX()][levelModel.getRockfordPositionY() - 1]; + + if (upElement.getPriority() < levelModel.getRockford().getPriority()) { + this.updatePosRockford.moveRockford(levelModel.getRockfordPositionX(), levelModel.getRockfordPositionY() - 1); + this.levelModel.getRockford().startRunningUp(); } } - private void right() { - DisplayableElementModel rightElement = levelModel.getGroundLevelModel()[levelModel.getRockfordPositionX() + 1][levelModel.getRockfordPositionY()]; - - if (rightElement.getPriority() < levelModel.getRockford().getPriority()) { - this.updatePosRockford.moveRockford(levelModel.getRockfordPositionX() + 1, levelModel.getRockfordPositionY()); - this.levelModel.getRockford().startRunningRight(); - } - } - - private void left() { - DisplayableElementModel leftElement = levelModel.getGroundLevelModel()[levelModel.getRockfordPositionX() - 1][levelModel.getRockfordPositionY()]; - - if (leftElement.getPriority() < levelModel.getRockford().getPriority()) { - this.updatePosRockford.moveRockford(levelModel.getRockfordPositionX() - 1, levelModel.getRockfordPositionY()); - this.levelModel.getRockford().startRunningLeft(); - } - } - - private void down() { + @Override + protected void down() { DisplayableElementModel downElement = levelModel.getGroundLevelModel()[levelModel.getRockfordPositionX()][levelModel.getRockfordPositionY() + 1]; if (downElement.getPriority() < levelModel.getRockford().getPriority()) { @@ -74,12 +49,23 @@ public class GameKeyController extends AbstractKeyController { } } - private void up() { - DisplayableElementModel upElement = levelModel.getGroundLevelModel()[levelModel.getRockfordPositionX()][levelModel.getRockfordPositionY() - 1]; + @Override + protected void left() { + DisplayableElementModel leftElement = levelModel.getGroundLevelModel()[levelModel.getRockfordPositionX() - 1][levelModel.getRockfordPositionY()]; - if (upElement.getPriority() < levelModel.getRockford().getPriority()) { - this.updatePosRockford.moveRockford(levelModel.getRockfordPositionX(), levelModel.getRockfordPositionY() - 1); - this.levelModel.getRockford().startRunningUp(); + if (leftElement.getPriority() < levelModel.getRockford().getPriority()) { + this.updatePosRockford.moveRockford(levelModel.getRockfordPositionX() - 1, levelModel.getRockfordPositionY()); + this.levelModel.getRockford().startRunningLeft(); + } + } + + @Override + protected void right() { + DisplayableElementModel rightElement = levelModel.getGroundLevelModel()[levelModel.getRockfordPositionX() + 1][levelModel.getRockfordPositionY()]; + + if (rightElement.getPriority() < levelModel.getRockford().getPriority()) { + this.updatePosRockford.moveRockford(levelModel.getRockfordPositionX() + 1, levelModel.getRockfordPositionY()); + this.levelModel.getRockford().startRunningRight(); } } diff --git a/src/fr/enssat/BoulderDash/controllers/LevelEditorKeyController.java b/src/fr/enssat/BoulderDash/controllers/LevelEditorKeyController.java index 3883cb95..88291724 100644 --- a/src/fr/enssat/BoulderDash/controllers/LevelEditorKeyController.java +++ b/src/fr/enssat/BoulderDash/controllers/LevelEditorKeyController.java @@ -31,30 +31,6 @@ public class LevelEditorKeyController extends AbstractKeyController { this.levelEditorView = levelEditorView; } - @Override - protected void handleKey(final int keyCode) { - switch (keyCode) { - case KeyEvent.VK_UP: - up(); - break; - case KeyEvent.VK_DOWN: - down(); - break; - case KeyEvent.VK_LEFT: - left(); - break; - case KeyEvent.VK_RIGHT: - right(); - break; - case KeyEvent.VK_SPACE: - space(); - break; - case KeyEvent.VK_SHIFT: - shift(); - break; - } - } - @Override protected void additionalSteps() { // Hold block change (quick edit) @@ -63,29 +39,34 @@ public class LevelEditorKeyController extends AbstractKeyController { } } - private void shift() { - this.capLocks = !capLocks; - } - - private void space() { - this.levelModel.triggerBlockChange(this.levelEditorView.getPickedBlockValue()); - } - - private void right() { - this.levelModel.incrementCursorXPosition(); - } - - private void left() { - this.levelModel.decrementCursorXPosition(); - } - - private void down() { - this.levelModel.incrementCursorYPosition(); - } - - private void up() { + @Override + protected void up() { this.levelModel.decrementCursorYPosition(); return; } + @Override + protected void down() { + this.levelModel.incrementCursorYPosition(); + } + + @Override + protected void left() { + this.levelModel.decrementCursorXPosition(); + } + + @Override + protected void right() { + this.levelModel.incrementCursorXPosition(); + } + + @Override + protected void space() { + this.levelModel.triggerBlockChange(this.levelEditorView.getPickedBlockValue()); + } + + @Override + protected void shift() { + this.capLocks = !capLocks; + } } From f8cb868e55068429e1a3dcf4afb8b2899edf3681 Mon Sep 17 00:00:00 2001 From: Daniel Langbein Date: Thu, 7 Nov 2024 20:49:33 +0100 Subject: [PATCH 7/7] rm unused imports --- src/fr/enssat/BoulderDash/controllers/GameController.java | 1 - src/fr/enssat/BoulderDash/controllers/GameKeyController.java | 1 - .../enssat/BoulderDash/controllers/LevelEditorController.java | 1 - .../BoulderDash/controllers/LevelEditorKeyController.java | 3 --- 4 files changed, 6 deletions(-) diff --git a/src/fr/enssat/BoulderDash/controllers/GameController.java b/src/fr/enssat/BoulderDash/controllers/GameController.java index cb013fd0..8a908652 100644 --- a/src/fr/enssat/BoulderDash/controllers/GameController.java +++ b/src/fr/enssat/BoulderDash/controllers/GameController.java @@ -5,7 +5,6 @@ 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; diff --git a/src/fr/enssat/BoulderDash/controllers/GameKeyController.java b/src/fr/enssat/BoulderDash/controllers/GameKeyController.java index ac2d1069..1721ead7 100644 --- a/src/fr/enssat/BoulderDash/controllers/GameKeyController.java +++ b/src/fr/enssat/BoulderDash/controllers/GameKeyController.java @@ -4,7 +4,6 @@ import fr.enssat.BoulderDash.models.DisplayableElementModel; import fr.enssat.BoulderDash.models.LevelModel; import java.awt.event.KeyEvent; -import java.awt.event.KeyListener; /** diff --git a/src/fr/enssat/BoulderDash/controllers/LevelEditorController.java b/src/fr/enssat/BoulderDash/controllers/LevelEditorController.java index 1e3ef664..a64aa607 100644 --- a/src/fr/enssat/BoulderDash/controllers/LevelEditorController.java +++ b/src/fr/enssat/BoulderDash/controllers/LevelEditorController.java @@ -1,7 +1,6 @@ package fr.enssat.BoulderDash.controllers; import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import fr.enssat.BoulderDash.exceptions.LevelConstraintNotRespectedException; import fr.enssat.BoulderDash.helpers.LevelRemoveHelper; diff --git a/src/fr/enssat/BoulderDash/controllers/LevelEditorKeyController.java b/src/fr/enssat/BoulderDash/controllers/LevelEditorKeyController.java index 88291724..1f399b18 100644 --- a/src/fr/enssat/BoulderDash/controllers/LevelEditorKeyController.java +++ b/src/fr/enssat/BoulderDash/controllers/LevelEditorKeyController.java @@ -3,9 +3,6 @@ package fr.enssat.BoulderDash.controllers; import fr.enssat.BoulderDash.models.LevelModel; import fr.enssat.BoulderDash.views.LevelEditorView; -import java.awt.event.KeyEvent; -import java.awt.event.KeyListener; - /** * LevelEditorKeyController