Merge branch 'ueb03-daniel2' into ueb03

# Conflicts:
#	.idea/misc.xml
#	src/fr/enssat/BoulderDash/controllers/GameController.java
#	src/fr/enssat/BoulderDash/controllers/GameKeyController.java
#	src/fr/enssat/BoulderDash/controllers/LevelEditorController.java
#	src/fr/enssat/BoulderDash/controllers/LevelEditorKeyController.java
This commit is contained in:
0nlineSam 2024-11-07 20:55:12 +01:00
commit a8dc0b20c7
15 changed files with 1399 additions and 1357 deletions

2
.idea/misc.xml generated
View File

@ -3,7 +3,7 @@
<component name="PDMPlugin"> <component name="PDMPlugin">
<option name="skipTestSources" value="false" /> <option name="skipTestSources" value="false" />
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="openjdk-21" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="openjdk-21" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/classes" /> <output url="file://$PROJECT_DIR$/classes" />
</component> </component>
</project> </project>

View File

@ -0,0 +1,87 @@
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 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 up() {
}
protected void down() {
}
protected void left() {
}
protected void right() {
}
protected void space() {
}
protected void shift() {
}
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.
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -3,11 +3,12 @@ package fr.enssat.BoulderDash.controllers;
import fr.enssat.BoulderDash.models.LevelModel; import fr.enssat.BoulderDash.models.LevelModel;
import fr.enssat.BoulderDash.models.DirtModel; import fr.enssat.BoulderDash.models.DirtModel;
import fr.enssat.BoulderDash.models.DisplayableElementModel; import fr.enssat.BoulderDash.models.DisplayableElementModel;
import fr.enssat.BoulderDash.helpers.AudioLoadHelper;
import static fr.enssat.BoulderDash.helpers.AudioLoadHelper.AUDIO_LOAD_HELPER;
/** /**
* ElementPositionUpdateHelper * ElementPositionUpdateHelper
* * <p>
* Updates position of all elements displayed on the map, according to their * 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 * 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. * their power to destroy in the food chain. Sorry for that Darwinism.
@ -15,9 +16,7 @@ import fr.enssat.BoulderDash.helpers.AudioLoadHelper;
* @author Colin Leverger <me@colinleverger.fr> * @author Colin Leverger <me@colinleverger.fr>
* @since 2015-06-19 * @since 2015-06-19
*/ */
public class BoulderAndDiamondController implements Runnable { public class BoulderAndDiamondController extends AbstractLevelController implements Runnable {
private LevelModel levelModel;
private AudioLoadHelper audioLoadHelper;
private Thread elementMovingThread; private Thread elementMovingThread;
/** /**
@ -25,9 +24,8 @@ public class BoulderAndDiamondController implements Runnable {
* *
* @param levelModel Level model * @param levelModel Level model
*/ */
public BoulderAndDiamondController(LevelModel levelModel, AudioLoadHelper audioLoadHelper) { public BoulderAndDiamondController(LevelModel levelModel) {
this.levelModel = levelModel; super(levelModel);
this.audioLoadHelper = audioLoadHelper;
// Start thread // Start thread
this.elementMovingThread = new Thread(this); this.elementMovingThread = new Thread(this);
@ -132,7 +130,7 @@ public class BoulderAndDiamondController implements Runnable {
} else if (spriteNameBelow == "rockford" && this.levelModel.getGroundLevelModel()[x][y].isFalling()) { } else if (spriteNameBelow == "rockford" && this.levelModel.getGroundLevelModel()[x][y].isFalling()) {
this.levelModel.exploseGround(x, y + 1); this.levelModel.exploseGround(x, y + 1);
this.audioLoadHelper.playSound("die"); AUDIO_LOAD_HELPER.playSound("die");
try { try {
Thread.sleep(25); Thread.sleep(25);

View File

@ -1,24 +1,24 @@
package fr.enssat.BoulderDash.controllers; package fr.enssat.BoulderDash.controllers;
import fr.enssat.BoulderDash.models.LevelModel; import fr.enssat.BoulderDash.models.LevelModel;
import fr.enssat.BoulderDash.helpers.AudioLoadHelper;
import fr.enssat.BoulderDash.views.MenuView; import fr.enssat.BoulderDash.views.MenuView;
import fr.enssat.BoulderDash.views.GameView; import fr.enssat.BoulderDash.views.GameView;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import static fr.enssat.BoulderDash.helpers.AudioLoadHelper.AUDIO_LOAD_HELPER;
/** /**
* GameController * GameController
* * <p>
* This system creates the view. * This system creates the view.
* The game loop is also handled there. * The game loop is also handled there.
* *
* @author Colin Leverger <me@colinleverger.fr> * @author Colin Leverger <me@colinleverger.fr>
* @since 2015-06-19 * @since 2015-06-19
*/ */
public class GameController extends GameModuleController { public class GameController extends AbstractNavController {
private AudioLoadHelper audioLoadHelper;
private boolean firstClickOnPause; private boolean firstClickOnPause;
private MenuView menuView; private MenuView menuView;
private GameView gameView; private GameView gameView;
@ -27,18 +27,18 @@ public class GameController extends GameModuleController {
* Class constructor * Class constructor
* *
* @param levelModel Level model * @param levelModel Level model
* @param navigationBetweenViewController * @param nav
*/ */
public GameController(LevelModel levelModel, AudioLoadHelper audioLoadHelper, NavigationBetweenViewController navigationBetweenViewController) { public GameController(LevelModel levelModel, NavigationBetweenViewController nav) {
super(levelModel, navigationBetweenViewController); super(levelModel, nav);
this.firstClickOnPause = true; this.firstClickOnPause = true;
this.audioLoadHelper = audioLoadHelper;
this.gameView = new GameView(this, levelModel); this.gameView = new GameView(this, levelModel);
this.menuView = navigationBetweenViewController.getMenuView(); this.menuView = nav.getMenuView();
this.getAudioLoadHelper().stopMusic(); AUDIO_LOAD_HELPER.stopMusic();
this.getAudioLoadHelper().playSound("new"); AUDIO_LOAD_HELPER.playSound("new");
} }
/** /**
@ -46,12 +46,14 @@ public class GameController extends GameModuleController {
* *
* @param event Action event * @param event Action event
*/ */
@Override
public void actionPerformed(ActionEvent event) { public void actionPerformed(ActionEvent event) {
switch (event.getActionCommand()) { switch (event.getActionCommand()) {
case "pause": case "pause":
LevelModel levelModel = getLevelModel(); if (this.firstClickOnPause) {
levelModel.setGamePaused(this.firstClickOnPause); this.levelModel.setGamePaused(true);
} else if (!this.firstClickOnPause) {
this.levelModel.setGamePaused(false);
}
this.firstClickOnPause = !this.firstClickOnPause; this.firstClickOnPause = !this.firstClickOnPause;
this.gameView.getGameFieldView().grabFocus(); this.gameView.getGameFieldView().grabFocus();
@ -59,13 +61,13 @@ public class GameController extends GameModuleController {
case "restart": case "restart":
this.resetGame("restart"); this.resetGame("restart");
this.getAudioLoadHelper().playSound("new"); AUDIO_LOAD_HELPER.playSound("new");
this.gameView.getGameFieldView().grabFocus(); this.gameView.getGameFieldView().grabFocus();
break; break;
case "menu": case "menu":
this.menuView.setVisible(true); this.menuView.setVisible(true);
this.getAudioLoadHelper().startMusic("game"); AUDIO_LOAD_HELPER.startMusic("game");
this.resetGame("menu"); this.resetGame("menu");
break; break;
} }
@ -78,35 +80,24 @@ public class GameController extends GameModuleController {
this.gameView.dispose(); this.gameView.dispose();
if (source.equals("restart")) { if (source.equals("restart")) {
resetLevelModel(this.audioLoadHelper); this.levelModel = new LevelModel(this.nav.getPickedLevelIdentifier());
LevelModel levelModel = getLevelModel();
this.gameView = new GameView(this, levelModel); this.gameView = new GameView(this, levelModel);
this.gameView.setVisible(true); 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 the game view
*
* @return gameView * @return gameView
*/ */
public GameView getGameView() { public GameView getGameView() {
return gameView; return gameView;
} }
/** // dead code
* Set the gameView //
* @param gameView //public void setGameView(GameView gameView) {
*/ // this.gameView = gameView;
public void setGameView(GameView gameView) { //}
this.gameView = gameView;
}
} }

View File

@ -2,92 +2,79 @@ package fr.enssat.BoulderDash.controllers;
import fr.enssat.BoulderDash.models.DisplayableElementModel; import fr.enssat.BoulderDash.models.DisplayableElementModel;
import fr.enssat.BoulderDash.models.LevelModel; 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; import java.awt.event.KeyEvent;
/** /**
* GameKeyController * GameKeyController
* * <p>
* Manages the key events controller. * Manages the key events controller.
* *
* @author Colin Leverger <me@colinleverger.fr> * @author Colin Leverger <me@colinleverger.fr>
* @since 2015-06-19 * @since 2015-06-19
*/ */
public class GameKeyController extends KeyController { public class GameKeyController extends AbstractKeyController {
private RockfordUpdateController updatePosRockford; private RockfordUpdateController updatePosRockford;
/** /**
* Class constructor * Class constructor
* *
* @param levelModel Level model * @param levelModel Level model
*/ */
public GameKeyController(LevelModel levelModel, AudioLoadHelper audioLoadHelper) { public GameKeyController(LevelModel levelModel) {
super(levelModel); super(levelModel);
new BoulderAndDiamondController(levelModel, audioLoadHelper); new BoulderAndDiamondController(levelModel);
this.updatePosRockford = new RockfordUpdateController(levelModel); this.updatePosRockford = new RockfordUpdateController(levelModel);
} }
public void keyPressed(KeyEvent e) { @Override
int keyCode = e.getKeyCode(); protected void up() {
LevelModel levelModel = getLevelModel();
switch (keyCode) {
// Direction: UP
case KeyEvent.VK_UP:
DisplayableElementModel upElement = levelModel.getGroundLevelModel()[levelModel.getRockfordPositionX()][levelModel.getRockfordPositionY() - 1]; DisplayableElementModel upElement = levelModel.getGroundLevelModel()[levelModel.getRockfordPositionX()][levelModel.getRockfordPositionY() - 1];
if (upElement.getPriority() < levelModel.getRockford().getPriority()) { if (upElement.getPriority() < levelModel.getRockford().getPriority()) {
this.updatePosRockford.moveRockford(levelModel.getRockfordPositionX(), levelModel.getRockfordPositionY() - 1); this.updatePosRockford.moveRockford(levelModel.getRockfordPositionX(), levelModel.getRockfordPositionY() - 1);
levelModel.getRockford().startRunningUp(); this.levelModel.getRockford().startRunningUp();
}
} }
break; @Override
protected void down() {
// Direction: DOWN
case KeyEvent.VK_DOWN:
DisplayableElementModel downElement = levelModel.getGroundLevelModel()[levelModel.getRockfordPositionX()][levelModel.getRockfordPositionY() + 1]; DisplayableElementModel downElement = levelModel.getGroundLevelModel()[levelModel.getRockfordPositionX()][levelModel.getRockfordPositionY() + 1];
if (downElement.getPriority() < levelModel.getRockford().getPriority()) { if (downElement.getPriority() < levelModel.getRockford().getPriority()) {
this.updatePosRockford.moveRockford(levelModel.getRockfordPositionX(), levelModel.getRockfordPositionY() + 1); this.updatePosRockford.moveRockford(levelModel.getRockfordPositionX(), levelModel.getRockfordPositionY() + 1);
levelModel.getRockford().startRunningDown(); this.levelModel.getRockford().startRunningDown();
}
} }
break; @Override
protected void left() {
// Direction: LEFT
case KeyEvent.VK_LEFT:
DisplayableElementModel leftElement = levelModel.getGroundLevelModel()[levelModel.getRockfordPositionX() - 1][levelModel.getRockfordPositionY()]; DisplayableElementModel leftElement = levelModel.getGroundLevelModel()[levelModel.getRockfordPositionX() - 1][levelModel.getRockfordPositionY()];
if (leftElement.getPriority() < levelModel.getRockford().getPriority()) { if (leftElement.getPriority() < levelModel.getRockford().getPriority()) {
this.updatePosRockford.moveRockford(levelModel.getRockfordPositionX() - 1, levelModel.getRockfordPositionY()); this.updatePosRockford.moveRockford(levelModel.getRockfordPositionX() - 1, levelModel.getRockfordPositionY());
levelModel.getRockford().startRunningLeft(); this.levelModel.getRockford().startRunningLeft();
}
} }
break; @Override
protected void right() {
// Direction: RIGHT
case KeyEvent.VK_RIGHT:
DisplayableElementModel rightElement = levelModel.getGroundLevelModel()[levelModel.getRockfordPositionX() + 1][levelModel.getRockfordPositionY()]; DisplayableElementModel rightElement = levelModel.getGroundLevelModel()[levelModel.getRockfordPositionX() + 1][levelModel.getRockfordPositionY()];
if (rightElement.getPriority() < levelModel.getRockford().getPriority()) { if (rightElement.getPriority() < levelModel.getRockford().getPriority()) {
this.updatePosRockford.moveRockford(levelModel.getRockfordPositionX() + 1, levelModel.getRockfordPositionY()); this.updatePosRockford.moveRockford(levelModel.getRockfordPositionX() + 1, levelModel.getRockfordPositionY());
levelModel.getRockford().startRunningRight(); this.levelModel.getRockford().startRunningRight();
}
break;
} }
} }
/**
* Handles the 'key released' event
*
* @param e Key event
*/
@Override @Override
public void keyReleased(KeyEvent e) { public void keyReleased(KeyEvent e) {
getLevelModel().getRockford().startStaying(); this.levelModel.getRockford().startStaying();
}
@Override
public void keyTyped(KeyEvent e) {
// Do nothing.
} }
} }

View File

@ -8,36 +8,37 @@ import fr.enssat.BoulderDash.helpers.LevelSaveHelper;
import fr.enssat.BoulderDash.models.LevelModel; import fr.enssat.BoulderDash.models.LevelModel;
import fr.enssat.BoulderDash.views.HelpView; import fr.enssat.BoulderDash.views.HelpView;
import fr.enssat.BoulderDash.views.LevelEditorView; import fr.enssat.BoulderDash.views.LevelEditorView;
import fr.enssat.BoulderDash.controllers.NavigationBetweenViewController;
import javax.swing.*; import javax.swing.*;
import static fr.enssat.BoulderDash.helpers.AudioLoadHelper.AUDIO_LOAD_HELPER;
/** /**
* LevelEditorController * LevelEditorController
* * <p>
* Manages the level editor controller. * Manages the level editor controller.
* *
* @author Valerian Saliou <valerian@valeriansaliou.name> * @author Valerian Saliou <valerian@valeriansaliou.name>
* @since 2015-06-19 * @since 2015-06-19
*/ */
public class LevelEditorController extends GameModuleController { public class LevelEditorController extends AbstractNavController {
private LevelEditorView levelEditorView; private LevelEditorView levelEditorView;
/** /**
* Class constructor' * Class constructor
* *
* @param levelModel Level model * @param levelModel Level model
*/ */
public LevelEditorController(LevelModel levelModel, NavigationBetweenViewController nav) { public LevelEditorController(LevelModel levelModel, NavigationBetweenViewController nav) {
super(levelModel, nav); super(levelModel, nav);
levelModel.setShowCursor(true); this.levelModel.setShowCursor(true);
nav.getAudioLoadHelper().stopMusic(); AUDIO_LOAD_HELPER.stopMusic();
this.levelEditorView = new LevelEditorView(this, levelModel, nav); this.levelEditorView = new LevelEditorView(this, levelModel, nav);
// Pre-bind event watcher (hack to fix a Java issue) // Pre-bind event watcher (hack to fix a Java issue)
levelModel.decrementCursorXPosition(); this.levelModel.decrementCursorXPosition();
} }
/** /**
@ -45,21 +46,19 @@ public class LevelEditorController extends GameModuleController {
* *
* @param event Action event * @param event Action event
*/ */
@Override
public void actionPerformed(ActionEvent event) { public void actionPerformed(ActionEvent event) {
switch (event.getActionCommand()) { switch (event.getActionCommand()) {
case "menu": case "menu":
this.levelEditorView.setVisible(false); this.levelEditorView.setVisible(false);
super.menuActionPerformed(); this.nav.setMenuView();
AUDIO_LOAD_HELPER.startMusic("game");
break; break;
case "save": case "save":
LevelModel levelModel = getLevelModel();
// Check constraints // Check constraints
try { try {
levelModel.checkConstraints(); this.levelModel.checkConstraints();
// Save action (direct save) // Save action (direct save)
String levelId = this.levelEditorView.getSelectedLevel(); String levelId = this.levelEditorView.getSelectedLevel();
@ -119,14 +118,17 @@ public class LevelEditorController extends GameModuleController {
return levelEditorView; return levelEditorView;
} }
/** // dead code
* Sets the level editor view //
* //public LevelModel getLevelModel() {
* @param levelEditorView Level editor view // return this.levelModel;
*/ //}
public void setLevelEditorView(LevelEditorView levelEditorView) {
this.levelEditorView = levelEditorView; // dead code
} //
//public void setLevelEditorView(LevelEditorView levelEditorView) {
// this.levelEditorView = levelEditorView;
//}
} }

View File

@ -3,18 +3,16 @@ package fr.enssat.BoulderDash.controllers;
import fr.enssat.BoulderDash.models.LevelModel; import fr.enssat.BoulderDash.models.LevelModel;
import fr.enssat.BoulderDash.views.LevelEditorView; import fr.enssat.BoulderDash.views.LevelEditorView;
import java.awt.event.KeyEvent;
/** /**
* LevelEditorKeyController * LevelEditorKeyController
* * <p>
* Manages the key events controller. * Manages the key events controller.
* *
* @author Valerian Saliou <valerian@valeriansaliou.name> * @author Valerian Saliou <valerian@valeriansaliou.name>
* @since 2015-06-21 * @since 2015-06-21
*/ */
public class LevelEditorKeyController extends KeyController { public class LevelEditorKeyController extends AbstractKeyController {
private LevelEditorView levelEditorView; private LevelEditorView levelEditorView;
private boolean capLocks; private boolean capLocks;
@ -31,54 +29,41 @@ public class LevelEditorKeyController extends KeyController {
} }
@Override @Override
public void keyPressed(KeyEvent e) { protected void additionalSteps() {
int keyCode = e.getKeyCode();
LevelModel levelModel = getLevelModel();
switch (keyCode) {
// Direction: UP
case KeyEvent.VK_UP:
levelModel.decrementCursorYPosition();
break;
// Direction: DOWN
case KeyEvent.VK_DOWN:
levelModel.incrementCursorYPosition();
break;
// Direction: LEFT
case KeyEvent.VK_LEFT:
levelModel.decrementCursorXPosition();
break;
// Direction: RIGHT
case KeyEvent.VK_RIGHT:
levelModel.incrementCursorXPosition();
break;
// Key: SPACE
case KeyEvent.VK_SPACE:
levelModel.triggerBlockChange(this.levelEditorView.getPickedBlockValue());
break;
case 16:
this.capLocks = !capLocks;
break;
}
// Hold block change (quick edit) // Hold block change (quick edit)
if (capLocks) { if (capLocks) {
levelModel.triggerBlockChange(this.levelEditorView.getPickedBlockValue()); this.levelModel.triggerBlockChange(this.levelEditorView.getPickedBlockValue());
} }
} }
@Override @Override
public void keyReleased(KeyEvent e) { protected void up() {
// Do nothing. this.levelModel.decrementCursorYPosition();
return;
} }
@Override @Override
public void keyTyped(KeyEvent e) { protected void down() {
// Do nothing. 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;
} }
} }

View File

@ -3,23 +3,19 @@ package fr.enssat.BoulderDash.controllers;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import fr.enssat.BoulderDash.helpers.AudioLoadHelper;
import fr.enssat.BoulderDash.models.LevelModel; import fr.enssat.BoulderDash.models.LevelModel;
import fr.enssat.BoulderDash.views.MenuView; 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 * Controller to navigate between the different views
* *
* @author Colin Leverger <me@colinleverger.fr> * @author Colin Leverger <me@colinleverger.fr>
*
*/ */
public class NavigationBetweenViewController implements ActionListener { public class NavigationBetweenViewController implements ActionListener {
private LevelEditorController levelEditorController; private LevelEditorController levelEditorController;
private MenuView menuView; private MenuView menuView;
private AudioLoadHelper audioLoadHelper;
private LevelModel levelModelForGame, levelModelForEditor;
private GameController gameController; private GameController gameController;
private String pickedLevelIdentifier; private String pickedLevelIdentifier;
@ -27,10 +23,8 @@ public class NavigationBetweenViewController implements ActionListener {
* Class constructor * Class constructor
*/ */
public NavigationBetweenViewController() { public NavigationBetweenViewController() {
this.audioLoadHelper = new AudioLoadHelper();
// Play game music // Play game music
this.getAudioLoadHelper().startMusic("game"); AUDIO_LOAD_HELPER.startMusic("game");
// Creation of the first view // Creation of the first view
this.menuView = new MenuView(this); this.menuView = new MenuView(this);
@ -50,8 +44,8 @@ public class NavigationBetweenViewController implements ActionListener {
case "editor": case "editor":
// New blank model for editor // New blank model for editor
this.levelModelForEditor = new LevelModel(audioLoadHelper); LevelModel levelModelForEditor = new LevelModel();
this.levelEditorController = new LevelEditorController(this.levelModelForEditor, this); this.levelEditorController = new LevelEditorController(levelModelForEditor, this);
this.levelEditorController.getLevelEditorView().setVisible(true); this.levelEditorController.getLevelEditorView().setVisible(true);
this.levelEditorController.getLevelEditorView().getLevelEditorGroundView().grabFocus(); this.levelEditorController.getLevelEditorView().getLevelEditorGroundView().grabFocus();
@ -66,8 +60,8 @@ public class NavigationBetweenViewController implements ActionListener {
// Reinit the levelModelForGame... // Reinit the levelModelForGame...
pickedLevelIdentifier = this.menuView.getLevelIdentifier(); pickedLevelIdentifier = this.menuView.getLevelIdentifier();
this.levelModelForGame = new LevelModel(pickedLevelIdentifier, audioLoadHelper); LevelModel levelModelForGame = new LevelModel(pickedLevelIdentifier);
this.gameController = new GameController(levelModelForGame, audioLoadHelper, this); this.gameController = new GameController(levelModelForGame, this);
if (levelEditorController != null) { if (levelEditorController != null) {
this.levelEditorController.getLevelEditorView().setVisible(false); this.levelEditorController.getLevelEditorView().setVisible(false);
@ -82,15 +76,6 @@ public class NavigationBetweenViewController implements ActionListener {
this.menuView.setVisible(false); this.menuView.setVisible(false);
} }
/**
* Get the audio load helper
*
* @return Audio load helper
*/
public AudioLoadHelper getAudioLoadHelper() {
return this.audioLoadHelper;
}
/** /**
* Get the first view * Get the first view
* *
@ -102,8 +87,6 @@ public class NavigationBetweenViewController implements ActionListener {
/** /**
* Set the first view * Set the first view
*
* @param menuView
*/ */
public MenuView setMenuView() { public MenuView setMenuView() {
this.menuView = new MenuView(this); this.menuView = new MenuView(this);
@ -119,14 +102,11 @@ public class NavigationBetweenViewController implements ActionListener {
return pickedLevelIdentifier; return pickedLevelIdentifier;
} }
/** // dead code
* Set the pickedLevelIdentifier //
* //public void setPickedLevelIdentifier(String pickedLevelIdentifier) {
* @param pickedLevelIdentifier Picked level identifier // this.pickedLevelIdentifier = pickedLevelIdentifier;
*/ //}
public void setPickedLevelIdentifier(String pickedLevelIdentifier) {
this.pickedLevelIdentifier = pickedLevelIdentifier;
}
} }

View File

@ -4,7 +4,7 @@ import fr.enssat.BoulderDash.models.LevelModel;
/** /**
* ElementPositionUpdateHelper * ElementPositionUpdateHelper
* * <p>
* Updates position of all elements displayed on the map, according to their * 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 * 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. * their power to destroy in the food chain. Sorry for that Darwinism.
@ -12,8 +12,7 @@ import fr.enssat.BoulderDash.models.LevelModel;
* @author Colin Leverger <me@colinleverger.fr> * @author Colin Leverger <me@colinleverger.fr>
* @since 2015-06-19 * @since 2015-06-19
*/ */
public class RockfordUpdateController implements Runnable { public class RockfordUpdateController extends AbstractLevelController implements Runnable {
private LevelModel levelModel;
private Thread elementMovingThread; private Thread elementMovingThread;
private int rockfordPositionX; private int rockfordPositionX;
private int rockfordPositionY; private int rockfordPositionY;
@ -25,7 +24,7 @@ public class RockfordUpdateController implements Runnable {
* @param levelModel Level model * @param levelModel Level model
*/ */
public RockfordUpdateController(LevelModel levelModel) { public RockfordUpdateController(LevelModel levelModel) {
this.levelModel = levelModel; super(levelModel);
this.elementMovingThread = new Thread(this); this.elementMovingThread = new Thread(this);
this.elementMovingThread.start(); this.elementMovingThread.start();
this.rockfordHasMoved = false; this.rockfordHasMoved = false;

View File

@ -8,14 +8,18 @@ import java.util.HashMap;
/** /**
* AudioLoadHelper * AudioLoadHelper
* * <p>
* Manages audio * Manages audio
* *
* @author Valerian Saliou <valerian@valeriansaliou.name> * @author Valerian Saliou <valerian@valeriansaliou.name>
* @since 2015-06-19 * @since 2015-06-19
*/ */
public class AudioLoadHelper { 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 SoundJLayerBridge musicToPlay;
private HashMap<String, SoundJLayerBridge> preloadedSounds; private HashMap<String, SoundJLayerBridge> preloadedSounds;

View File

@ -3,26 +3,17 @@ package fr.enssat.BoulderDash.models;
import fr.enssat.BoulderDash.exceptions.LevelConstraintNotRespectedException; import fr.enssat.BoulderDash.exceptions.LevelConstraintNotRespectedException;
import fr.enssat.BoulderDash.exceptions.UnknownModelException; import fr.enssat.BoulderDash.exceptions.UnknownModelException;
import fr.enssat.BoulderDash.helpers.LevelLoadHelper; import fr.enssat.BoulderDash.helpers.LevelLoadHelper;
import fr.enssat.BoulderDash.helpers.AudioLoadHelper;
import fr.enssat.BoulderDash.helpers.ModelConvertHelper; 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.awt.image.BufferedImage;
import java.util.Observable; import java.util.Observable;
import static fr.enssat.BoulderDash.helpers.AudioLoadHelper.AUDIO_LOAD_HELPER;
/** /**
* LevelModel * LevelModel
* * <p>
* Levels are loaded from XML file. The view knows the model, the controller is * 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 * going to modify the model in function of the game panel. The model notifies
* the view when there are changes on it. * the view when there are changes on it.
@ -33,7 +24,6 @@ import java.util.Observable;
public class LevelModel extends Observable implements Runnable { public class LevelModel extends Observable implements Runnable {
private DisplayableElementModel[][] groundGrid; private DisplayableElementModel[][] groundGrid;
private String levelName; private String levelName;
private AudioLoadHelper audioLoadHelper;
private int sizeWidth = 0; private int sizeWidth = 0;
private int sizeHeight = 0; private int sizeHeight = 0;
private int cursorXPosition = 0; private int cursorXPosition = 0;
@ -63,12 +53,10 @@ public class LevelModel extends Observable implements Runnable {
* Class constructor * Class constructor
* *
* @param levelName Level name * @param levelName Level name
* @param audioLoadHelper Audio load helper
* @param mode Instance mode * @param mode Instance mode
*/ */
public LevelModel(String levelName, AudioLoadHelper audioLoadHelper, String mode) { public LevelModel(String levelName, String mode) {
this.levelName = levelName; this.levelName = levelName;
this.audioLoadHelper = audioLoadHelper;
this.gamePaused = false; this.gamePaused = false;
this.gameRunning = true; this.gameRunning = true;
this.mode = mode; this.mode = mode;
@ -94,19 +82,15 @@ public class LevelModel extends Observable implements Runnable {
* Class constructor * Class constructor
* *
* @param levelName Level name * @param levelName Level name
* @param audioLoadHelper Audio load helper
*/ */
public LevelModel(String levelName, AudioLoadHelper audioLoadHelper) { public LevelModel(String levelName) {
this(levelName, audioLoadHelper, "game"); this(levelName, "game");
} }
/** /**
* Class constructor (editor mode) * Class constructor (editor mode)
*
* @param audioLoadHelper Audio load helper
*/ */
public LevelModel(AudioLoadHelper audioLoadHelper) { public LevelModel() {
this.audioLoadHelper = audioLoadHelper;
this.gameRunning = false; this.gameRunning = false;
this.mode = "editor"; this.mode = "editor";
@ -209,7 +193,7 @@ public class LevelModel extends Observable implements Runnable {
} }
if (collisionSound != null) { if (collisionSound != null) {
this.audioLoadHelper.playSound(collisionSound); AUDIO_LOAD_HELPER.playSound(collisionSound);
} }
} }

View File

@ -31,7 +31,7 @@ public class GameGroundView extends GroundView {
this.gameController = gameController; 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.setBorder(BorderFactory.createLineBorder(Color.black));
this.setFocusable(true); this.setFocusable(true);

View File

@ -169,10 +169,10 @@ public class LevelEditorView extends JFrame implements Observer {
if(selectedLevelValue != null && !selectedLevelValue.isEmpty()) { if(selectedLevelValue != null && !selectedLevelValue.isEmpty()) {
// Load existing model // Load existing model
pickedLevelModel = new LevelModel(selectedLevelValue, this.nav.getAudioLoadHelper(), "editor"); pickedLevelModel = new LevelModel(selectedLevelValue, "editor");
} else { } else {
// New blank model for editor // New blank model for editor
pickedLevelModel = new LevelModel(this.nav.getAudioLoadHelper()); pickedLevelModel = new LevelModel();
} }
pickedLevelModel.setShowCursor(true); pickedLevelModel.setShowCursor(true);