Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
1842d8ecc0 | |||
8c05ed2a67 | |||
ce055e4377 | |||
![]() |
2cd827bdab | ||
![]() |
12d4bb3c4d |
BIN
SQ - Exercises.pdf
Normal file
BIN
SQ - Exercises.pdf
Normal file
Binary file not shown.
@ -0,0 +1,6 @@
|
|||||||
|
package fr.enssat.BoulderDash.bridges;
|
||||||
|
|
||||||
|
public interface SoundBridge {
|
||||||
|
void play();
|
||||||
|
void stop();
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
package fr.enssat.BoulderDash.bridges;
|
||||||
|
|
||||||
|
public abstract class SoundBridgeFactory {
|
||||||
|
public abstract SoundBridge createSoundBridgeFromFilePath(String filePath);
|
||||||
|
}
|
@ -14,7 +14,7 @@ import javazoom.jl.player.FactoryRegistry;
|
|||||||
* @author Valerian Saliou <valerian@valeriansaliou.name>
|
* @author Valerian Saliou <valerian@valeriansaliou.name>
|
||||||
* @since 2015-06-19
|
* @since 2015-06-19
|
||||||
*/
|
*/
|
||||||
public class SoundJLayerBridge extends PlaybackListener implements Runnable {
|
public class SoundJLayerBridge extends PlaybackListener implements Runnable, SoundBridge {
|
||||||
private String filePath;
|
private String filePath;
|
||||||
private AdvancedPlayer player;
|
private AdvancedPlayer player;
|
||||||
private Thread playerThread;
|
private Thread playerThread;
|
||||||
@ -31,6 +31,7 @@ public class SoundJLayerBridge extends PlaybackListener implements Runnable {
|
|||||||
/**
|
/**
|
||||||
* Play the target sound
|
* Play the target sound
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public void play() {
|
public void play() {
|
||||||
try {
|
try {
|
||||||
String urlAsString = "file:///"
|
String urlAsString = "file:///"
|
||||||
@ -55,6 +56,7 @@ public class SoundJLayerBridge extends PlaybackListener implements Runnable {
|
|||||||
/**
|
/**
|
||||||
* Stops the target sound
|
* Stops the target sound
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public void stop() {
|
public void stop() {
|
||||||
try {
|
try {
|
||||||
this.playerThread.stop();
|
this.playerThread.stop();
|
||||||
@ -66,6 +68,7 @@ public class SoundJLayerBridge extends PlaybackListener implements Runnable {
|
|||||||
/**
|
/**
|
||||||
* Runs the player thread
|
* Runs the player thread
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
this.player.play();
|
this.player.play();
|
||||||
|
@ -0,0 +1,10 @@
|
|||||||
|
package fr.enssat.BoulderDash.bridges;
|
||||||
|
|
||||||
|
public class SoundJLayerBridgeFactory extends SoundBridgeFactory {
|
||||||
|
public SoundJLayerBridgeFactory() {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SoundBridge createSoundBridgeFromFilePath(String filePath) {
|
||||||
|
return new SoundJLayerBridge(filePath);
|
||||||
|
}
|
||||||
|
}
|
@ -2,7 +2,7 @@ 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.helpers.AudioLoadHelper;
|
||||||
import fr.enssat.BoulderDash.controllers.NavigationBetweenViewController;
|
import fr.enssat.BoulderDash.models.LevelModelFactory;
|
||||||
import fr.enssat.BoulderDash.views.MenuView;
|
import fr.enssat.BoulderDash.views.MenuView;
|
||||||
import fr.enssat.BoulderDash.views.GameView;
|
import fr.enssat.BoulderDash.views.GameView;
|
||||||
|
|
||||||
@ -86,7 +86,7 @@ public class GameController implements ActionListener {
|
|||||||
this.gameView.dispose();
|
this.gameView.dispose();
|
||||||
|
|
||||||
if(source.equals("restart")){
|
if(source.equals("restart")){
|
||||||
this.levelModel = new LevelModel(this.navigationBetweenViewController.getPickedLevelIdentifier(), audioLoadHelper);
|
this.levelModel = LevelModelFactory.createLevelModel(this.navigationBetweenViewController.getPickedLevelIdentifier(), audioLoadHelper);
|
||||||
this.gameView = new GameView(this, levelModel);
|
this.gameView = new GameView(this, levelModel);
|
||||||
this.gameView.setVisible(true);
|
this.gameView.setVisible(true);
|
||||||
}
|
}
|
||||||
|
@ -3,11 +3,11 @@ 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.bridges.SoundJLayerBridgeFactory;
|
||||||
import fr.enssat.BoulderDash.helpers.AudioLoadHelper;
|
import fr.enssat.BoulderDash.helpers.AudioLoadHelper;
|
||||||
import fr.enssat.BoulderDash.models.LevelModel;
|
import fr.enssat.BoulderDash.models.LevelModel;
|
||||||
|
import fr.enssat.BoulderDash.models.LevelModelFactory;
|
||||||
import fr.enssat.BoulderDash.views.MenuView;
|
import fr.enssat.BoulderDash.views.MenuView;
|
||||||
import fr.enssat.BoulderDash.controllers.LevelEditorController;
|
|
||||||
import fr.enssat.BoulderDash.controllers.GameController;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controller to navigate between the different views
|
* Controller to navigate between the different views
|
||||||
@ -27,7 +27,7 @@ public class NavigationBetweenViewController implements ActionListener {
|
|||||||
* Class constructor
|
* Class constructor
|
||||||
*/
|
*/
|
||||||
public NavigationBetweenViewController() {
|
public NavigationBetweenViewController() {
|
||||||
this.audioLoadHelper = new AudioLoadHelper();
|
this.audioLoadHelper = new AudioLoadHelper(new SoundJLayerBridgeFactory());
|
||||||
|
|
||||||
// Play game music
|
// Play game music
|
||||||
this.getAudioLoadHelper().startMusic("game");
|
this.getAudioLoadHelper().startMusic("game");
|
||||||
@ -50,7 +50,7 @@ public class NavigationBetweenViewController implements ActionListener {
|
|||||||
|
|
||||||
case "editor":
|
case "editor":
|
||||||
// New blank model for editor
|
// New blank model for editor
|
||||||
this.levelModelForEditor = new LevelModel(audioLoadHelper);
|
this.levelModelForEditor = LevelModelFactory.createLevelModel(audioLoadHelper);
|
||||||
this.levelEditorController = new LevelEditorController(this.levelModelForEditor, this);
|
this.levelEditorController = new LevelEditorController(this.levelModelForEditor, this);
|
||||||
|
|
||||||
this.levelEditorController.getLevelEditorView().setVisible(true);
|
this.levelEditorController.getLevelEditorView().setVisible(true);
|
||||||
@ -66,7 +66,7 @@ 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);
|
this.levelModelForGame = LevelModelFactory.createLevelModel(pickedLevelIdentifier, audioLoadHelper);
|
||||||
this.gameController = new GameController(levelModelForGame, audioLoadHelper, this);
|
this.gameController = new GameController(levelModelForGame, audioLoadHelper, this);
|
||||||
|
|
||||||
if (levelEditorController != null) {
|
if (levelEditorController != null) {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package fr.enssat.BoulderDash.helpers;
|
package fr.enssat.BoulderDash.helpers;
|
||||||
|
|
||||||
import fr.enssat.BoulderDash.bridges.SoundJLayerBridge;
|
import fr.enssat.BoulderDash.bridges.SoundBridge;
|
||||||
|
import fr.enssat.BoulderDash.bridges.SoundBridgeFactory;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FilenameFilter;
|
import java.io.FilenameFilter;
|
||||||
@ -17,13 +18,15 @@ import java.util.HashMap;
|
|||||||
public class AudioLoadHelper {
|
public class AudioLoadHelper {
|
||||||
private static String pathToAudioStore = "./res/audio";
|
private static String pathToAudioStore = "./res/audio";
|
||||||
|
|
||||||
private SoundJLayerBridge musicToPlay;
|
private final SoundBridgeFactory soundBridgeFactory;
|
||||||
private HashMap<String, SoundJLayerBridge> preloadedSounds;
|
private SoundBridge musicToPlay;
|
||||||
|
private HashMap<String, SoundBridge> preloadedSounds;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor
|
* Class constructor
|
||||||
*/
|
*/
|
||||||
public AudioLoadHelper() {
|
public AudioLoadHelper(SoundBridgeFactory soundBridgeFactory) {
|
||||||
|
this.soundBridgeFactory = soundBridgeFactory;
|
||||||
this.preloadSounds();
|
this.preloadSounds();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,9 +50,8 @@ public class AudioLoadHelper {
|
|||||||
this.stopMusic();
|
this.stopMusic();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.musicToPlay = new SoundJLayerBridge(
|
String filePath = this.getMusicPathInAudioStore(musicId);
|
||||||
this.getMusicPathInAudioStore(musicId)
|
this.musicToPlay = soundBridgeFactory.createSoundBridgeFromFilePath(filePath);
|
||||||
);
|
|
||||||
this.musicToPlay.play();
|
this.musicToPlay.play();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,7 +68,7 @@ public class AudioLoadHelper {
|
|||||||
private void preloadSounds() {
|
private void preloadSounds() {
|
||||||
// Initialize
|
// Initialize
|
||||||
String curSoundIdPrep;
|
String curSoundIdPrep;
|
||||||
this.preloadedSounds = new HashMap<String, SoundJLayerBridge>();
|
this.preloadedSounds = new HashMap<>();
|
||||||
|
|
||||||
// List sound files
|
// List sound files
|
||||||
File soundsDir = new File(AudioLoadHelper.pathToAudioStore + "/sounds/");
|
File soundsDir = new File(AudioLoadHelper.pathToAudioStore + "/sounds/");
|
||||||
@ -77,14 +79,13 @@ public class AudioLoadHelper {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Cache them all!
|
// Cache them all!^
|
||||||
for (File curSoundId : soundFiles) {
|
for (File curSoundId : soundFiles) {
|
||||||
curSoundIdPrep = curSoundId.getName();
|
curSoundIdPrep = curSoundId.getName();
|
||||||
curSoundIdPrep = curSoundIdPrep.substring(0, curSoundIdPrep.lastIndexOf('.'));
|
curSoundIdPrep = curSoundIdPrep.substring(0, curSoundIdPrep.lastIndexOf('.'));
|
||||||
|
|
||||||
this.preloadedSounds.put(curSoundIdPrep, new SoundJLayerBridge(
|
this.preloadedSounds.put(curSoundIdPrep,
|
||||||
curSoundId.getPath()
|
soundBridgeFactory.createSoundBridgeFromFilePath(curSoundId.getPath()));
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,7 +95,7 @@ public class AudioLoadHelper {
|
|||||||
* @param soundId Sound identifier
|
* @param soundId Sound identifier
|
||||||
* @return Preloaded sound instance
|
* @return Preloaded sound instance
|
||||||
*/
|
*/
|
||||||
private SoundJLayerBridge getPreloadedSound(String soundId) {
|
private SoundBridge getPreloadedSound(String soundId) {
|
||||||
return this.preloadedSounds.get(soundId);
|
return this.preloadedSounds.get(soundId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,19 +2,8 @@ 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.AudioLoadHelper;
|
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;
|
||||||
@ -32,7 +21,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 AudioLoadHelper audioLoadHelper;
|
private AudioLoadHelper audioLoadHelper;
|
||||||
private int sizeWidth = 0;
|
private int sizeWidth = 0;
|
||||||
private int sizeHeight = 0;
|
private int sizeHeight = 0;
|
||||||
@ -40,7 +28,6 @@ public class LevelModel extends Observable implements Runnable {
|
|||||||
private int cursorYPosition = 0;
|
private int cursorYPosition = 0;
|
||||||
private boolean showCursor = false;
|
private boolean showCursor = false;
|
||||||
private CursorModel cursorModel;
|
private CursorModel cursorModel;
|
||||||
private LevelLoadHelper levelLoadHelper;
|
|
||||||
private RockfordModel rockford;
|
private RockfordModel rockford;
|
||||||
private GameInformationModel gameInformationModel;
|
private GameInformationModel gameInformationModel;
|
||||||
private int rockfordPositionX, rockfordPositionY;
|
private int rockfordPositionX, rockfordPositionY;
|
||||||
@ -49,120 +36,34 @@ public class LevelModel extends Observable implements Runnable {
|
|||||||
// Are we in editor or game mode ?
|
// Are we in editor or game mode ?
|
||||||
private String mode;
|
private String mode;
|
||||||
|
|
||||||
/**
|
|
||||||
* Sprite animation thread
|
|
||||||
*/
|
|
||||||
private Thread spriteAnimator;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Animation speed
|
* Animation speed
|
||||||
*/
|
*/
|
||||||
private final int DELAY = 25;
|
private final int DELAY = 25;
|
||||||
|
|
||||||
/**
|
LevelModel(AudioLoadHelper audioLoadHelper,
|
||||||
* Class constructor
|
String mode,
|
||||||
*
|
boolean gameRunning,
|
||||||
* @param levelName Level name
|
CursorModel cursorModel,
|
||||||
* @param audioLoadHelper Audio load helper
|
GameInformationModel gameInformationModel,
|
||||||
* @param mode Instance mode
|
DisplayableElementModel[][] groundGrid,
|
||||||
*/
|
int sizeWidth,
|
||||||
public LevelModel(String levelName, AudioLoadHelper audioLoadHelper, String mode) {
|
int sizeHeight,
|
||||||
this.levelName = levelName;
|
int rockfordPositionX,
|
||||||
|
int rockfordPositionY,
|
||||||
|
RockfordModel rockford){
|
||||||
this.audioLoadHelper = audioLoadHelper;
|
this.audioLoadHelper = audioLoadHelper;
|
||||||
this.gamePaused = false;
|
this.gamePaused = false;
|
||||||
this.gameRunning = true;
|
this.gameRunning = gameRunning;
|
||||||
this.mode = mode;
|
this.mode = mode;
|
||||||
|
this.groundGrid = groundGrid;
|
||||||
this.levelLoadHelper = new LevelLoadHelper(this.levelName);
|
this.sizeWidth = sizeWidth;
|
||||||
|
this.sizeHeight = sizeHeight;
|
||||||
this.groundGrid = this.levelLoadHelper.getGroundGrid();
|
this.cursorModel = cursorModel;
|
||||||
this.sizeWidth = this.levelLoadHelper.getWidthSizeValue();
|
this.gameInformationModel = gameInformationModel;
|
||||||
this.sizeHeight = this.levelLoadHelper.getHeightSizeValue();
|
this.rockfordPositionX = rockfordPositionX;
|
||||||
|
this.rockfordPositionY = rockfordPositionY;
|
||||||
this.cursorModel = new CursorModel();
|
this.rockford = rockford;
|
||||||
this.gameInformationModel = new GameInformationModel(this.levelLoadHelper.getDiamondsToCatch());
|
|
||||||
|
|
||||||
this.createLimits();
|
|
||||||
|
|
||||||
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 (editor mode)
|
|
||||||
*
|
|
||||||
* @param audioLoadHelper Audio load helper
|
|
||||||
*/
|
|
||||||
public LevelModel(AudioLoadHelper audioLoadHelper) {
|
|
||||||
this.audioLoadHelper = audioLoadHelper;
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.createLimits();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initializes the animator thread
|
|
||||||
*/
|
|
||||||
private void initThreadAnimator() {
|
|
||||||
this.spriteAnimator = new Thread(this);
|
|
||||||
this.spriteAnimator.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initializes the Rockford position attributes
|
|
||||||
*/
|
|
||||||
private void initRockford() {
|
|
||||||
this.rockfordPositionX = this.levelLoadHelper.getRockfordPositionX();
|
|
||||||
this.rockfordPositionY = this.levelLoadHelper.getRockfordPositionY();
|
|
||||||
this.rockford = this.levelLoadHelper.getRockfordInstance();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -183,12 +84,8 @@ public class LevelModel extends Observable implements Runnable {
|
|||||||
* @param posY Vertical position
|
* @param posY Vertical position
|
||||||
*/
|
*/
|
||||||
private boolean isOutOfBounds(int posX, int posY) {
|
private boolean isOutOfBounds(int posX, int posY) {
|
||||||
if (posX > 0 && posY > 0 && posX < this.getLevelLoadHelper().getHeightSizeValue() && posY < this.getLevelLoadHelper().getWidthSizeValue()) {
|
return posX <= 0 || posY <= 0 || posX >= this.sizeHeight || posY >= this.sizeWidth;
|
||||||
return false;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Plays collision sound
|
* Plays collision sound
|
||||||
@ -509,22 +406,6 @@ public class LevelModel extends Observable implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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
|
* Gets the cursor position X value
|
||||||
*
|
*
|
||||||
@ -825,5 +706,4 @@ public class LevelModel extends Observable implements Runnable {
|
|||||||
public void setMode(String mode) {
|
public void setMode(String mode) {
|
||||||
this.mode = mode;
|
this.mode = mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -0,0 +1,79 @@
|
|||||||
|
package fr.enssat.BoulderDash.models;
|
||||||
|
|
||||||
|
import fr.enssat.BoulderDash.helpers.AudioLoadHelper;
|
||||||
|
import fr.enssat.BoulderDash.helpers.LevelLoadHelper;
|
||||||
|
|
||||||
|
|
||||||
|
public class LevelModelFactory {
|
||||||
|
public static LevelModel createLevelModel(String levelName, AudioLoadHelper audioLoadHelper, String mode) {
|
||||||
|
LevelLoadHelper levelLoadHelper = new LevelLoadHelper(levelName);
|
||||||
|
CursorModel cursorModel = new CursorModel();
|
||||||
|
GameInformationModel gameInformationModel = new GameInformationModel(levelLoadHelper.getDiamondsToCatch());
|
||||||
|
|
||||||
|
int sizeWidth = levelLoadHelper.getWidthSizeValue();
|
||||||
|
int sizeHeight = levelLoadHelper.getHeightSizeValue();
|
||||||
|
DisplayableElementModel[][] groundGrid = levelLoadHelper.getGroundGrid();
|
||||||
|
createLimits(groundGrid, sizeWidth, sizeHeight);
|
||||||
|
|
||||||
|
int rockfordPositionX = 0;
|
||||||
|
int rockfordPositionY = 0;
|
||||||
|
RockfordModel rockford = null;
|
||||||
|
if(mode.equals("game")) {
|
||||||
|
// initRockford
|
||||||
|
rockfordPositionX = levelLoadHelper.getRockfordPositionX();
|
||||||
|
rockfordPositionY = levelLoadHelper.getRockfordPositionY();
|
||||||
|
rockford = levelLoadHelper.getRockfordInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
LevelModel levelModel = new LevelModel(audioLoadHelper, mode, true, cursorModel, gameInformationModel, groundGrid, sizeWidth, sizeHeight,
|
||||||
|
rockfordPositionX, rockfordPositionY, rockford);
|
||||||
|
|
||||||
|
if(mode.equals("game")) {
|
||||||
|
// initThreadAnimator
|
||||||
|
Thread spriteAnimator = new Thread(levelModel);
|
||||||
|
spriteAnimator.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
return levelModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static LevelModel createLevelModel(String levelName, AudioLoadHelper audioLoadHelper) {
|
||||||
|
return createLevelModel(levelName, audioLoadHelper, "game");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static LevelModel createLevelModel(AudioLoadHelper audioLoadHelper) {
|
||||||
|
CursorModel cursorModel = new CursorModel();
|
||||||
|
|
||||||
|
int sizeWidth = 25 + 2;
|
||||||
|
int sizeHeight = 25 + 2;
|
||||||
|
DisplayableElementModel[][] groundGrid = new DisplayableElementModel[sizeWidth][sizeHeight];
|
||||||
|
for (int x = 0; x < sizeWidth; x++) {
|
||||||
|
for (int y = 0; y < sizeHeight; y++) {
|
||||||
|
groundGrid[x][y] = new DirtModel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
createLimits(groundGrid, sizeWidth, sizeHeight);
|
||||||
|
|
||||||
|
|
||||||
|
return new LevelModel(audioLoadHelper, "editor", false, cursorModel, null, groundGrid, sizeWidth, sizeHeight,
|
||||||
|
0, 0, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static void createLimits(DisplayableElementModel[][] groundGrid,
|
||||||
|
int sizeWidth,
|
||||||
|
int sizeHeight) {
|
||||||
|
int maxWidth = sizeWidth - 1;
|
||||||
|
int maxHeight = sizeHeight - 1;
|
||||||
|
|
||||||
|
for (int x = 0; x < sizeWidth; x++) {
|
||||||
|
groundGrid[x][0] = new SteelWallModel();
|
||||||
|
groundGrid[x][maxHeight] = new SteelWallModel();
|
||||||
|
}
|
||||||
|
for (int y = 0; y < sizeHeight; y++) {
|
||||||
|
groundGrid[0][y] = new SteelWallModel();
|
||||||
|
groundGrid[maxWidth][y] = new SteelWallModel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -9,9 +9,7 @@ import fr.enssat.BoulderDash.helpers.LevelSelectorHelper;
|
|||||||
import fr.enssat.BoulderDash.controllers.LevelEditorController;
|
import fr.enssat.BoulderDash.controllers.LevelEditorController;
|
||||||
import fr.enssat.BoulderDash.controllers.NavigationBetweenViewController;
|
import fr.enssat.BoulderDash.controllers.NavigationBetweenViewController;
|
||||||
import fr.enssat.BoulderDash.models.LevelModel;
|
import fr.enssat.BoulderDash.models.LevelModel;
|
||||||
import fr.enssat.BoulderDash.views.LevelEditorGroundView;
|
import fr.enssat.BoulderDash.models.LevelModelFactory;
|
||||||
import fr.enssat.BoulderDash.views.AssetsLevelEditorComponent;
|
|
||||||
import fr.enssat.BoulderDash.views.MenuLevelSelector;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -169,10 +167,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 = LevelModelFactory.createLevelModel(selectedLevelValue, this.nav.getAudioLoadHelper(), "editor");
|
||||||
} else {
|
} else {
|
||||||
// New blank model for editor
|
// New blank model for editor
|
||||||
pickedLevelModel = new LevelModel(this.nav.getAudioLoadHelper());
|
pickedLevelModel = LevelModelFactory.createLevelModel(this.nav.getAudioLoadHelper());
|
||||||
}
|
}
|
||||||
|
|
||||||
pickedLevelModel.setShowCursor(true);
|
pickedLevelModel.setShowCursor(true);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user