reformat code
This commit is contained in:
parent
6e9a53dd72
commit
aa3bdfde55
@ -7,17 +7,17 @@ import javax.swing.*;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Game
|
* Game
|
||||||
*
|
* <p>
|
||||||
* Spawns the game.
|
* Spawns the game.
|
||||||
*
|
*
|
||||||
* @author Valerian Saliou <valerian@valeriansaliou.name>
|
* @author Valerian Saliou <valerian@valeriansaliou.name>
|
||||||
* @since 2015-06-19
|
* @since 2015-06-19
|
||||||
*/
|
*/
|
||||||
public class Game {
|
public class Game {
|
||||||
/**
|
/**
|
||||||
* Class constructor
|
* Class constructor
|
||||||
*
|
*
|
||||||
* @param args Command-line arguments
|
* @param args Command-line arguments
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SwingUtilities.invokeLater(new Runnable() {
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
|
@ -8,11 +8,11 @@ import javazoom.jl.player.FactoryRegistry;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* SoundJLayerBridge
|
* SoundJLayerBridge
|
||||||
*
|
* <p>
|
||||||
* Sound bridge to the JLayer library.
|
* Sound bridge to the JLayer library.
|
||||||
*
|
*
|
||||||
* @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 {
|
||||||
private String filePath;
|
private String filePath;
|
||||||
@ -22,7 +22,7 @@ public class SoundJLayerBridge extends PlaybackListener implements Runnable {
|
|||||||
/**
|
/**
|
||||||
* Class constructor
|
* Class constructor
|
||||||
*
|
*
|
||||||
* @param filePath File path to sound file
|
* @param filePath File path to sound file
|
||||||
*/
|
*/
|
||||||
public SoundJLayerBridge(String filePath) {
|
public SoundJLayerBridge(String filePath) {
|
||||||
this.filePath = filePath;
|
this.filePath = filePath;
|
||||||
@ -34,9 +34,9 @@ public class SoundJLayerBridge extends PlaybackListener implements Runnable {
|
|||||||
public void play() {
|
public void play() {
|
||||||
try {
|
try {
|
||||||
String urlAsString = "file:///"
|
String urlAsString = "file:///"
|
||||||
+ new java.io.File(".").getCanonicalPath()
|
+ new java.io.File(".").getCanonicalPath()
|
||||||
+ "/"
|
+ "/"
|
||||||
+ this.filePath;
|
+ this.filePath;
|
||||||
|
|
||||||
this.player = new AdvancedPlayer(
|
this.player = new AdvancedPlayer(
|
||||||
new URL(urlAsString).openStream(),
|
new URL(urlAsString).openStream(),
|
||||||
|
@ -7,7 +7,7 @@ import fr.enssat.BoulderDash.helpers.AudioLoadHelper;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 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.
|
||||||
@ -16,149 +16,149 @@ import fr.enssat.BoulderDash.helpers.AudioLoadHelper;
|
|||||||
* @since 2015-06-19
|
* @since 2015-06-19
|
||||||
*/
|
*/
|
||||||
public class BoulderAndDiamondController implements Runnable {
|
public class BoulderAndDiamondController implements Runnable {
|
||||||
private LevelModel levelModel;
|
private LevelModel levelModel;
|
||||||
private AudioLoadHelper audioLoadHelper;
|
private AudioLoadHelper audioLoadHelper;
|
||||||
private Thread elementMovingThread;
|
private Thread elementMovingThread;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor
|
* Class constructor
|
||||||
*
|
*
|
||||||
* @param levelModel Level model
|
* @param levelModel Level model
|
||||||
*/
|
*/
|
||||||
public BoulderAndDiamondController(LevelModel levelModel, AudioLoadHelper audioLoadHelper) {
|
public BoulderAndDiamondController(LevelModel levelModel, AudioLoadHelper audioLoadHelper) {
|
||||||
this.levelModel = levelModel;
|
this.levelModel = levelModel;
|
||||||
this.audioLoadHelper = audioLoadHelper;
|
this.audioLoadHelper = audioLoadHelper;
|
||||||
|
|
||||||
// Start thread
|
// Start thread
|
||||||
this.elementMovingThread = new Thread(this);
|
this.elementMovingThread = new Thread(this);
|
||||||
this.elementMovingThread.start();
|
this.elementMovingThread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Watches for elements to be moved
|
* Watches for elements to be moved
|
||||||
*/
|
*/
|
||||||
public void run() {
|
public void run() {
|
||||||
while (this.levelModel.isGameRunning()) {
|
while (this.levelModel.isGameRunning()) {
|
||||||
if(!this.levelModel.getGamePaused()){
|
if (!this.levelModel.getGamePaused()) {
|
||||||
this.manageFallingObject();
|
this.manageFallingObject();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Thread.sleep(250);
|
Thread.sleep(250);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scan the ground to detect the boulders & the diamonds, then make them
|
* Scan the ground to detect the boulders & the diamonds, then make them
|
||||||
* fall if necessary
|
* fall if necessary
|
||||||
* Note: scan of the ground upside down: we want things to fall slowly !
|
* Note: scan of the ground upside down: we want things to fall slowly !
|
||||||
*/
|
*/
|
||||||
private void manageFallingObject() {
|
private void manageFallingObject() {
|
||||||
for (int x = this.levelModel.getSizeWidth() - 1; x >= 0; x--) {
|
for (int x = this.levelModel.getSizeWidth() - 1; x >= 0; x--) {
|
||||||
for (int y = this.levelModel.getSizeHeight() - 1; y >= 0; y--) {
|
for (int y = this.levelModel.getSizeHeight() - 1; y >= 0; y--) {
|
||||||
// Gets the spriteName of actual DisplayableElementModel object scanned
|
// Gets the spriteName of actual DisplayableElementModel object scanned
|
||||||
DisplayableElementModel elementModel = this.levelModel.getGroundLevelModel()[x][y];
|
DisplayableElementModel elementModel = this.levelModel.getGroundLevelModel()[x][y];
|
||||||
|
|
||||||
if(elementModel == null) {
|
if (elementModel == null) {
|
||||||
elementModel = new DirtModel();
|
elementModel = new DirtModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
String spriteName = elementModel.getSpriteName();
|
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
// If it is a boulder or a diamond...
|
||||||
* Expand the wall at left & right
|
if (spriteName == "boulder" || spriteName == "diamond") {
|
||||||
|
this.manageFall(x, y);
|
||||||
|
} else if (spriteName == "expandingwall") {
|
||||||
|
if (this.expandWall(x, y).equals("left")) {
|
||||||
|
x -= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Expand the wall at left & right
|
||||||
*
|
*
|
||||||
* @param x Horizontal position
|
* @param x Horizontal position
|
||||||
* @param y Vertical position
|
* @param y Vertical position
|
||||||
*/
|
*/
|
||||||
private String expandWall(int x, int y) {
|
private String expandWall(int x, int y) {
|
||||||
DisplayableElementModel elementLeft = this.levelModel.getGroundLevelModel()[x - 1][y];
|
DisplayableElementModel elementLeft = this.levelModel.getGroundLevelModel()[x - 1][y];
|
||||||
DisplayableElementModel elementRight = this.levelModel.getGroundLevelModel()[x + 1][y];
|
DisplayableElementModel elementRight = this.levelModel.getGroundLevelModel()[x + 1][y];
|
||||||
String spriteNameLeft = elementLeft.getSpriteName();
|
String spriteNameLeft = elementLeft.getSpriteName();
|
||||||
String spriteNameRight = elementRight.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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
String way = "";
|
||||||
* Manages the fall of elements
|
if (spriteNameLeft == "black") {
|
||||||
*
|
this.levelModel.expandThisWallToLeft(x, y);
|
||||||
* @param x Horizontal position
|
way = "left";
|
||||||
* @param y Vertical position
|
}
|
||||||
*/
|
if (spriteNameRight == "black") {
|
||||||
private void manageFall(int x, int y) {
|
this.levelModel.expandThisWallToRight(x, y);
|
||||||
// Get informed about Rockford surroundings
|
way = "right";
|
||||||
|
}
|
||||||
|
return way;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 elementBelow = this.levelModel.getGroundLevelModel()[x][y + 1];
|
||||||
DisplayableElementModel elementLeft = this.levelModel.getGroundLevelModel()[x - 1][y];
|
DisplayableElementModel elementLeft = this.levelModel.getGroundLevelModel()[x - 1][y];
|
||||||
DisplayableElementModel elementRight = this.levelModel.getGroundLevelModel()[x + 1][y];
|
DisplayableElementModel elementRight = this.levelModel.getGroundLevelModel()[x + 1][y];
|
||||||
|
|
||||||
String spriteNameBelow = elementBelow.getSpriteName();
|
String spriteNameBelow = elementBelow.getSpriteName();
|
||||||
String spriteNameLeft = elementLeft.getSpriteName();
|
String spriteNameLeft = elementLeft.getSpriteName();
|
||||||
String spriteNameRight = elementRight.getSpriteName();
|
String spriteNameRight = elementRight.getSpriteName();
|
||||||
|
|
||||||
// Then, process in case of the surrounding
|
// Then, process in case of the surrounding
|
||||||
if (spriteNameBelow == "black") {
|
if (spriteNameBelow == "black") {
|
||||||
this.levelModel.makeThisDisplayableElementFall(x, y);
|
this.levelModel.makeThisDisplayableElementFall(x, y);
|
||||||
} else if (spriteNameBelow == "boulder") {
|
} else if (spriteNameBelow == "boulder") {
|
||||||
// Boulders have to roll if they hit another boulder
|
// Boulders have to roll if they hit another boulder
|
||||||
if (this.levelModel.getGroundLevelModel()[x - 1][y + 1].getSpriteName() == "black") {
|
if (this.levelModel.getGroundLevelModel()[x - 1][y + 1].getSpriteName() == "black") {
|
||||||
this.levelModel.makeThisBoulderSlideLeft(x, y);
|
this.levelModel.makeThisBoulderSlideLeft(x, y);
|
||||||
} else if (this.levelModel.getGroundLevelModel()[x + 1][y + 1].getSpriteName() == "black") {
|
} else if (this.levelModel.getGroundLevelModel()[x + 1][y + 1].getSpriteName() == "black") {
|
||||||
this.levelModel.makeThisBoulderSlideRight(x, y);
|
this.levelModel.makeThisBoulderSlideRight(x, y);
|
||||||
}
|
}
|
||||||
} 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");
|
this.audioLoadHelper.playSound("die");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Thread.sleep(25);
|
Thread.sleep(25);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.levelModel.setGameRunning(false);
|
this.levelModel.setGameRunning(false);
|
||||||
} else if (spriteNameBelow == "magicwall") {
|
} else if (spriteNameBelow == "magicwall") {
|
||||||
if (this.levelModel.getGroundLevelModel()[x][y].getSpriteName() == "boulder"
|
if (this.levelModel.getGroundLevelModel()[x][y].getSpriteName() == "boulder"
|
||||||
&& (this.levelModel.getGroundLevelModel()[x][y+2].getSpriteName() == "dirt" ||
|
&& (this.levelModel.getGroundLevelModel()[x][y + 2].getSpriteName() == "dirt" ||
|
||||||
this.levelModel.getGroundLevelModel()[x][y+2].getSpriteName() == "black")) {
|
this.levelModel.getGroundLevelModel()[x][y + 2].getSpriteName() == "black")) {
|
||||||
if(this.levelModel.getGroundLevelModel()[x][y].isConvertible()) {
|
if (this.levelModel.getGroundLevelModel()[x][y].isConvertible()) {
|
||||||
this.levelModel.transformThisBoulderIntoADiamond(x, y);
|
this.levelModel.transformThisBoulderIntoADiamond(x, y);
|
||||||
} else {
|
} else {
|
||||||
this.levelModel.deleteThisBoulder(x, y);
|
this.levelModel.deleteThisBoulder(x, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (elementBelow.isDestructible() && spriteNameBelow != "dirt" && this.levelModel.getGroundLevelModel()[x][y].isFalling()) {
|
} else if (elementBelow.isDestructible() && spriteNameBelow != "dirt" && this.levelModel.getGroundLevelModel()[x][y].isFalling()) {
|
||||||
this.levelModel.exploseThisBrickWall(x, y);
|
this.levelModel.exploseThisBrickWall(x, y);
|
||||||
} else if (spriteNameLeft == "rockford" && this.levelModel.getRockford().isRunningRight() && this.levelModel.getGroundLevelModel()[x + 1][y].getSpriteName() == "black") {
|
} else if (spriteNameLeft == "rockford" && this.levelModel.getRockford().isRunningRight() && this.levelModel.getGroundLevelModel()[x + 1][y].getSpriteName() == "black") {
|
||||||
this.levelModel.moveThisBoulderToRight(x, y);
|
this.levelModel.moveThisBoulderToRight(x, y);
|
||||||
} else if (spriteNameRight == "rockford" && this.levelModel.getRockford().isRunningLeft() && this.levelModel.getGroundLevelModel()[x - 1][y].getSpriteName() == "black") {
|
} else if (spriteNameRight == "rockford" && this.levelModel.getRockford().isRunningLeft() && this.levelModel.getGroundLevelModel()[x - 1][y].getSpriteName() == "black") {
|
||||||
this.levelModel.moveThisBoulderToLeft(x, y);
|
this.levelModel.moveThisBoulderToLeft(x, y);
|
||||||
} else {
|
} else {
|
||||||
this.levelModel.getGroundLevelModel()[x][y].setFalling(false);
|
this.levelModel.getGroundLevelModel()[x][y].setFalling(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,57 +12,57 @@ import java.awt.event.ActionListener;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 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 implements ActionListener {
|
public class GameController implements ActionListener {
|
||||||
private LevelModel levelModel;
|
private LevelModel levelModel;
|
||||||
private AudioLoadHelper audioLoadHelper;
|
private AudioLoadHelper audioLoadHelper;
|
||||||
private boolean firstClickOnPause;
|
private boolean firstClickOnPause;
|
||||||
private MenuView menuView;
|
private MenuView menuView;
|
||||||
private GameView gameView;
|
private GameView gameView;
|
||||||
private NavigationBetweenViewController navigationBetweenViewController;
|
private NavigationBetweenViewController navigationBetweenViewController;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor
|
* Class constructor
|
||||||
*
|
*
|
||||||
* @param levelModel Level model
|
* @param levelModel Level model
|
||||||
* @param navigationBetweenViewController
|
* @param navigationBetweenViewController
|
||||||
*/
|
*/
|
||||||
public GameController(LevelModel levelModel, AudioLoadHelper audioLoadHelper, NavigationBetweenViewController navigationBetweenViewController) {
|
public GameController(LevelModel levelModel, AudioLoadHelper audioLoadHelper, NavigationBetweenViewController navigationBetweenViewController) {
|
||||||
this.firstClickOnPause = true;
|
this.firstClickOnPause = true;
|
||||||
|
|
||||||
this.navigationBetweenViewController = navigationBetweenViewController;
|
this.navigationBetweenViewController = navigationBetweenViewController;
|
||||||
|
|
||||||
this.levelModel = levelModel;
|
this.levelModel = levelModel;
|
||||||
this.audioLoadHelper = audioLoadHelper;
|
this.audioLoadHelper = audioLoadHelper;
|
||||||
this.gameView = new GameView(this, levelModel);
|
this.gameView = new GameView(this, levelModel);
|
||||||
this.menuView = navigationBetweenViewController.getMenuView();
|
this.menuView = navigationBetweenViewController.getMenuView();
|
||||||
|
|
||||||
this.getAudioLoadHelper().stopMusic();
|
this.getAudioLoadHelper().stopMusic();
|
||||||
this.getAudioLoadHelper().playSound("new");
|
this.getAudioLoadHelper().playSound("new");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles the 'action performed' event
|
* Handles the 'action performed' event
|
||||||
*
|
*
|
||||||
* @param event Action event
|
* @param event Action event
|
||||||
*/
|
*/
|
||||||
public void actionPerformed(ActionEvent event) {
|
public void actionPerformed(ActionEvent event) {
|
||||||
switch(event.getActionCommand()) {
|
switch (event.getActionCommand()) {
|
||||||
case "pause":
|
case "pause":
|
||||||
if(this.firstClickOnPause) {
|
if (this.firstClickOnPause) {
|
||||||
this.levelModel.setGamePaused(true);
|
this.levelModel.setGamePaused(true);
|
||||||
} else if(!this.firstClickOnPause) {
|
} else if (!this.firstClickOnPause) {
|
||||||
this.levelModel.setGamePaused(false);
|
this.levelModel.setGamePaused(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.firstClickOnPause = !this.firstClickOnPause;
|
this.firstClickOnPause = !this.firstClickOnPause;
|
||||||
this.gameView.getGameFieldView().grabFocus();
|
this.gameView.getGameFieldView().grabFocus();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "restart":
|
case "restart":
|
||||||
@ -70,32 +70,32 @@ public class GameController implements ActionListener {
|
|||||||
this.getAudioLoadHelper().playSound("new");
|
this.getAudioLoadHelper().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");
|
this.getAudioLoadHelper().startMusic("game");
|
||||||
this.resetGame("menu");
|
this.resetGame("menu");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to reset the game
|
* Function to reset the game
|
||||||
*/
|
*/
|
||||||
private void resetGame(String source) {
|
private void resetGame(String source) {
|
||||||
this.gameView.dispose();
|
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
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
|
* Gets the audio load helper instance
|
||||||
*
|
*
|
||||||
* @return Audio load helper instance
|
* @return Audio load helper instance
|
||||||
*/
|
*/
|
||||||
public AudioLoadHelper getAudioLoadHelper() {
|
public AudioLoadHelper getAudioLoadHelper() {
|
||||||
return this.audioLoadHelper;
|
return this.audioLoadHelper;
|
||||||
@ -103,17 +103,19 @@ public class GameController implements ActionListener {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the game view
|
* Return the game view
|
||||||
|
*
|
||||||
* @return gameView
|
* @return gameView
|
||||||
*/
|
*/
|
||||||
public GameView getGameView() {
|
public GameView getGameView() {
|
||||||
return gameView;
|
return gameView;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the gameView
|
* Set the gameView
|
||||||
* @param gameView
|
*
|
||||||
*/
|
* @param gameView
|
||||||
public void setGameView(GameView gameView) {
|
*/
|
||||||
this.gameView = gameView;
|
public void setGameView(GameView gameView) {
|
||||||
}
|
this.gameView = gameView;
|
||||||
|
}
|
||||||
}
|
}
|
@ -12,32 +12,33 @@ import java.awt.event.KeyListener;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 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 implements KeyListener {
|
public class GameKeyController implements KeyListener {
|
||||||
private LevelModel levelModel;
|
private LevelModel levelModel;
|
||||||
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, AudioLoadHelper audioLoadHelper) {
|
||||||
this.levelModel = levelModel;
|
this.levelModel = levelModel;
|
||||||
new BoulderAndDiamondController(levelModel, audioLoadHelper);
|
new BoulderAndDiamondController(levelModel, audioLoadHelper);
|
||||||
this.updatePosRockford = new RockfordUpdateController(levelModel);
|
this.updatePosRockford = new RockfordUpdateController(levelModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles the 'key pressed' event
|
* Handles the 'key pressed' event
|
||||||
*
|
*
|
||||||
* @param e Key event
|
* @param e Key event
|
||||||
*/
|
*/
|
||||||
public void keyPressed(KeyEvent e) {
|
public void keyPressed(KeyEvent e) {
|
||||||
int keyCode = e.getKeyCode();
|
int keyCode = e.getKeyCode();
|
||||||
|
|
||||||
switch (keyCode) {
|
switch (keyCode) {
|
||||||
@ -85,25 +86,25 @@ public class GameKeyController implements KeyListener {
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles the 'key released' event
|
* Handles the 'key released' event
|
||||||
*
|
*
|
||||||
* @param e Key event
|
* @param e Key event
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void keyReleased(KeyEvent e) {
|
public void keyReleased(KeyEvent e) {
|
||||||
this.levelModel.getRockford().startStaying();
|
this.levelModel.getRockford().startStaying();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles the 'key typed' event
|
* Handles the 'key typed' event
|
||||||
*
|
*
|
||||||
* @param e Key event
|
* @param e Key event
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void keyTyped(KeyEvent e) {
|
public void keyTyped(KeyEvent e) {
|
||||||
// Do nothing.
|
// Do nothing.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,21 +15,21 @@ import javax.swing.*;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 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 implements ActionListener {
|
public class LevelEditorController implements ActionListener {
|
||||||
private LevelModel levelModel;
|
private LevelModel levelModel;
|
||||||
private LevelEditorView levelEditorView;
|
private LevelEditorView levelEditorView;
|
||||||
private NavigationBetweenViewController nav;
|
private NavigationBetweenViewController nav;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor'
|
* Class constructor'
|
||||||
*
|
*
|
||||||
* @param levelModel Level model
|
* @param levelModel Level model
|
||||||
*/
|
*/
|
||||||
public LevelEditorController(LevelModel levelModel, NavigationBetweenViewController nav) {
|
public LevelEditorController(LevelModel levelModel, NavigationBetweenViewController nav) {
|
||||||
this.levelModel = levelModel;
|
this.levelModel = levelModel;
|
||||||
@ -37,7 +37,7 @@ public class LevelEditorController implements ActionListener {
|
|||||||
|
|
||||||
this.nav = nav;
|
this.nav = nav;
|
||||||
this.nav.getAudioLoadHelper().stopMusic();
|
this.nav.getAudioLoadHelper().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)
|
||||||
@ -47,13 +47,13 @@ public class LevelEditorController implements ActionListener {
|
|||||||
/**
|
/**
|
||||||
* Handles the 'action performed' event
|
* Handles the 'action performed' event
|
||||||
*
|
*
|
||||||
* @param event Action event
|
* @param event Action event
|
||||||
*/
|
*/
|
||||||
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);
|
||||||
this.nav.setMenuView();
|
this.nav.setMenuView();
|
||||||
this.nav.getAudioLoadHelper().startMusic("game");
|
this.nav.getAudioLoadHelper().startMusic("game");
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -67,7 +67,7 @@ public class LevelEditorController implements ActionListener {
|
|||||||
String levelId = this.levelEditorView.getSelectedLevel();
|
String levelId = this.levelEditorView.getSelectedLevel();
|
||||||
LevelSaveHelper levelSave;
|
LevelSaveHelper levelSave;
|
||||||
|
|
||||||
if(levelId == null || levelId.isEmpty()) {
|
if (levelId == null || levelId.isEmpty()) {
|
||||||
// Create a new level
|
// Create a new level
|
||||||
levelSave = new LevelSaveHelper(levelModel.getGroundLevelModel());
|
levelSave = new LevelSaveHelper(levelModel.getGroundLevelModel());
|
||||||
} else {
|
} else {
|
||||||
@ -79,7 +79,7 @@ public class LevelEditorController implements ActionListener {
|
|||||||
JOptionPane.showMessageDialog(frameDialog, "Level saved");
|
JOptionPane.showMessageDialog(frameDialog, "Level saved");
|
||||||
|
|
||||||
this.levelEditorView.openedLevelChange(levelSave.getLevelId());
|
this.levelEditorView.openedLevelChange(levelSave.getLevelId());
|
||||||
} catch(LevelConstraintNotRespectedException e) {
|
} catch (LevelConstraintNotRespectedException e) {
|
||||||
JFrame frameDialog = new JFrame("Error");
|
JFrame frameDialog = new JFrame("Error");
|
||||||
JOptionPane.showMessageDialog(frameDialog, e.getMessage());
|
JOptionPane.showMessageDialog(frameDialog, e.getMessage());
|
||||||
}
|
}
|
||||||
@ -90,7 +90,7 @@ public class LevelEditorController implements ActionListener {
|
|||||||
String levelId = this.levelEditorView.getSelectedLevel();
|
String levelId = this.levelEditorView.getSelectedLevel();
|
||||||
JFrame frameDialog = new JFrame("Info");
|
JFrame frameDialog = new JFrame("Info");
|
||||||
|
|
||||||
if(levelId == null || levelId.isEmpty()) {
|
if (levelId == null || levelId.isEmpty()) {
|
||||||
JOptionPane.showMessageDialog(frameDialog, "Level not yet saved, no need to delete it!");
|
JOptionPane.showMessageDialog(frameDialog, "Level not yet saved, no need to delete it!");
|
||||||
} else {
|
} else {
|
||||||
new LevelRemoveHelper(levelId);
|
new LevelRemoveHelper(levelId);
|
||||||
@ -99,9 +99,9 @@ public class LevelEditorController implements ActionListener {
|
|||||||
this.levelEditorView.openedLevelChange(null);
|
this.levelEditorView.openedLevelChange(null);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "help":
|
case "help":
|
||||||
new HelpView();
|
new HelpView();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "new":
|
case "new":
|
||||||
@ -115,16 +115,16 @@ public class LevelEditorController implements ActionListener {
|
|||||||
/**
|
/**
|
||||||
* Gets the level editor view
|
* Gets the level editor view
|
||||||
*
|
*
|
||||||
* @return Level editor view
|
* @return Level editor view
|
||||||
*/
|
*/
|
||||||
public LevelEditorView getLevelEditorView() {
|
public LevelEditorView getLevelEditorView() {
|
||||||
return levelEditorView;
|
return levelEditorView;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets level model
|
* Gets level model
|
||||||
*
|
*
|
||||||
* @return Level model
|
* @return Level model
|
||||||
*/
|
*/
|
||||||
public LevelModel getLevelModel() {
|
public LevelModel getLevelModel() {
|
||||||
return this.levelModel;
|
return this.levelModel;
|
||||||
@ -133,11 +133,11 @@ public class LevelEditorController implements ActionListener {
|
|||||||
/**
|
/**
|
||||||
* Sets the level editor view
|
* Sets the level editor view
|
||||||
*
|
*
|
||||||
* @param levelEditorView Level editor view
|
* @param levelEditorView Level editor view
|
||||||
*/
|
*/
|
||||||
public void setLevelEditorView(LevelEditorView levelEditorView) {
|
public void setLevelEditorView(LevelEditorView levelEditorView) {
|
||||||
this.levelEditorView = levelEditorView;
|
this.levelEditorView = levelEditorView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -9,22 +9,22 @@ import java.awt.event.KeyListener;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 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 implements KeyListener {
|
public class LevelEditorKeyController implements KeyListener {
|
||||||
private LevelModel levelModel;
|
private LevelModel levelModel;
|
||||||
private LevelEditorView levelEditorView;
|
private LevelEditorView levelEditorView;
|
||||||
private boolean capLocks;
|
private boolean capLocks;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor
|
* Class constructor
|
||||||
*
|
*
|
||||||
* @param levelModel Level model
|
* @param levelModel Level model
|
||||||
* @param levelEditorView Level editor view
|
* @param levelEditorView Level editor view
|
||||||
*/
|
*/
|
||||||
public LevelEditorKeyController(LevelModel levelModel, LevelEditorView levelEditorView) {
|
public LevelEditorKeyController(LevelModel levelModel, LevelEditorView levelEditorView) {
|
||||||
this.levelModel = levelModel;
|
this.levelModel = levelModel;
|
||||||
@ -35,7 +35,7 @@ public class LevelEditorKeyController implements KeyListener {
|
|||||||
/**
|
/**
|
||||||
* Handles the 'key pressed' event
|
* Handles the 'key pressed' event
|
||||||
*
|
*
|
||||||
* @param e Key event
|
* @param e Key event
|
||||||
*/
|
*/
|
||||||
public void keyPressed(KeyEvent e) {
|
public void keyPressed(KeyEvent e) {
|
||||||
int keyCode = e.getKeyCode();
|
int keyCode = e.getKeyCode();
|
||||||
@ -65,22 +65,22 @@ public class LevelEditorKeyController implements KeyListener {
|
|||||||
case KeyEvent.VK_SPACE:
|
case KeyEvent.VK_SPACE:
|
||||||
this.levelModel.triggerBlockChange(this.levelEditorView.getPickedBlockValue());
|
this.levelModel.triggerBlockChange(this.levelEditorView.getPickedBlockValue());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 16:
|
case 16:
|
||||||
this.capLocks = !capLocks;
|
this.capLocks = !capLocks;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hold block change (quick edit)
|
// Hold block change (quick edit)
|
||||||
if(capLocks) {
|
if (capLocks) {
|
||||||
this.levelModel.triggerBlockChange(this.levelEditorView.getPickedBlockValue());
|
this.levelModel.triggerBlockChange(this.levelEditorView.getPickedBlockValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles the 'key released' event
|
* Handles the 'key released' event
|
||||||
*
|
*
|
||||||
* @param e Key event
|
* @param e Key event
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void keyReleased(KeyEvent e) {
|
public void keyReleased(KeyEvent e) {
|
||||||
@ -90,7 +90,7 @@ public class LevelEditorKeyController implements KeyListener {
|
|||||||
/**
|
/**
|
||||||
* Handles the 'key typed' event
|
* Handles the 'key typed' event
|
||||||
*
|
*
|
||||||
* @param e Key event
|
* @param e Key event
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void keyTyped(KeyEvent e) {
|
public void keyTyped(KeyEvent e) {
|
||||||
|
@ -11,39 +11,38 @@ import fr.enssat.BoulderDash.controllers.GameController;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 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 AudioLoadHelper audioLoadHelper;
|
||||||
private LevelModel levelModelForGame, levelModelForEditor;
|
private LevelModel levelModelForGame, levelModelForEditor;
|
||||||
private GameController gameController;
|
private GameController gameController;
|
||||||
private String pickedLevelIdentifier;
|
private String pickedLevelIdentifier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor
|
* Class constructor
|
||||||
*/
|
*/
|
||||||
public NavigationBetweenViewController() {
|
public NavigationBetweenViewController() {
|
||||||
this.audioLoadHelper = new AudioLoadHelper();
|
this.audioLoadHelper = new AudioLoadHelper();
|
||||||
|
|
||||||
// Play game music
|
// Play game music
|
||||||
this.getAudioLoadHelper().startMusic("game");
|
this.getAudioLoadHelper().startMusic("game");
|
||||||
|
|
||||||
// Creation of the first view
|
// Creation of the first view
|
||||||
this.menuView = new MenuView(this);
|
this.menuView = new MenuView(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Action performed event handler
|
* Action performed event handler
|
||||||
*
|
*
|
||||||
* @param event Action event
|
* @param event Action event
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent event) {
|
public void actionPerformed(ActionEvent event) {
|
||||||
switch (event.getActionCommand()) {
|
switch (event.getActionCommand()) {
|
||||||
case "quit":
|
case "quit":
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
break;
|
break;
|
||||||
@ -76,16 +75,16 @@ public class NavigationBetweenViewController implements ActionListener {
|
|||||||
this.gameController.getGameView().setVisible(true);
|
this.gameController.getGameView().setVisible(true);
|
||||||
this.gameController.getGameView().getGameFieldView().grabFocus();
|
this.gameController.getGameView().getGameFieldView().grabFocus();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.menuView.setVisible(false);
|
this.menuView.setVisible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the audio load helper
|
* Get the audio load helper
|
||||||
*
|
*
|
||||||
* @return Audio load helper
|
* @return Audio load helper
|
||||||
*/
|
*/
|
||||||
public AudioLoadHelper getAudioLoadHelper() {
|
public AudioLoadHelper getAudioLoadHelper() {
|
||||||
return this.audioLoadHelper;
|
return this.audioLoadHelper;
|
||||||
@ -94,39 +93,39 @@ public class NavigationBetweenViewController implements ActionListener {
|
|||||||
/**
|
/**
|
||||||
* Get the first view
|
* Get the first view
|
||||||
*
|
*
|
||||||
* @return First view
|
* @return First view
|
||||||
*/
|
*/
|
||||||
public MenuView getMenuView() {
|
public MenuView getMenuView() {
|
||||||
return this.menuView;
|
return this.menuView;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the first view
|
* Set the first view
|
||||||
*
|
|
||||||
* @param menuView
|
|
||||||
*/
|
|
||||||
public MenuView setMenuView() {
|
|
||||||
this.menuView = new MenuView(this);
|
|
||||||
return menuView;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the pickedLevel
|
|
||||||
*
|
*
|
||||||
* @return pickedLevelIdentifier Picked level identifier
|
* @param menuView
|
||||||
*/
|
*/
|
||||||
public String getPickedLevelIdentifier() {
|
public MenuView setMenuView() {
|
||||||
return pickedLevelIdentifier;
|
this.menuView = new MenuView(this);
|
||||||
}
|
return menuView;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the pickedLevelIdentifier
|
* Get the pickedLevel
|
||||||
*
|
*
|
||||||
* @param pickedLevelIdentifier Picked level identifier
|
* @return pickedLevelIdentifier Picked level identifier
|
||||||
*/
|
*/
|
||||||
public void setPickedLevelIdentifier(String pickedLevelIdentifier) {
|
public String getPickedLevelIdentifier() {
|
||||||
this.pickedLevelIdentifier = pickedLevelIdentifier;
|
return pickedLevelIdentifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the pickedLevelIdentifier
|
||||||
|
*
|
||||||
|
* @param pickedLevelIdentifier Picked level identifier
|
||||||
|
*/
|
||||||
|
public void setPickedLevelIdentifier(String pickedLevelIdentifier) {
|
||||||
|
this.pickedLevelIdentifier = pickedLevelIdentifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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.
|
||||||
@ -13,52 +13,52 @@ import fr.enssat.BoulderDash.models.LevelModel;
|
|||||||
* @since 2015-06-19
|
* @since 2015-06-19
|
||||||
*/
|
*/
|
||||||
public class RockfordUpdateController implements Runnable {
|
public class RockfordUpdateController implements Runnable {
|
||||||
private LevelModel levelModel;
|
private LevelModel levelModel;
|
||||||
private Thread elementMovingThread;
|
private Thread elementMovingThread;
|
||||||
private int rockfordPositionX;
|
private int rockfordPositionX;
|
||||||
private int rockfordPositionY;
|
private int rockfordPositionY;
|
||||||
private boolean rockfordHasMoved;
|
private boolean rockfordHasMoved;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor
|
* Class constructor
|
||||||
*
|
*
|
||||||
* @param levelModel Level model
|
* @param levelModel Level model
|
||||||
*/
|
*/
|
||||||
public RockfordUpdateController(LevelModel levelModel) {
|
public RockfordUpdateController(LevelModel levelModel) {
|
||||||
this.levelModel = levelModel;
|
this.levelModel = levelModel;
|
||||||
this.elementMovingThread = new Thread(this);
|
this.elementMovingThread = new Thread(this);
|
||||||
this.elementMovingThread.start();
|
this.elementMovingThread.start();
|
||||||
this.rockfordHasMoved = false;
|
this.rockfordHasMoved = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Watches for elements to be moved
|
* Watches for elements to be moved
|
||||||
*/
|
*/
|
||||||
public void run() {
|
public void run() {
|
||||||
while (this.levelModel.isGameRunning()) {
|
while (this.levelModel.isGameRunning()) {
|
||||||
if(!this.levelModel.getGamePaused()){
|
if (!this.levelModel.getGamePaused()) {
|
||||||
if (this.rockfordHasMoved) {
|
if (this.rockfordHasMoved) {
|
||||||
this.levelModel.setPositionOfRockford(rockfordPositionX, rockfordPositionY);
|
this.levelModel.setPositionOfRockford(rockfordPositionX, rockfordPositionY);
|
||||||
this.rockfordHasMoved = false;
|
this.rockfordHasMoved = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Thread.sleep(100);
|
Thread.sleep(100);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Moves Rockford
|
* Moves Rockford
|
||||||
*
|
*
|
||||||
* @param rockfordPositionX Next horizontal position on the grid
|
* @param rockfordPositionX Next horizontal position on the grid
|
||||||
* @param rockfordPositionY Next vertical position on the grid
|
* @param rockfordPositionY Next vertical position on the grid
|
||||||
*/
|
*/
|
||||||
public void moveRockford(int rockfordPositionX, int rockfordPositionY) {
|
public void moveRockford(int rockfordPositionX, int rockfordPositionY) {
|
||||||
this.rockfordPositionX = rockfordPositionX;
|
this.rockfordPositionX = rockfordPositionX;
|
||||||
this.rockfordPositionY = rockfordPositionY;
|
this.rockfordPositionY = rockfordPositionY;
|
||||||
this.rockfordHasMoved = true;
|
this.rockfordHasMoved = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,18 +3,18 @@ package fr.enssat.BoulderDash.exceptions;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* LevelConstraintNotRespectedException
|
* LevelConstraintNotRespectedException
|
||||||
*
|
* <p>
|
||||||
* Raises an 'LevelConstraintNotRespectedException' exception.
|
* Raises an 'LevelConstraintNotRespectedException' exception.
|
||||||
* Given the exception message.
|
* Given the exception message.
|
||||||
*
|
*
|
||||||
* @author Valerian Saliou <valerian@valeriansaliou.name>
|
* @author Valerian Saliou <valerian@valeriansaliou.name>
|
||||||
* @since 2015-06-24
|
* @since 2015-06-24
|
||||||
*/
|
*/
|
||||||
public class LevelConstraintNotRespectedException extends Exception {
|
public class LevelConstraintNotRespectedException extends Exception {
|
||||||
/**
|
/**
|
||||||
* Class constructor
|
* Class constructor
|
||||||
*
|
*
|
||||||
* @param message Exception backtrace message
|
* @param message Exception backtrace message
|
||||||
*/
|
*/
|
||||||
public LevelConstraintNotRespectedException(String message) {
|
public LevelConstraintNotRespectedException(String message) {
|
||||||
super(message);
|
super(message);
|
||||||
|
@ -3,18 +3,18 @@ package fr.enssat.BoulderDash.exceptions;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* ModelNotReadyException
|
* ModelNotReadyException
|
||||||
*
|
* <p>
|
||||||
* Raises an 'ModelNotReadyException' exception.
|
* Raises an 'ModelNotReadyException' exception.
|
||||||
* Given the exception message.
|
* Given the exception message.
|
||||||
*
|
*
|
||||||
* @author Valerian Saliou <valerian@valeriansaliou.name>
|
* @author Valerian Saliou <valerian@valeriansaliou.name>
|
||||||
* @since 2015-06-23
|
* @since 2015-06-23
|
||||||
*/
|
*/
|
||||||
public class ModelNotReadyException extends Exception {
|
public class ModelNotReadyException extends Exception {
|
||||||
/**
|
/**
|
||||||
* Class constructor
|
* Class constructor
|
||||||
*
|
*
|
||||||
* @param message Exception backtrace message
|
* @param message Exception backtrace message
|
||||||
*/
|
*/
|
||||||
public ModelNotReadyException(String message) {
|
public ModelNotReadyException(String message) {
|
||||||
super(message);
|
super(message);
|
||||||
|
@ -3,20 +3,20 @@ package fr.enssat.BoulderDash.exceptions;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* UnknownModelException
|
* UnknownModelException
|
||||||
*
|
* <p>
|
||||||
* Raises an 'UnknownSpriteException' exception.
|
* Raises an 'UnknownSpriteException' exception.
|
||||||
* Given the exception message.
|
* Given the exception message.
|
||||||
*
|
*
|
||||||
* @author Valerian Saliou <valerian@valeriansaliou.name>
|
* @author Valerian Saliou <valerian@valeriansaliou.name>
|
||||||
* @since 2015-06-19
|
* @since 2015-06-19
|
||||||
*/
|
*/
|
||||||
public class UnknownModelException extends Exception {
|
public class UnknownModelException extends Exception {
|
||||||
/**
|
/**
|
||||||
* Class constructor
|
* Class constructor
|
||||||
*
|
*
|
||||||
* @param message Exception backtrace message
|
* @param message Exception backtrace message
|
||||||
*/
|
*/
|
||||||
public UnknownModelException(String message) {
|
public UnknownModelException(String message) {
|
||||||
super(message);
|
super(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,11 +8,11 @@ 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 String pathToAudioStore = "./res/audio";
|
||||||
@ -30,8 +30,8 @@ public class AudioLoadHelper {
|
|||||||
/**
|
/**
|
||||||
* Gets music storage path
|
* Gets music storage path
|
||||||
*
|
*
|
||||||
* @param musicId Music identifier
|
* @param musicId Music identifier
|
||||||
* @return Music path, with file extension
|
* @return Music path, with file extension
|
||||||
*/
|
*/
|
||||||
private String getMusicPathInAudioStore(String musicId) {
|
private String getMusicPathInAudioStore(String musicId) {
|
||||||
return AudioLoadHelper.pathToAudioStore + "/music/" + musicId + ".mp3";
|
return AudioLoadHelper.pathToAudioStore + "/music/" + musicId + ".mp3";
|
||||||
@ -40,10 +40,10 @@ public class AudioLoadHelper {
|
|||||||
/**
|
/**
|
||||||
* Starts game music
|
* Starts game music
|
||||||
*
|
*
|
||||||
* @param musicId Music identifier
|
* @param musicId Music identifier
|
||||||
*/
|
*/
|
||||||
public void startMusic(String musicId) {
|
public void startMusic(String musicId) {
|
||||||
if(this.musicToPlay != null) {
|
if (this.musicToPlay != null) {
|
||||||
this.stopMusic();
|
this.stopMusic();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,7 +70,7 @@ public class AudioLoadHelper {
|
|||||||
|
|
||||||
// List sound files
|
// List sound files
|
||||||
File soundsDir = new File(AudioLoadHelper.pathToAudioStore + "/sounds/");
|
File soundsDir = new File(AudioLoadHelper.pathToAudioStore + "/sounds/");
|
||||||
File [] soundFiles = soundsDir.listFiles(new FilenameFilter() {
|
File[] soundFiles = soundsDir.listFiles(new FilenameFilter() {
|
||||||
@Override
|
@Override
|
||||||
public boolean accept(File dir, String name) {
|
public boolean accept(File dir, String name) {
|
||||||
return name.endsWith(".mp3");
|
return name.endsWith(".mp3");
|
||||||
@ -91,8 +91,8 @@ public class AudioLoadHelper {
|
|||||||
/**
|
/**
|
||||||
* Gets a preloaded sound
|
* Gets a preloaded sound
|
||||||
*
|
*
|
||||||
* @param soundId Sound identifier
|
* @param soundId Sound identifier
|
||||||
* @return Preloaded sound instance
|
* @return Preloaded sound instance
|
||||||
*/
|
*/
|
||||||
private SoundJLayerBridge getPreloadedSound(String soundId) {
|
private SoundJLayerBridge getPreloadedSound(String soundId) {
|
||||||
return this.preloadedSounds.get(soundId);
|
return this.preloadedSounds.get(soundId);
|
||||||
@ -101,7 +101,7 @@ public class AudioLoadHelper {
|
|||||||
/**
|
/**
|
||||||
* Plays a sound
|
* Plays a sound
|
||||||
*
|
*
|
||||||
* @param soundId Sound identifier
|
* @param soundId Sound identifier
|
||||||
*/
|
*/
|
||||||
public void playSound(String soundId) {
|
public void playSound(String soundId) {
|
||||||
this.getPreloadedSound(soundId).play();
|
this.getPreloadedSound(soundId).play();
|
||||||
|
@ -36,233 +36,233 @@ import java.util.Locale;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* LevelLoadHelper
|
* LevelLoadHelper
|
||||||
*
|
* <p>
|
||||||
* Proceeds level load routine
|
* Proceeds level load routine
|
||||||
* Able to deserialize level data from storage, and format it to
|
* Able to deserialize level data from storage, and format it to
|
||||||
* internal representation To be used as a data factory from level
|
* internal representation To be used as a data factory from level
|
||||||
* model classes
|
* model classes
|
||||||
*
|
*
|
||||||
* @author Valerian Saliou <valerian@valeriansaliou.name>
|
* @author Valerian Saliou <valerian@valeriansaliou.name>
|
||||||
* @since 2015-06-19
|
* @since 2015-06-19
|
||||||
*/
|
*/
|
||||||
public class LevelLoadHelper {
|
public class LevelLoadHelper {
|
||||||
private static String pathToDataStore = "./res/levels";
|
private static String pathToDataStore = "./res/levels";
|
||||||
private String levelId = null;
|
private String levelId = null;
|
||||||
private Document levelDOM;
|
private Document levelDOM;
|
||||||
private XPath xpathBuilder;
|
private XPath xpathBuilder;
|
||||||
private SimpleDateFormat dateFormatter;
|
private SimpleDateFormat dateFormatter;
|
||||||
|
|
||||||
// Parsed values
|
// Parsed values
|
||||||
private String nameValue = null;
|
private String nameValue = null;
|
||||||
private Date dateCreatedValue = null;
|
private Date dateCreatedValue = null;
|
||||||
private Date dateModifiedValue = null;
|
private Date dateModifiedValue = null;
|
||||||
|
|
||||||
private int widthSizeValue = 0;
|
private int widthSizeValue = 0;
|
||||||
private int heightSizeValue = 0;
|
private int heightSizeValue = 0;
|
||||||
private int limitsWidth = 2;
|
private int limitsWidth = 2;
|
||||||
private int limitsHeight = 2;
|
private int limitsHeight = 2;
|
||||||
private int limitsOffsetWidth = 1;
|
private int limitsOffsetWidth = 1;
|
||||||
private int limitsOffsetHeight = 1;
|
private int limitsOffsetHeight = 1;
|
||||||
|
|
||||||
private RockfordModel rockfordInstance;
|
private RockfordModel rockfordInstance;
|
||||||
private int rockfordPositionX = 0;
|
private int rockfordPositionX = 0;
|
||||||
private int rockfordPositionY = 0;
|
private int rockfordPositionY = 0;
|
||||||
|
|
||||||
private int diamondsToCatch;
|
|
||||||
|
|
||||||
private DisplayableElementModel[][] groundGrid;
|
private int diamondsToCatch;
|
||||||
|
|
||||||
|
private DisplayableElementModel[][] groundGrid;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor
|
* Class constructor
|
||||||
*
|
*
|
||||||
* @param levelId Level identifier
|
* @param levelId Level identifier
|
||||||
*/
|
*/
|
||||||
public LevelLoadHelper(String levelId) {
|
public LevelLoadHelper(String levelId) {
|
||||||
this.setLevelId(levelId);
|
this.setLevelId(levelId);
|
||||||
this.diamondsToCatch = 0;
|
this.diamondsToCatch = 0;
|
||||||
|
|
||||||
// Requirements
|
// Requirements
|
||||||
this.dateFormatter = new SimpleDateFormat("yyy-MM-dd/HH:mm:ss", Locale.ENGLISH);
|
this.dateFormatter = new SimpleDateFormat("yyy-MM-dd/HH:mm:ss", Locale.ENGLISH);
|
||||||
|
|
||||||
if (this.levelId != null) {
|
if (this.levelId != null) {
|
||||||
// Let's go.
|
// Let's go.
|
||||||
this.loadLevelData();
|
this.loadLevelData();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets level storage path
|
* Gets level storage path
|
||||||
*
|
*
|
||||||
* @return Level path, with file extension
|
* @return Level path, with file extension
|
||||||
*/
|
*/
|
||||||
private String getLevelPathInDataStore() {
|
private String getLevelPathInDataStore() {
|
||||||
return this.pathToDataStore + "/" + this.getLevelId() + ".xml";
|
return this.pathToDataStore + "/" + this.getLevelId() + ".xml";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads the level data into instance data space
|
* Loads the level data into instance data space
|
||||||
*/
|
*/
|
||||||
private void loadLevelData() {
|
private void loadLevelData() {
|
||||||
this.xpathBuilder = XPathFactory.newInstance().newXPath();
|
this.xpathBuilder = XPathFactory.newInstance().newXPath();
|
||||||
|
|
||||||
String pathToData = this.getLevelPathInDataStore();
|
String pathToData = this.getLevelPathInDataStore();
|
||||||
|
|
||||||
// Parse & process level data
|
// Parse & process level data
|
||||||
this.parseLevelData(pathToData);
|
this.parseLevelData(pathToData);
|
||||||
this.processLevelData();
|
this.processLevelData();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses the level data for the given file
|
* Parses the level data for the given file
|
||||||
* Handles the task of reading and storing the parsed DOM
|
* Handles the task of reading and storing the parsed DOM
|
||||||
*
|
*
|
||||||
* @param pathToLevelData FS path to the level data
|
* @param pathToLevelData FS path to the level data
|
||||||
*/
|
*/
|
||||||
private void parseLevelData(String pathToLevelData) {
|
private void parseLevelData(String pathToLevelData) {
|
||||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||||
|
|
||||||
// Parse data in level file
|
// Parse data in level file
|
||||||
this.levelDOM = documentBuilder.parse(pathToLevelData);
|
this.levelDOM = documentBuilder.parse(pathToLevelData);
|
||||||
} catch (ParserConfigurationException e) {
|
} catch (ParserConfigurationException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (org.xml.sax.SAXException e) {
|
} catch (org.xml.sax.SAXException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes the parsed level data
|
* Processes the parsed level data
|
||||||
*/
|
*/
|
||||||
private void processLevelData() {
|
private void processLevelData() {
|
||||||
// Parse elements from structure
|
// Parse elements from structure
|
||||||
try {
|
try {
|
||||||
this.processNameElement();
|
this.processNameElement();
|
||||||
this.processDateElement();
|
this.processDateElement();
|
||||||
this.processSizeElement();
|
this.processSizeElement();
|
||||||
this.processGridElement();
|
this.processGridElement();
|
||||||
} catch (XPathExpressionException e) {
|
} catch (XPathExpressionException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes the 'name' element
|
* Processes the 'name' element
|
||||||
*/
|
*/
|
||||||
private void processNameElement() throws XPathExpressionException {
|
private void processNameElement() throws XPathExpressionException {
|
||||||
// Returns level name value
|
// Returns level name value
|
||||||
this.nameValue = this.xpathBuilder.compile("/bd-level/name").evaluate(this.levelDOM);
|
this.nameValue = this.xpathBuilder.compile("/bd-level/name").evaluate(this.levelDOM);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes the 'date' element
|
* Processes the 'date' element
|
||||||
*/
|
*/
|
||||||
private void processDateElement() throws XPathExpressionException, ParseException {
|
private void processDateElement() throws XPathExpressionException, ParseException {
|
||||||
// Returns level creation date value
|
// Returns level creation date value
|
||||||
this.dateCreatedValue = this.dateFormatter.parse(xpathBuilder.compile("/bd-level/date[@format='utc']/created").evaluate(this.levelDOM));
|
this.dateCreatedValue = this.dateFormatter.parse(xpathBuilder.compile("/bd-level/date[@format='utc']/created").evaluate(this.levelDOM));
|
||||||
|
|
||||||
// Returns level modification date value
|
// Returns level modification date value
|
||||||
this.dateModifiedValue = this.dateFormatter.parse(this.xpathBuilder.compile("/bd-level/date[@format='utc']/modified").evaluate(this.levelDOM));
|
this.dateModifiedValue = this.dateFormatter.parse(this.xpathBuilder.compile("/bd-level/date[@format='utc']/modified").evaluate(this.levelDOM));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes the 'size' element
|
* Processes the 'size' element
|
||||||
*/
|
*/
|
||||||
private void processSizeElement() throws XPathExpressionException {
|
private void processSizeElement() throws XPathExpressionException {
|
||||||
// Returns level width value
|
// Returns level width value
|
||||||
this.widthSizeValue = Integer.parseInt(this.xpathBuilder.compile("/bd-level/size/width").evaluate(this.levelDOM));
|
this.widthSizeValue = Integer.parseInt(this.xpathBuilder.compile("/bd-level/size/width").evaluate(this.levelDOM));
|
||||||
this.widthSizeValue += this.limitsWidth;
|
this.widthSizeValue += this.limitsWidth;
|
||||||
|
|
||||||
// Returns level height value
|
// Returns level height value
|
||||||
this.heightSizeValue = Integer.parseInt(this.xpathBuilder.compile("/bd-level/size/height").evaluate(this.levelDOM));
|
this.heightSizeValue = Integer.parseInt(this.xpathBuilder.compile("/bd-level/size/height").evaluate(this.levelDOM));
|
||||||
this.heightSizeValue += this.limitsHeight;
|
this.heightSizeValue += this.limitsHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes the 'grid' element
|
* Processes the 'grid' element
|
||||||
*/
|
*/
|
||||||
private void processGridElement() throws XPathExpressionException {
|
private void processGridElement() throws XPathExpressionException {
|
||||||
// Initialize the grid
|
// Initialize the grid
|
||||||
this.groundGrid = new DisplayableElementModel[this.widthSizeValue][this.heightSizeValue];
|
this.groundGrid = new DisplayableElementModel[this.widthSizeValue][this.heightSizeValue];
|
||||||
|
|
||||||
// Populate the grid
|
// Populate the grid
|
||||||
NodeList lineNode = (NodeList) this.xpathBuilder.compile("/bd-level/grid[@state='initial']/line").evaluate(this.levelDOM, XPathConstants.NODESET);
|
NodeList lineNode = (NodeList) this.xpathBuilder.compile("/bd-level/grid[@state='initial']/line").evaluate(this.levelDOM, XPathConstants.NODESET);
|
||||||
|
|
||||||
// Parse lines
|
// Parse lines
|
||||||
for (int y = 0; y < lineNode.getLength(); y++) {
|
for (int y = 0; y < lineNode.getLength(); y++) {
|
||||||
Node currentLineNode = lineNode.item(y);
|
Node currentLineNode = lineNode.item(y);
|
||||||
|
|
||||||
// Current line
|
// Current line
|
||||||
if (currentLineNode.getNodeType() == Node.ELEMENT_NODE) {
|
if (currentLineNode.getNodeType() == Node.ELEMENT_NODE) {
|
||||||
Element currentLineElement = (Element) currentLineNode;
|
Element currentLineElement = (Element) currentLineNode;
|
||||||
int lineIndex = Integer.parseInt(currentLineElement.getAttribute("index"));
|
int lineIndex = Integer.parseInt(currentLineElement.getAttribute("index"));
|
||||||
|
|
||||||
NodeList rowNode = (NodeList) currentLineNode.getChildNodes();
|
NodeList rowNode = (NodeList) currentLineNode.getChildNodes();
|
||||||
|
|
||||||
for (int x = 0; x < rowNode.getLength(); x++) {
|
for (int x = 0; x < rowNode.getLength(); x++) {
|
||||||
Node currentRowNode = rowNode.item(x);
|
Node currentRowNode = rowNode.item(x);
|
||||||
|
|
||||||
// Current row
|
// Current row
|
||||||
if (currentRowNode.getNodeType() == Node.ELEMENT_NODE) {
|
if (currentRowNode.getNodeType() == Node.ELEMENT_NODE) {
|
||||||
Element currentRowElement = (Element) currentRowNode;
|
Element currentRowElement = (Element) currentRowNode;
|
||||||
int rowIndex = Integer.parseInt(currentRowElement.getAttribute("index"));
|
int rowIndex = Integer.parseInt(currentRowElement.getAttribute("index"));
|
||||||
|
|
||||||
NodeList spriteNode = currentRowElement.getElementsByTagName("sprite");
|
NodeList spriteNode = currentRowElement.getElementsByTagName("sprite");
|
||||||
|
|
||||||
if (spriteNode.getLength() > 0) {
|
if (spriteNode.getLength() > 0) {
|
||||||
Node currentSpriteNode = spriteNode.item(0);
|
Node currentSpriteNode = spriteNode.item(0);
|
||||||
|
|
||||||
if (currentSpriteNode.getNodeType() == Node.ELEMENT_NODE) {
|
if (currentSpriteNode.getNodeType() == Node.ELEMENT_NODE) {
|
||||||
Element currentSpriteElement = (Element) currentSpriteNode;
|
Element currentSpriteElement = (Element) currentSpriteNode;
|
||||||
String currentSpriteName = currentSpriteElement.getAttribute("name");
|
String currentSpriteName = currentSpriteElement.getAttribute("name");
|
||||||
String currentSpriteConvertibleValue = currentSpriteElement.getAttribute("convertible");
|
String currentSpriteConvertibleValue = currentSpriteElement.getAttribute("convertible");
|
||||||
boolean currentSpriteConvertible = false;
|
boolean currentSpriteConvertible = false;
|
||||||
|
|
||||||
// No name? Continue.
|
// No name? Continue.
|
||||||
if(currentSpriteName == null || currentSpriteName.isEmpty()) {
|
if (currentSpriteName == null || currentSpriteName.isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(currentSpriteConvertibleValue.equals("1")) {
|
if (currentSpriteConvertibleValue.equals("1")) {
|
||||||
currentSpriteConvertible = true;
|
currentSpriteConvertible = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process positions
|
// Process positions
|
||||||
int pX = rowIndex + this.limitsOffsetWidth;
|
int pX = rowIndex + this.limitsOffsetWidth;
|
||||||
int pY = lineIndex + this.limitsOffsetHeight;
|
int pY = lineIndex + this.limitsOffsetHeight;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.groundGrid[pX][pY] = this.constructGridElement(currentSpriteName, pX, pY, currentSpriteConvertible);
|
this.groundGrid[pX][pY] = this.constructGridElement(currentSpriteName, pX, pY, currentSpriteConvertible);
|
||||||
} catch (UnknownModelException e) {
|
} catch (UnknownModelException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs the grid element
|
* Constructs the grid element
|
||||||
*
|
*
|
||||||
* @param spriteName Sprite name
|
* @param spriteName Sprite name
|
||||||
* @param rowIndex Position in row (horizontal axis)
|
* @param rowIndex Position in row (horizontal axis)
|
||||||
* @param lineIndex Position in line (vertical axis)
|
* @param lineIndex Position in line (vertical axis)
|
||||||
*/
|
*/
|
||||||
private DisplayableElementModel constructGridElement(String spriteName, int rowIndex, int lineIndex, boolean convertible) throws UnknownModelException {
|
private DisplayableElementModel constructGridElement(String spriteName, int rowIndex, int lineIndex, boolean convertible) throws UnknownModelException {
|
||||||
ModelConvertHelper modelConvert = new ModelConvertHelper();
|
ModelConvertHelper modelConvert = new ModelConvertHelper();
|
||||||
DisplayableElementModel element = modelConvert.toModel(spriteName, convertible);
|
DisplayableElementModel element = modelConvert.toModel(spriteName, convertible);
|
||||||
|
|
||||||
// Custom actions?
|
// Custom actions?
|
||||||
switch (spriteName) {
|
switch (spriteName) {
|
||||||
case "diamond":
|
case "diamond":
|
||||||
diamondsToCatch += 1;
|
diamondsToCatch += 1;
|
||||||
break;
|
break;
|
||||||
@ -272,206 +272,208 @@ public class LevelLoadHelper {
|
|||||||
this.setRockfordPositionY(lineIndex);
|
this.setRockfordPositionY(lineIndex);
|
||||||
this.setRockfordInstance((RockfordModel) element);
|
this.setRockfordInstance((RockfordModel) element);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the level identifier
|
* Gets the level identifier
|
||||||
*
|
*
|
||||||
* @return Level identifier
|
* @return Level identifier
|
||||||
*/
|
*/
|
||||||
public String getLevelId() {
|
public String getLevelId() {
|
||||||
return this.levelId;
|
return this.levelId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the level identifier
|
* Sets the level identifier
|
||||||
*
|
*
|
||||||
* @param levelId Level identifier
|
* @param levelId Level identifier
|
||||||
*/
|
*/
|
||||||
private void setLevelId(String levelId) {
|
private void setLevelId(String levelId) {
|
||||||
this.levelId = levelId;
|
this.levelId = levelId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the name value
|
* Gets the name value
|
||||||
*
|
*
|
||||||
* @return Name value
|
* @return Name value
|
||||||
*/
|
*/
|
||||||
public String getNameValue() {
|
public String getNameValue() {
|
||||||
return this.nameValue;
|
return this.nameValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the name value
|
* Sets the name value
|
||||||
*
|
*
|
||||||
* @param nameValue Name value
|
* @param nameValue Name value
|
||||||
*/
|
*/
|
||||||
private void setNameValue(String nameValue) {
|
private void setNameValue(String nameValue) {
|
||||||
this.nameValue = nameValue;
|
this.nameValue = nameValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the creation date value
|
* Gets the creation date value
|
||||||
*
|
*
|
||||||
* @return Creation date value
|
* @return Creation date value
|
||||||
*/
|
*/
|
||||||
public Date getDateCreatedValue() {
|
public Date getDateCreatedValue() {
|
||||||
return this.dateCreatedValue;
|
return this.dateCreatedValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the creation date value
|
* Sets the creation date value
|
||||||
*
|
*
|
||||||
* @param dateCreatedValue Creation date value
|
* @param dateCreatedValue Creation date value
|
||||||
*/
|
*/
|
||||||
private void setDateCreatedValue(Date dateCreatedValue) {
|
private void setDateCreatedValue(Date dateCreatedValue) {
|
||||||
this.dateCreatedValue = dateCreatedValue;
|
this.dateCreatedValue = dateCreatedValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the modified date value
|
* Gets the modified date value
|
||||||
*
|
*
|
||||||
* @return Modified date value
|
* @return Modified date value
|
||||||
*/
|
*/
|
||||||
public Date getDateModifiedValue() {
|
public Date getDateModifiedValue() {
|
||||||
return this.dateModifiedValue;
|
return this.dateModifiedValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the modified date value
|
* Sets the modified date value
|
||||||
*
|
*
|
||||||
* @param dateModifiedValue Modified date value
|
* @param dateModifiedValue Modified date value
|
||||||
*/
|
*/
|
||||||
private void setDateModifiedValue(Date dateModifiedValue) {
|
private void setDateModifiedValue(Date dateModifiedValue) {
|
||||||
this.dateModifiedValue = dateModifiedValue;
|
this.dateModifiedValue = dateModifiedValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the width size value
|
* Gets the width size value
|
||||||
*
|
*
|
||||||
* @return Width size value
|
* @return Width size value
|
||||||
*/
|
*/
|
||||||
public int getWidthSizeValue() {
|
public int getWidthSizeValue() {
|
||||||
return this.widthSizeValue;
|
return this.widthSizeValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the width size value
|
* Sets the width size value
|
||||||
*
|
*
|
||||||
* @param widthSizeValue Width size value
|
* @param widthSizeValue Width size value
|
||||||
*/
|
*/
|
||||||
private void setWidthSizeValue(int widthSizeValue) {
|
private void setWidthSizeValue(int widthSizeValue) {
|
||||||
this.widthSizeValue = widthSizeValue;
|
this.widthSizeValue = widthSizeValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the height size value
|
* Gets the height size value
|
||||||
*
|
*
|
||||||
* @return Height size value
|
* @return Height size value
|
||||||
*/
|
*/
|
||||||
public int getHeightSizeValue() {
|
public int getHeightSizeValue() {
|
||||||
return this.heightSizeValue;
|
return this.heightSizeValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the eight size value
|
* Sets the eight size value
|
||||||
*
|
*
|
||||||
* @param heightSizeValue Height size value
|
* @param heightSizeValue Height size value
|
||||||
*/
|
*/
|
||||||
private void setHeightSizeValue(int heightSizeValue) {
|
private void setHeightSizeValue(int heightSizeValue) {
|
||||||
this.heightSizeValue = heightSizeValue;
|
this.heightSizeValue = heightSizeValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the horizontal position of the Rockford element
|
* Gets the horizontal position of the Rockford element
|
||||||
*
|
*
|
||||||
* @return Horizontal position of the Rockford element
|
* @return Horizontal position of the Rockford element
|
||||||
*/
|
*/
|
||||||
public int getRockfordPositionX() {
|
public int getRockfordPositionX() {
|
||||||
return this.rockfordPositionX;
|
return this.rockfordPositionX;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the horizontal position of the Rockford element
|
* Sets the horizontal position of the Rockford element
|
||||||
*
|
*
|
||||||
* @param x Horizontal position of the Rockford element
|
* @param x Horizontal position of the Rockford element
|
||||||
*/
|
*/
|
||||||
public void setRockfordPositionX(int x) {
|
public void setRockfordPositionX(int x) {
|
||||||
this.rockfordPositionX = x;
|
this.rockfordPositionX = x;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the vertical position of the Rockford element
|
* Gets the vertical position of the Rockford element
|
||||||
*
|
*
|
||||||
* @return Vertical position of the Rockford element
|
* @return Vertical position of the Rockford element
|
||||||
*/
|
*/
|
||||||
public int getRockfordPositionY() {
|
public int getRockfordPositionY() {
|
||||||
return this.rockfordPositionY;
|
return this.rockfordPositionY;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the vertical position of the Rockford element
|
* Sets the vertical position of the Rockford element
|
||||||
*
|
*
|
||||||
* @param y Vertical position of the Rockford element
|
* @param y Vertical position of the Rockford element
|
||||||
*/
|
*/
|
||||||
public void setRockfordPositionY(int y) {
|
public void setRockfordPositionY(int y) {
|
||||||
this.rockfordPositionY = y;
|
this.rockfordPositionY = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the instance of Rockford
|
* Gets the instance of Rockford
|
||||||
*
|
*
|
||||||
* @return Rockford instance
|
* @return Rockford instance
|
||||||
*/
|
*/
|
||||||
public RockfordModel getRockfordInstance() {
|
public RockfordModel getRockfordInstance() {
|
||||||
return this.rockfordInstance;
|
return this.rockfordInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the instance of Rockford
|
* Sets the instance of Rockford
|
||||||
*
|
*
|
||||||
* @param rockfordInstance Rockford instance
|
* @param rockfordInstance Rockford instance
|
||||||
*/
|
*/
|
||||||
public void setRockfordInstance(RockfordModel rockfordInstance) {
|
public void setRockfordInstance(RockfordModel rockfordInstance) {
|
||||||
this.rockfordInstance = rockfordInstance;
|
this.rockfordInstance = rockfordInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the ground grid
|
* Gets the ground grid
|
||||||
*
|
*
|
||||||
* @return Ground grid
|
* @return Ground grid
|
||||||
*/
|
*/
|
||||||
public DisplayableElementModel[][] getGroundGrid() {
|
public DisplayableElementModel[][] getGroundGrid() {
|
||||||
return this.groundGrid;
|
return this.groundGrid;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the ground grid
|
* Sets the ground grid
|
||||||
*
|
*
|
||||||
* @param groundGrid Ground grid
|
* @param groundGrid Ground grid
|
||||||
*/
|
*/
|
||||||
private void setGroundGrid(DisplayableElementModel[][] groundGrid) {
|
private void setGroundGrid(DisplayableElementModel[][] groundGrid) {
|
||||||
this.groundGrid = groundGrid;
|
this.groundGrid = groundGrid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the number of Diamonds to catch
|
||||||
|
*
|
||||||
|
* @return number of Diamonds to catch
|
||||||
|
*/
|
||||||
|
public int getDiamondsToCatch() {
|
||||||
|
return diamondsToCatch;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the number of Diamonds to catch
|
||||||
|
*
|
||||||
|
* @param diamondsToCatch
|
||||||
|
*/
|
||||||
|
public void setDiamondsToCatch(int diamondsToCatch) {
|
||||||
|
this.diamondsToCatch = diamondsToCatch;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the number of Diamonds to catch
|
|
||||||
* @return number of Diamonds to catch
|
|
||||||
*/
|
|
||||||
public int getDiamondsToCatch() {
|
|
||||||
return diamondsToCatch;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the number of Diamonds to catch
|
|
||||||
* @param diamondsToCatch
|
|
||||||
*/
|
|
||||||
public void setDiamondsToCatch(int diamondsToCatch) {
|
|
||||||
this.diamondsToCatch = diamondsToCatch;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,12 +5,12 @@ import java.io.File;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* LevelRemoveHelper
|
* LevelRemoveHelper
|
||||||
*
|
* <p>
|
||||||
* Proceeds level save routine
|
* Proceeds level save routine
|
||||||
* Able to iterate on internal representation of a map and serialize it to XML
|
* Able to iterate on internal representation of a map and serialize it to XML
|
||||||
*
|
*
|
||||||
* @author Valerian Saliou <valerian@valeriansaliou.name>
|
* @author Valerian Saliou <valerian@valeriansaliou.name>
|
||||||
* @since 2015-06-21
|
* @since 2015-06-21
|
||||||
*/
|
*/
|
||||||
public class LevelRemoveHelper {
|
public class LevelRemoveHelper {
|
||||||
private static String pathToDataStore = "./res/levels";
|
private static String pathToDataStore = "./res/levels";
|
||||||
@ -19,7 +19,7 @@ public class LevelRemoveHelper {
|
|||||||
/**
|
/**
|
||||||
* Class constructor
|
* Class constructor
|
||||||
*
|
*
|
||||||
* @param levelId Level identifier
|
* @param levelId Level identifier
|
||||||
*/
|
*/
|
||||||
public LevelRemoveHelper(String levelId) {
|
public LevelRemoveHelper(String levelId) {
|
||||||
this.levelId = levelId;
|
this.levelId = levelId;
|
||||||
@ -31,7 +31,7 @@ public class LevelRemoveHelper {
|
|||||||
/**
|
/**
|
||||||
* Gets level storage path
|
* Gets level storage path
|
||||||
*
|
*
|
||||||
* @return Level path, with file extension
|
* @return Level path, with file extension
|
||||||
*/
|
*/
|
||||||
private String getLevelPathInDataStore() {
|
private String getLevelPathInDataStore() {
|
||||||
return this.pathToDataStore + "/" + this.levelId + ".xml";
|
return this.pathToDataStore + "/" + this.levelId + ".xml";
|
||||||
|
@ -23,12 +23,12 @@ import fr.enssat.BoulderDash.models.DirtModel;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* LevelSaveHelper
|
* LevelSaveHelper
|
||||||
*
|
* <p>
|
||||||
* Proceeds level save routine
|
* Proceeds level save routine
|
||||||
* Able to iterate on internal representation of a map and serialize it to XML
|
* Able to iterate on internal representation of a map and serialize it to XML
|
||||||
*
|
*
|
||||||
* @author Valerian Saliou <valerian@valeriansaliou.name>
|
* @author Valerian Saliou <valerian@valeriansaliou.name>
|
||||||
* @since 2015-06-21
|
* @since 2015-06-21
|
||||||
*/
|
*/
|
||||||
public class LevelSaveHelper {
|
public class LevelSaveHelper {
|
||||||
private static String pathToDataStore = "./res/levels";
|
private static String pathToDataStore = "./res/levels";
|
||||||
@ -39,8 +39,8 @@ public class LevelSaveHelper {
|
|||||||
/**
|
/**
|
||||||
* Class constructor
|
* Class constructor
|
||||||
*
|
*
|
||||||
* @param levelId Level identifier
|
* @param levelId Level identifier
|
||||||
* @param groundGrid Ground grid
|
* @param groundGrid Ground grid
|
||||||
*/
|
*/
|
||||||
public LevelSaveHelper(String levelId, DisplayableElementModel[][] groundGrid) {
|
public LevelSaveHelper(String levelId, DisplayableElementModel[][] groundGrid) {
|
||||||
this.setLevelId(levelId);
|
this.setLevelId(levelId);
|
||||||
@ -58,7 +58,7 @@ public class LevelSaveHelper {
|
|||||||
/**
|
/**
|
||||||
* Class constructor
|
* Class constructor
|
||||||
*
|
*
|
||||||
* @param groundGrid Ground grid
|
* @param groundGrid Ground grid
|
||||||
*/
|
*/
|
||||||
public LevelSaveHelper(DisplayableElementModel[][] groundGrid) {
|
public LevelSaveHelper(DisplayableElementModel[][] groundGrid) {
|
||||||
this(generateNewLevelId(), groundGrid);
|
this(generateNewLevelId(), groundGrid);
|
||||||
@ -67,7 +67,7 @@ public class LevelSaveHelper {
|
|||||||
/**
|
/**
|
||||||
* Gets level storage path
|
* Gets level storage path
|
||||||
*
|
*
|
||||||
* @return Level path, with file extension
|
* @return Level path, with file extension
|
||||||
*/
|
*/
|
||||||
private String getLevelPathInDataStore() {
|
private String getLevelPathInDataStore() {
|
||||||
return this.pathToDataStore + "/" + this.getLevelId() + ".xml";
|
return this.pathToDataStore + "/" + this.getLevelId() + ".xml";
|
||||||
@ -76,7 +76,7 @@ public class LevelSaveHelper {
|
|||||||
/**
|
/**
|
||||||
* Generates a new level identifier
|
* Generates a new level identifier
|
||||||
*
|
*
|
||||||
* @return Level identifier
|
* @return Level identifier
|
||||||
*/
|
*/
|
||||||
private static String generateNewLevelId() {
|
private static String generateNewLevelId() {
|
||||||
File directory = new File(pathToDataStore);
|
File directory = new File(pathToDataStore);
|
||||||
@ -93,13 +93,13 @@ public class LevelSaveHelper {
|
|||||||
Pattern pattern = Pattern.compile("^level([0-9]+)\\.xml");
|
Pattern pattern = Pattern.compile("^level([0-9]+)\\.xml");
|
||||||
Matcher matcher;
|
Matcher matcher;
|
||||||
|
|
||||||
for (File file : fileList){
|
for (File file : fileList) {
|
||||||
matcher = pattern.matcher(file.getName());
|
matcher = pattern.matcher(file.getName());
|
||||||
|
|
||||||
if (matcher.matches()) {
|
if (matcher.matches()) {
|
||||||
matchedId = matcher.group(1);
|
matchedId = matcher.group(1);
|
||||||
|
|
||||||
if(!matchedId.isEmpty()) {
|
if (!matchedId.isEmpty()) {
|
||||||
tempLevelId = new Integer(matchedId);
|
tempLevelId = new Integer(matchedId);
|
||||||
|
|
||||||
if (tempLevelId > electedLastLevelId) {
|
if (tempLevelId > electedLastLevelId) {
|
||||||
@ -117,7 +117,7 @@ public class LevelSaveHelper {
|
|||||||
electedLastLevelId += 1;
|
electedLastLevelId += 1;
|
||||||
|
|
||||||
// Stringify
|
// Stringify
|
||||||
if(electedLastLevelId < 10) {
|
if (electedLastLevelId < 10) {
|
||||||
finalLevelId = "0" + electedLastLevelId.toString();
|
finalLevelId = "0" + electedLastLevelId.toString();
|
||||||
} else {
|
} else {
|
||||||
finalLevelId = electedLastLevelId.toString();
|
finalLevelId = electedLastLevelId.toString();
|
||||||
@ -156,8 +156,8 @@ public class LevelSaveHelper {
|
|||||||
/**
|
/**
|
||||||
* Writes the level document data to disk
|
* Writes the level document data to disk
|
||||||
*
|
*
|
||||||
* @param document Document to be saved
|
* @param document Document to be saved
|
||||||
* @return Whether save was successful or not
|
* @return Whether save was successful or not
|
||||||
*/
|
*/
|
||||||
private boolean writeDocumentToDisk(Document document) {
|
private boolean writeDocumentToDisk(Document document) {
|
||||||
boolean isSuccessful = true;
|
boolean isSuccessful = true;
|
||||||
@ -180,8 +180,8 @@ public class LevelSaveHelper {
|
|||||||
/**
|
/**
|
||||||
* Creates the name node
|
* Creates the name node
|
||||||
*
|
*
|
||||||
* @param document Document
|
* @param document Document
|
||||||
* @return Name node
|
* @return Name node
|
||||||
*/
|
*/
|
||||||
private Node nameNode(Document document) {
|
private Node nameNode(Document document) {
|
||||||
String nameValue;
|
String nameValue;
|
||||||
@ -194,14 +194,14 @@ public class LevelSaveHelper {
|
|||||||
/**
|
/**
|
||||||
* Creates the date node
|
* Creates the date node
|
||||||
*
|
*
|
||||||
* @param document Document
|
* @param document Document
|
||||||
* @return Date node
|
* @return Date node
|
||||||
*/
|
*/
|
||||||
private Node dateNode(Document document) {
|
private Node dateNode(Document document) {
|
||||||
// Get values
|
// Get values
|
||||||
String dateCreatedValue, dateModifiedValue;
|
String dateCreatedValue, dateModifiedValue;
|
||||||
|
|
||||||
dateCreatedValue = "0000-00-00/00:00:00";
|
dateCreatedValue = "0000-00-00/00:00:00";
|
||||||
dateModifiedValue = "0000-00-00/00:00:00";
|
dateModifiedValue = "0000-00-00/00:00:00";
|
||||||
|
|
||||||
// Create element
|
// Create element
|
||||||
@ -218,8 +218,8 @@ public class LevelSaveHelper {
|
|||||||
/**
|
/**
|
||||||
* Creates the size node
|
* Creates the size node
|
||||||
*
|
*
|
||||||
* @param document Document
|
* @param document Document
|
||||||
* @return Size node
|
* @return Size node
|
||||||
*/
|
*/
|
||||||
private Node sizeNode(Document document) {
|
private Node sizeNode(Document document) {
|
||||||
// Get values
|
// Get values
|
||||||
@ -227,11 +227,11 @@ public class LevelSaveHelper {
|
|||||||
|
|
||||||
widthValue = this.getGroundGrid().length - 2;
|
widthValue = this.getGroundGrid().length - 2;
|
||||||
|
|
||||||
if(widthValue > 0) {
|
if (widthValue > 0) {
|
||||||
heightValue = this.getGroundGrid()[0].length - 2;
|
heightValue = this.getGroundGrid()[0].length - 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(heightValue < 0 || widthValue < 0) {
|
if (heightValue < 0 || widthValue < 0) {
|
||||||
heightValue = 0;
|
heightValue = 0;
|
||||||
widthValue = 0;
|
widthValue = 0;
|
||||||
}
|
}
|
||||||
@ -248,15 +248,15 @@ public class LevelSaveHelper {
|
|||||||
/**
|
/**
|
||||||
* Creates the grid node
|
* Creates the grid node
|
||||||
*
|
*
|
||||||
* @param document Document
|
* @param document Document
|
||||||
* @return Grid node
|
* @return Grid node
|
||||||
*/
|
*/
|
||||||
private Node gridNode(Document document) {
|
private Node gridNode(Document document) {
|
||||||
Element gridElement = document.createElement("grid");
|
Element gridElement = document.createElement("grid");
|
||||||
gridElement.setAttribute("state", "initial");
|
gridElement.setAttribute("state", "initial");
|
||||||
|
|
||||||
// Iterate in MATRIX:{x}
|
// Iterate in MATRIX:{x}
|
||||||
if(this.getGroundGrid().length > 2) {
|
if (this.getGroundGrid().length > 2) {
|
||||||
// XML structure matrix is the inverse of the internal representation (hence the weird loop)
|
// XML structure matrix is the inverse of the internal representation (hence the weird loop)
|
||||||
for (Integer curLineIndex = 1; curLineIndex < (this.getGroundGrid()[0].length - 1); curLineIndex++) {
|
for (Integer curLineIndex = 1; curLineIndex < (this.getGroundGrid()[0].length - 1); curLineIndex++) {
|
||||||
gridElement.appendChild(this.gridLineNode(document, curLineIndex));
|
gridElement.appendChild(this.gridLineNode(document, curLineIndex));
|
||||||
@ -269,16 +269,16 @@ public class LevelSaveHelper {
|
|||||||
/**
|
/**
|
||||||
* Creates the grid line node
|
* Creates the grid line node
|
||||||
*
|
*
|
||||||
* @param document Document
|
* @param document Document
|
||||||
* @param curLineIndex Current line index
|
* @param curLineIndex Current line index
|
||||||
* @return Grid line node
|
* @return Grid line node
|
||||||
*/
|
*/
|
||||||
private Node gridLineNode(Document document, Integer curLineIndex) {
|
private Node gridLineNode(Document document, Integer curLineIndex) {
|
||||||
Element gridLineElement = document.createElement("line");
|
Element gridLineElement = document.createElement("line");
|
||||||
gridLineElement.setAttribute("index", Integer.toString(curLineIndex - 1));
|
gridLineElement.setAttribute("index", Integer.toString(curLineIndex - 1));
|
||||||
|
|
||||||
// Iterate in MATRIX:X:{y}
|
// Iterate in MATRIX:X:{y}
|
||||||
if(this.getGroundGrid().length > 2) {
|
if (this.getGroundGrid().length > 2) {
|
||||||
// XML structure matrix is the inverse of the internal representation (hence the weird loop)
|
// XML structure matrix is the inverse of the internal representation (hence the weird loop)
|
||||||
for (Integer curItemIndex = 1; curItemIndex < (this.getGroundGrid().length - 1); curItemIndex++) {
|
for (Integer curItemIndex = 1; curItemIndex < (this.getGroundGrid().length - 1); curItemIndex++) {
|
||||||
gridLineElement.appendChild(this.gridLineItemNode(document, curLineIndex, curItemIndex));
|
gridLineElement.appendChild(this.gridLineItemNode(document, curLineIndex, curItemIndex));
|
||||||
@ -291,10 +291,10 @@ public class LevelSaveHelper {
|
|||||||
/**
|
/**
|
||||||
* Creates the grid line item node
|
* Creates the grid line item node
|
||||||
*
|
*
|
||||||
* @param document Document
|
* @param document Document
|
||||||
* @param curLineIndex Current line index
|
* @param curLineIndex Current line index
|
||||||
* @param curItemIndex Current line item index
|
* @param curItemIndex Current line item index
|
||||||
* @return Grid line item node
|
* @return Grid line item node
|
||||||
*/
|
*/
|
||||||
private Node gridLineItemNode(Document document, Integer curLineIndex, Integer curItemIndex) {
|
private Node gridLineItemNode(Document document, Integer curLineIndex, Integer curItemIndex) {
|
||||||
Element gridLineItemElement = document.createElement("item");
|
Element gridLineItemElement = document.createElement("item");
|
||||||
@ -308,10 +308,10 @@ public class LevelSaveHelper {
|
|||||||
/**
|
/**
|
||||||
* Creates the grid line sprite item node
|
* Creates the grid line sprite item node
|
||||||
*
|
*
|
||||||
* @param document Document
|
* @param document Document
|
||||||
* @param curLineIndex Current line index
|
* @param curLineIndex Current line index
|
||||||
* @param curItemIndex Current line item index
|
* @param curItemIndex Current line item index
|
||||||
* @return Grid line item sprite node
|
* @return Grid line item sprite node
|
||||||
*/
|
*/
|
||||||
private Node gridLineItemSpriteNode(Document document, Integer curLineIndex, Integer curItemIndex) {
|
private Node gridLineItemSpriteNode(Document document, Integer curLineIndex, Integer curItemIndex) {
|
||||||
String groupValue, nameValue, stateValue, convertibleValue;
|
String groupValue, nameValue, stateValue, convertibleValue;
|
||||||
@ -319,14 +319,14 @@ public class LevelSaveHelper {
|
|||||||
DisplayableElementModel curGridElement = this.getGroundGrid()[curItemIndex][curLineIndex];
|
DisplayableElementModel curGridElement = this.getGroundGrid()[curItemIndex][curLineIndex];
|
||||||
|
|
||||||
// Null?
|
// Null?
|
||||||
if(curGridElement == null) {
|
if (curGridElement == null) {
|
||||||
curGridElement = new DirtModel();
|
curGridElement = new DirtModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retrieve current values
|
// Retrieve current values
|
||||||
groupValue = curGridElement.getGroupName();
|
groupValue = curGridElement.getGroupName();
|
||||||
nameValue = curGridElement.getSpriteName();
|
nameValue = curGridElement.getSpriteName();
|
||||||
stateValue = curGridElement.getStateValue();
|
stateValue = curGridElement.getStateValue();
|
||||||
if (curGridElement.isConvertible()) {
|
if (curGridElement.isConvertible()) {
|
||||||
convertibleValue = "1";
|
convertibleValue = "1";
|
||||||
} else {
|
} else {
|
||||||
@ -341,7 +341,7 @@ public class LevelSaveHelper {
|
|||||||
gridLineItemSpriteElement.setAttribute("name", nameValue);
|
gridLineItemSpriteElement.setAttribute("name", nameValue);
|
||||||
gridLineItemSpriteElement.setAttribute("state", stateValue);
|
gridLineItemSpriteElement.setAttribute("state", stateValue);
|
||||||
|
|
||||||
if("1".equals(convertibleValue)) {
|
if ("1".equals(convertibleValue)) {
|
||||||
gridLineItemSpriteElement.setAttribute("convertible", convertibleValue);
|
gridLineItemSpriteElement.setAttribute("convertible", convertibleValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -351,10 +351,10 @@ public class LevelSaveHelper {
|
|||||||
/**
|
/**
|
||||||
* Creates a bare text node
|
* Creates a bare text node
|
||||||
*
|
*
|
||||||
* @param document Document
|
* @param document Document
|
||||||
* @param name Element name
|
* @param name Element name
|
||||||
* @param value Element value
|
* @param value Element value
|
||||||
* @return Text node
|
* @return Text node
|
||||||
*/
|
*/
|
||||||
private Node textNode(Document document, String name, String value) {
|
private Node textNode(Document document, String name, String value) {
|
||||||
Element node = document.createElement(name);
|
Element node = document.createElement(name);
|
||||||
@ -366,7 +366,7 @@ public class LevelSaveHelper {
|
|||||||
/**
|
/**
|
||||||
* Gets the level identifier
|
* Gets the level identifier
|
||||||
*
|
*
|
||||||
* @return Level identifier
|
* @return Level identifier
|
||||||
*/
|
*/
|
||||||
public String getLevelId() {
|
public String getLevelId() {
|
||||||
return this.levelId;
|
return this.levelId;
|
||||||
@ -375,7 +375,7 @@ public class LevelSaveHelper {
|
|||||||
/**
|
/**
|
||||||
* Sets the level identifier
|
* Sets the level identifier
|
||||||
*
|
*
|
||||||
* @param levelId Level identifier
|
* @param levelId Level identifier
|
||||||
*/
|
*/
|
||||||
private void setLevelId(String levelId) {
|
private void setLevelId(String levelId) {
|
||||||
this.levelId = levelId;
|
this.levelId = levelId;
|
||||||
@ -384,7 +384,7 @@ public class LevelSaveHelper {
|
|||||||
/**
|
/**
|
||||||
* Gets the ground grid
|
* Gets the ground grid
|
||||||
*
|
*
|
||||||
* @return Ground grid
|
* @return Ground grid
|
||||||
*/
|
*/
|
||||||
public DisplayableElementModel[][] getGroundGrid() {
|
public DisplayableElementModel[][] getGroundGrid() {
|
||||||
return this.groundGrid;
|
return this.groundGrid;
|
||||||
@ -393,7 +393,7 @@ public class LevelSaveHelper {
|
|||||||
/**
|
/**
|
||||||
* Sets the ground grid
|
* Sets the ground grid
|
||||||
*
|
*
|
||||||
* @param groundGrid Ground grid
|
* @param groundGrid Ground grid
|
||||||
*/
|
*/
|
||||||
private void setGroundGrid(DisplayableElementModel[][] groundGrid) {
|
private void setGroundGrid(DisplayableElementModel[][] groundGrid) {
|
||||||
this.groundGrid = groundGrid;
|
this.groundGrid = groundGrid;
|
||||||
|
@ -10,11 +10,11 @@ import java.util.List;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* LevelSelectorHelper
|
* LevelSelectorHelper
|
||||||
*
|
* <p>
|
||||||
* Level selector helper
|
* Level selector helper
|
||||||
*
|
*
|
||||||
* @author Valerian Saliou <valerian@valeriansaliou.name>
|
* @author Valerian Saliou <valerian@valeriansaliou.name>
|
||||||
* @since 2015-06-23
|
* @since 2015-06-23
|
||||||
*/
|
*/
|
||||||
public class LevelSelectorHelper {
|
public class LevelSelectorHelper {
|
||||||
private static String levelStorage = "./res/levels";
|
private static String levelStorage = "./res/levels";
|
||||||
@ -37,7 +37,7 @@ public class LevelSelectorHelper {
|
|||||||
/**
|
/**
|
||||||
* Creates the level list
|
* Creates the level list
|
||||||
*
|
*
|
||||||
* @return Level list selector
|
* @return Level list selector
|
||||||
*/
|
*/
|
||||||
public MenuLevelSelector createLevelList() {
|
public MenuLevelSelector createLevelList() {
|
||||||
String[] availableLevels = this.listAvailableLevels();
|
String[] availableLevels = this.listAvailableLevels();
|
||||||
@ -45,10 +45,11 @@ public class LevelSelectorHelper {
|
|||||||
// Proceed available levels listing
|
// Proceed available levels listing
|
||||||
MenuLevelSelector menuLevelList = new MenuLevelSelector(availableLevels, this.levelEditorView);
|
MenuLevelSelector menuLevelList = new MenuLevelSelector(availableLevels, this.levelEditorView);
|
||||||
|
|
||||||
if(availableLevels.length > 0) {
|
if (availableLevels.length > 0) {
|
||||||
menuLevelList.setChoiceValue(availableLevels[0]);
|
menuLevelList.setChoiceValue(availableLevels[0]);
|
||||||
menuLevelList.setSelectedIndex(0);
|
menuLevelList.setSelectedIndex(0);
|
||||||
};
|
}
|
||||||
|
;
|
||||||
|
|
||||||
menuLevelList.addActionListener(menuLevelList);
|
menuLevelList.addActionListener(menuLevelList);
|
||||||
|
|
||||||
@ -58,7 +59,7 @@ public class LevelSelectorHelper {
|
|||||||
/**
|
/**
|
||||||
* Lists available levels and store them in instance context
|
* Lists available levels and store them in instance context
|
||||||
*
|
*
|
||||||
* @return Available levels
|
* @return Available levels
|
||||||
*/
|
*/
|
||||||
private String[] listAvailableLevels() {
|
private String[] listAvailableLevels() {
|
||||||
List<String> stockList = new ArrayList<String>();
|
List<String> stockList = new ArrayList<String>();
|
||||||
@ -69,18 +70,18 @@ public class LevelSelectorHelper {
|
|||||||
int fileNameExtIndex;
|
int fileNameExtIndex;
|
||||||
|
|
||||||
// Add empty element?
|
// Add empty element?
|
||||||
if(this.hasEmptyElement) {
|
if (this.hasEmptyElement) {
|
||||||
stockList.add("");
|
stockList.add("");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (File file : fileList){
|
for (File file : fileList) {
|
||||||
fileName = file.getName();
|
fileName = file.getName();
|
||||||
fileNameExtIndex = fileName.lastIndexOf('.');
|
fileNameExtIndex = fileName.lastIndexOf('.');
|
||||||
|
|
||||||
if (fileNameExtIndex > 0) {
|
if (fileNameExtIndex > 0) {
|
||||||
fileNameExtValue = fileName.substring(fileNameExtIndex, fileName.length());
|
fileNameExtValue = fileName.substring(fileNameExtIndex, fileName.length());
|
||||||
|
|
||||||
if(fileNameExtValue.equals(".xml")) {
|
if (fileNameExtValue.equals(".xml")) {
|
||||||
fileName = fileName.substring(0, fileNameExtIndex);
|
fileName = fileName.substring(0, fileNameExtIndex);
|
||||||
stockList.add(fileName);
|
stockList.add(fileName);
|
||||||
}
|
}
|
||||||
|
@ -16,11 +16,11 @@ import fr.enssat.BoulderDash.models.SteelWallModel;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* ModelConvertHelper
|
* ModelConvertHelper
|
||||||
*
|
* <p>
|
||||||
* Provides model conversion services.
|
* Provides model conversion services.
|
||||||
*
|
*
|
||||||
* @author Valerian Saliou <valerian@valeriansaliou.name>
|
* @author Valerian Saliou <valerian@valeriansaliou.name>
|
||||||
* @since 2015-06-22
|
* @since 2015-06-22
|
||||||
*/
|
*/
|
||||||
public class ModelConvertHelper {
|
public class ModelConvertHelper {
|
||||||
/**
|
/**
|
||||||
@ -33,8 +33,8 @@ public class ModelConvertHelper {
|
|||||||
/**
|
/**
|
||||||
* Gets the model associated to the string
|
* Gets the model associated to the string
|
||||||
*
|
*
|
||||||
* @param spriteName Sprite name
|
* @param spriteName Sprite name
|
||||||
* @return Model associated to given sprite name
|
* @return Model associated to given sprite name
|
||||||
*/
|
*/
|
||||||
public DisplayableElementModel toModel(String spriteName, boolean isConvertible) throws UnknownModelException {
|
public DisplayableElementModel toModel(String spriteName, boolean isConvertible) throws UnknownModelException {
|
||||||
DisplayableElementModel element;
|
DisplayableElementModel element;
|
||||||
@ -96,7 +96,7 @@ public class ModelConvertHelper {
|
|||||||
/**
|
/**
|
||||||
* Gets the string associated to the model
|
* Gets the string associated to the model
|
||||||
*
|
*
|
||||||
* @return Model string name
|
* @return Model string name
|
||||||
*/
|
*/
|
||||||
public String toString(DisplayableElementModel model) {
|
public String toString(DisplayableElementModel model) {
|
||||||
return model.getSpriteName();
|
return model.getSpriteName();
|
||||||
|
@ -5,42 +5,42 @@ import fr.enssat.BoulderDash.models.DisplayableElementModel;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* BoulderModel
|
* BoulderModel
|
||||||
*
|
* <p>
|
||||||
* Represents the boulders.
|
* Represents the boulders.
|
||||||
*
|
*
|
||||||
* @author Colin Leverger <me@colinleverger.fr>
|
* @author Colin Leverger <me@colinleverger.fr>
|
||||||
* @since 2015-06-19
|
* @since 2015-06-19
|
||||||
*/
|
*/
|
||||||
public class BoulderModel extends DisplayableElementModel {
|
public class BoulderModel extends DisplayableElementModel {
|
||||||
private static String spriteName;
|
private static String spriteName;
|
||||||
private static boolean isDestructible;
|
private static boolean isDestructible;
|
||||||
private static boolean canMove;
|
private static boolean canMove;
|
||||||
private static boolean impactExplosive;
|
private static boolean impactExplosive;
|
||||||
private static boolean animate;
|
private static boolean animate;
|
||||||
private static int priority;
|
private static int priority;
|
||||||
private static String collideSound;
|
private static String collideSound;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Static dataset
|
* Static dataset
|
||||||
* Specifies the physical parameters of the object
|
* Specifies the physical parameters of the object
|
||||||
*/
|
*/
|
||||||
static {
|
static {
|
||||||
spriteName = "boulder";
|
spriteName = "boulder";
|
||||||
isDestructible = false;
|
isDestructible = false;
|
||||||
canMove = true;
|
canMove = true;
|
||||||
impactExplosive = false;
|
impactExplosive = false;
|
||||||
animate = true;
|
animate = true;
|
||||||
priority = 2;
|
priority = 2;
|
||||||
collideSound = "die";
|
collideSound = "die";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor
|
* Class constructor
|
||||||
*/
|
*/
|
||||||
public BoulderModel(boolean convertible) {
|
public BoulderModel(boolean convertible) {
|
||||||
super(isDestructible, canMove, spriteName, priority, impactExplosive, animate, false, collideSound, convertible);
|
super(isDestructible, canMove, spriteName, priority, impactExplosive, animate, false, collideSound, convertible);
|
||||||
this.loadSprite(spriteName);
|
this.loadSprite(spriteName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BoulderModel() {
|
public BoulderModel() {
|
||||||
this(false);
|
this(false);
|
||||||
|
@ -5,42 +5,42 @@ import fr.enssat.BoulderDash.models.DisplayableElementModel;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* BrickWallModel
|
* BrickWallModel
|
||||||
*
|
* <p>
|
||||||
* Represents the brick wall in the game.
|
* Represents the brick wall in the game.
|
||||||
*
|
*
|
||||||
* @author Colin Leverger <me@colinleverger.fr>
|
* @author Colin Leverger <me@colinleverger.fr>
|
||||||
* @since 2015-06-19
|
* @since 2015-06-19
|
||||||
*/
|
*/
|
||||||
public class BrickWallModel extends DisplayableElementModel {
|
public class BrickWallModel extends DisplayableElementModel {
|
||||||
private static String spriteName;
|
private static String spriteName;
|
||||||
private static boolean isDestructible;
|
private static boolean isDestructible;
|
||||||
private static boolean canMove;
|
private static boolean canMove;
|
||||||
private static boolean impactExplosive;
|
private static boolean impactExplosive;
|
||||||
private static boolean animate;
|
private static boolean animate;
|
||||||
private static int priority;
|
private static int priority;
|
||||||
private static boolean falling;
|
private static boolean falling;
|
||||||
private static String collideSound;
|
private static String collideSound;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Static dataset
|
* Static dataset
|
||||||
* Specifies the physical parameters of the object
|
* Specifies the physical parameters of the object
|
||||||
*/
|
*/
|
||||||
static {
|
static {
|
||||||
spriteName = "brickwall";
|
spriteName = "brickwall";
|
||||||
isDestructible = true;
|
isDestructible = true;
|
||||||
canMove = false;
|
canMove = false;
|
||||||
impactExplosive = false;
|
impactExplosive = false;
|
||||||
animate = false;
|
animate = false;
|
||||||
priority = 3;
|
priority = 3;
|
||||||
falling = false;
|
falling = false;
|
||||||
collideSound = "touch";
|
collideSound = "touch";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor
|
* Class constructor
|
||||||
*/
|
*/
|
||||||
public BrickWallModel() {
|
public BrickWallModel() {
|
||||||
super(isDestructible, canMove, spriteName, priority, impactExplosive, animate, falling, collideSound);
|
super(isDestructible, canMove, spriteName, priority, impactExplosive, animate, falling, collideSound);
|
||||||
this.loadSprite(spriteName);
|
this.loadSprite(spriteName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,11 +5,11 @@ import fr.enssat.BoulderDash.models.DisplayableElementModel;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* CursorModel
|
* CursorModel
|
||||||
*
|
* <p>
|
||||||
* Represents the field cursor pointer.
|
* Represents the field cursor pointer.
|
||||||
*
|
*
|
||||||
* @author Valerian Saliou <valerian@valeriansaliou.name>
|
* @author Valerian Saliou <valerian@valeriansaliou.name>
|
||||||
* @since 2015-06-22
|
* @since 2015-06-22
|
||||||
*/
|
*/
|
||||||
public class CursorModel extends DisplayableElementModel {
|
public class CursorModel extends DisplayableElementModel {
|
||||||
private static String spriteName;
|
private static String spriteName;
|
||||||
|
@ -8,83 +8,83 @@ import fr.enssat.BoulderDash.models.DisplayableElementModel;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* DiamondModel
|
* DiamondModel
|
||||||
*
|
* <p>
|
||||||
* Represents a diamond in the game.
|
* Represents a diamond in the game.
|
||||||
*
|
*
|
||||||
* @author Colin Leverger <me@colinleverger.fr>
|
* @author Colin Leverger <me@colinleverger.fr>
|
||||||
* @since 2015-06-19
|
* @since 2015-06-19
|
||||||
*/
|
*/
|
||||||
public class DiamondModel extends DisplayableElementModel {
|
public class DiamondModel extends DisplayableElementModel {
|
||||||
private static String spriteName;
|
private static String spriteName;
|
||||||
private static boolean isDestructible;
|
private static boolean isDestructible;
|
||||||
private static boolean canMove;
|
private static boolean canMove;
|
||||||
private static boolean impactExplosive;
|
private static boolean impactExplosive;
|
||||||
private static boolean animate;
|
private static boolean animate;
|
||||||
private static int priority;
|
private static int priority;
|
||||||
private static String collideSound;
|
private static String collideSound;
|
||||||
private long previousTime;
|
private long previousTime;
|
||||||
private int currentFrame;
|
private int currentFrame;
|
||||||
|
|
||||||
private final int SIZ_X_OF_SPRITE = 16;
|
private final int SIZ_X_OF_SPRITE = 16;
|
||||||
private final int SIZ_Y_OF_SPRITE = 16;
|
private final int SIZ_Y_OF_SPRITE = 16;
|
||||||
private long speed;
|
private long speed;
|
||||||
|
|
||||||
private ArrayList<BufferedImage> framesDiamond;
|
private ArrayList<BufferedImage> framesDiamond;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Static dataset
|
* Static dataset
|
||||||
* Specifies the physical parameters of the object
|
* Specifies the physical parameters of the object
|
||||||
*/
|
*/
|
||||||
static {
|
static {
|
||||||
spriteName = "diamond";
|
spriteName = "diamond";
|
||||||
isDestructible = true;
|
isDestructible = true;
|
||||||
canMove = true;
|
canMove = true;
|
||||||
impactExplosive = false;
|
impactExplosive = false;
|
||||||
animate = true;
|
animate = true;
|
||||||
priority = 0;
|
priority = 0;
|
||||||
collideSound = "coin";
|
collideSound = "coin";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor
|
* Class constructor
|
||||||
*/
|
*/
|
||||||
public DiamondModel() {
|
public DiamondModel() {
|
||||||
super(isDestructible, canMove, spriteName, priority, impactExplosive, animate, false, collideSound);
|
super(isDestructible, canMove, spriteName, priority, impactExplosive, animate, false, collideSound);
|
||||||
|
|
||||||
this.initSprites();
|
this.initSprites();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the sprite (animation loop)
|
* Updates the sprite (animation loop)
|
||||||
*
|
*
|
||||||
* @param time Current time
|
* @param time Current time
|
||||||
*/
|
*/
|
||||||
public void update(long time) {
|
public void update(long time) {
|
||||||
if (time - previousTime >= speed) {
|
if (time - previousTime >= speed) {
|
||||||
// Update the animation
|
// Update the animation
|
||||||
previousTime = time;
|
previousTime = time;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.currentFrame += 1;
|
this.currentFrame += 1;
|
||||||
this.setSprite(framesDiamond.get(this.currentFrame));
|
this.setSprite(framesDiamond.get(this.currentFrame));
|
||||||
} catch (IndexOutOfBoundsException e) {
|
} catch (IndexOutOfBoundsException e) {
|
||||||
this.currentFrame = 0;
|
this.currentFrame = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the sprites
|
* Initialize the sprites
|
||||||
* This is an animated element, hence this method
|
* This is an animated element, hence this method
|
||||||
*/
|
*/
|
||||||
private void initSprites() {
|
private void initSprites() {
|
||||||
/* Initialize object sprites */
|
/* Initialize object sprites */
|
||||||
this.framesDiamond = new ArrayList<BufferedImage>();
|
this.framesDiamond = new ArrayList<BufferedImage>();
|
||||||
|
|
||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
this.framesDiamond.add(
|
this.framesDiamond.add(
|
||||||
this.grabSprite(loadSprite(spriteName), i * 24, 0, SIZ_X_OF_SPRITE, SIZ_Y_OF_SPRITE)
|
this.grabSprite(loadSprite(spriteName), i * 24, 0, SIZ_X_OF_SPRITE, SIZ_Y_OF_SPRITE)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -5,43 +5,43 @@ import fr.enssat.BoulderDash.models.DisplayableElementModel;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* DirtModel
|
* DirtModel
|
||||||
*
|
* <p>
|
||||||
* Represents the dirt in the game.
|
* Represents the dirt in the game.
|
||||||
*
|
*
|
||||||
* @author Colin Leverger <me@colinleverger.fr>
|
* @author Colin Leverger <me@colinleverger.fr>
|
||||||
* @since 2015-06-19
|
* @since 2015-06-19
|
||||||
*/
|
*/
|
||||||
public class DirtModel extends DisplayableElementModel {
|
public class DirtModel extends DisplayableElementModel {
|
||||||
private static String spriteName;
|
private static String spriteName;
|
||||||
private static boolean isDestructible;
|
private static boolean isDestructible;
|
||||||
private static boolean canMove;
|
private static boolean canMove;
|
||||||
private static boolean impactExplosive;
|
private static boolean impactExplosive;
|
||||||
private static boolean animate;
|
private static boolean animate;
|
||||||
private static int priority;
|
private static int priority;
|
||||||
private static boolean falling;
|
private static boolean falling;
|
||||||
private static String collideSound;
|
private static String collideSound;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Static dataset
|
* Static dataset
|
||||||
* Specifies the physical parameters of the object
|
* Specifies the physical parameters of the object
|
||||||
*/
|
*/
|
||||||
static {
|
static {
|
||||||
spriteName = "dirt";
|
spriteName = "dirt";
|
||||||
isDestructible = true;
|
isDestructible = true;
|
||||||
canMove = false;
|
canMove = false;
|
||||||
impactExplosive = false;
|
impactExplosive = false;
|
||||||
animate = false;
|
animate = false;
|
||||||
priority = 0;
|
priority = 0;
|
||||||
falling = false;
|
falling = false;
|
||||||
collideSound = null;
|
collideSound = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor
|
* Class constructor
|
||||||
*/
|
*/
|
||||||
public DirtModel() {
|
public DirtModel() {
|
||||||
super(isDestructible, canMove, spriteName, priority, impactExplosive, animate, falling, collideSound);
|
super(isDestructible, canMove, spriteName, priority, impactExplosive, animate, falling, collideSound);
|
||||||
|
|
||||||
this.loadSprite(spriteName);
|
this.loadSprite(spriteName);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -8,59 +8,59 @@ import java.io.IOException;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* DisplayableElementModel
|
* DisplayableElementModel
|
||||||
*
|
* <p>
|
||||||
* Represents a abstract displayable element
|
* Represents a abstract displayable element
|
||||||
*
|
*
|
||||||
* @author Colin Leverger <me@colinleverger.fr>
|
* @author Colin Leverger <me@colinleverger.fr>
|
||||||
* @since 2015-06-19
|
* @since 2015-06-19
|
||||||
*/
|
*/
|
||||||
public abstract class DisplayableElementModel {
|
public abstract class DisplayableElementModel {
|
||||||
private static String spriteStorageFolderPath = "./res/drawable/field/";
|
private static String spriteStorageFolderPath = "./res/drawable/field/";
|
||||||
|
|
||||||
private static String groupName;
|
private static String groupName;
|
||||||
private static String stateValue;
|
private static String stateValue;
|
||||||
|
|
||||||
private boolean destructible;
|
private boolean destructible;
|
||||||
private boolean moving;
|
private boolean moving;
|
||||||
private boolean animate;
|
private boolean animate;
|
||||||
private boolean impactExplosive;
|
private boolean impactExplosive;
|
||||||
private String spriteName;
|
private String spriteName;
|
||||||
private int priority;
|
private int priority;
|
||||||
private BufferedImage sprite;
|
private BufferedImage sprite;
|
||||||
private boolean falling;
|
private boolean falling;
|
||||||
private boolean convertible;
|
private boolean convertible;
|
||||||
private String collideSound;
|
private String collideSound;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Static dataset
|
* Static dataset
|
||||||
*/
|
*/
|
||||||
static {
|
static {
|
||||||
groupName = "field";
|
groupName = "field";
|
||||||
stateValue = "initial";
|
stateValue = "initial";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor
|
* Class constructor
|
||||||
*
|
*
|
||||||
* @param destructible Object destructible?
|
* @param destructible Object destructible?
|
||||||
* @param moving Object is moving?
|
* @param moving Object is moving?
|
||||||
* @param spriteName Object sprite name?
|
* @param spriteName Object sprite name?
|
||||||
* @param priority Object priority?
|
* @param priority Object priority?
|
||||||
* @param impactExplosive Object explodes on impact?
|
* @param impactExplosive Object explodes on impact?
|
||||||
* @param animate Object can be animated?
|
* @param animate Object can be animated?
|
||||||
*/
|
*/
|
||||||
public DisplayableElementModel(boolean destructible, boolean moving, String spriteName, int priority, boolean impactExplosive, boolean animate, boolean falling, String collideSound, boolean convertible) {
|
public DisplayableElementModel(boolean destructible, boolean moving, String spriteName, int priority, boolean impactExplosive, boolean animate, boolean falling, String collideSound, boolean convertible) {
|
||||||
this.moving = moving;
|
this.moving = moving;
|
||||||
this.destructible = destructible;
|
this.destructible = destructible;
|
||||||
this.spriteName = spriteName;
|
this.spriteName = spriteName;
|
||||||
this.priority = priority;
|
this.priority = priority;
|
||||||
this.animate = animate;
|
this.animate = animate;
|
||||||
this.impactExplosive = impactExplosive;
|
this.impactExplosive = impactExplosive;
|
||||||
this.priority = priority;
|
this.priority = priority;
|
||||||
this.falling = falling;
|
this.falling = falling;
|
||||||
this.convertible = convertible;
|
this.convertible = convertible;
|
||||||
this.collideSound = collideSound;
|
this.collideSound = collideSound;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DisplayableElementModel(boolean destructible, boolean moving, String spriteName, int priority, boolean impactExplosive, boolean animate, boolean falling, String collideSound) {
|
public DisplayableElementModel(boolean destructible, boolean moving, String spriteName, int priority, boolean impactExplosive, boolean animate, boolean falling, String collideSound) {
|
||||||
this(
|
this(
|
||||||
@ -71,179 +71,179 @@ public abstract class DisplayableElementModel {
|
|||||||
/**
|
/**
|
||||||
* Gets the 'destructible' value
|
* Gets the 'destructible' value
|
||||||
*
|
*
|
||||||
* @return Whether object is destructible or not
|
* @return Whether object is destructible or not
|
||||||
*/
|
*/
|
||||||
public boolean isDestructible() {
|
public boolean isDestructible() {
|
||||||
return this.destructible;
|
return this.destructible;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the 'moving' value
|
* Gets the 'moving' value
|
||||||
*
|
*
|
||||||
* @return Whether object is moving or not
|
* @return Whether object is moving or not
|
||||||
*/
|
*/
|
||||||
public boolean isMoving() {
|
public boolean isMoving() {
|
||||||
return this.moving;
|
return this.moving;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the group name value
|
* Gets the group name value
|
||||||
*
|
|
||||||
* @return Group name value
|
|
||||||
*/
|
|
||||||
public String getGroupName() {
|
|
||||||
return this.groupName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the state value
|
|
||||||
*
|
|
||||||
* @return State value
|
|
||||||
*/
|
|
||||||
public String getStateValue() {
|
|
||||||
return this.stateValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the sprite name value
|
|
||||||
*
|
*
|
||||||
* @return Sprite name value
|
* @return Group name value
|
||||||
*/
|
*/
|
||||||
public String getSpriteName() {
|
public String getGroupName() {
|
||||||
return this.spriteName;
|
return this.groupName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the folder path of the sprite storage
|
* Gets the state value
|
||||||
*
|
*
|
||||||
* @return Folder path of the sprite storage
|
* @return State value
|
||||||
*/
|
*/
|
||||||
private static String getSpriteStorageFolderPath() {
|
public String getStateValue() {
|
||||||
return spriteStorageFolderPath;
|
return this.stateValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the path to the sprite file in storage
|
* Gets the sprite name value
|
||||||
*
|
*
|
||||||
* @return Path to the sprite file in storage
|
* @return Sprite name value
|
||||||
*/
|
*/
|
||||||
public String getPathToSprite() {
|
public String getSpriteName() {
|
||||||
return getSpriteStorageFolderPath() + getSpriteName() + ".gif";
|
return this.spriteName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the priority of the object
|
* Gets the folder path of the sprite storage
|
||||||
*
|
*
|
||||||
* @return Object priority
|
* @return Folder path of the sprite storage
|
||||||
*/
|
*/
|
||||||
public int getPriority() {
|
private static String getSpriteStorageFolderPath() {
|
||||||
return this.priority;
|
return spriteStorageFolderPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Gets the path to the sprite file in storage
|
||||||
|
*
|
||||||
|
* @return Path to the sprite file in storage
|
||||||
|
*/
|
||||||
|
public String getPathToSprite() {
|
||||||
|
return getSpriteStorageFolderPath() + getSpriteName() + ".gif";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the priority of the object
|
||||||
|
*
|
||||||
|
* @return Object priority
|
||||||
|
*/
|
||||||
|
public int getPriority() {
|
||||||
|
return this.priority;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
* Sets the priority of the object
|
* Sets the priority of the object
|
||||||
*
|
*
|
||||||
* @param priority Object priority
|
* @param priority Object priority
|
||||||
*/
|
*/
|
||||||
public void setPriority(int priority) {
|
public void setPriority(int priority) {
|
||||||
this.priority = priority;
|
this.priority = priority;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the 'animate' value
|
* Gets the 'animate' value
|
||||||
*
|
*
|
||||||
* @return Whether object is animated or not
|
* @return Whether object is animated or not
|
||||||
*/
|
*/
|
||||||
public boolean isAnimate() {
|
public boolean isAnimate() {
|
||||||
return this.animate;
|
return this.animate;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the 'animate' value
|
* Sets the 'animate' value
|
||||||
*
|
*
|
||||||
* @return animate Whether object is animated or not
|
* @return animate Whether object is animated or not
|
||||||
*/
|
*/
|
||||||
public void setAnimate(boolean animate) {
|
public void setAnimate(boolean animate) {
|
||||||
this.animate = animate;
|
this.animate = animate;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the 'impact explosive' value
|
* Gets the 'impact explosive' value
|
||||||
*
|
*
|
||||||
* @return Whether object explodes on impact or not
|
* @return Whether object explodes on impact or not
|
||||||
*/
|
*/
|
||||||
public boolean isImpactExplosive() {
|
public boolean isImpactExplosive() {
|
||||||
return this.impactExplosive;
|
return this.impactExplosive;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the 'impact explosive' value
|
* Sets the 'impact explosive' value
|
||||||
*
|
*
|
||||||
* @return impactExplosive Whether object explodes on impact or not
|
* @return impactExplosive Whether object explodes on impact or not
|
||||||
*/
|
*/
|
||||||
public void setImpactExplosive(boolean impactExplosive) {
|
public void setImpactExplosive(boolean impactExplosive) {
|
||||||
this.impactExplosive = impactExplosive;
|
this.impactExplosive = impactExplosive;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the sprite
|
* Sets the sprite
|
||||||
*
|
*
|
||||||
* @param sprite Sprite object
|
* @param sprite Sprite object
|
||||||
*/
|
*/
|
||||||
public void setSprite(BufferedImage sprite) {
|
public void setSprite(BufferedImage sprite) {
|
||||||
this.sprite = sprite;
|
this.sprite = sprite;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the sprite
|
* Gets the sprite
|
||||||
*
|
*
|
||||||
* @return Sprite object
|
* @return Sprite object
|
||||||
*/
|
*/
|
||||||
public BufferedImage getSprite() {
|
public BufferedImage getSprite() {
|
||||||
return sprite;
|
return sprite;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads the target sprite
|
* Loads the target sprite
|
||||||
*
|
*
|
||||||
* @param spriteName Sprite name
|
* @param spriteName Sprite name
|
||||||
* @return Sprite object
|
* @return Sprite object
|
||||||
*/
|
*/
|
||||||
public BufferedImage loadSprite(String spriteName) {
|
public BufferedImage loadSprite(String spriteName) {
|
||||||
BufferedImage sprite = null;
|
BufferedImage sprite = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
sprite = ImageIO.read(new File("res/drawable/field/" + spriteName + ".gif"));
|
sprite = ImageIO.read(new File("res/drawable/field/" + spriteName + ".gif"));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.sprite = sprite;
|
this.sprite = sprite;
|
||||||
|
|
||||||
return sprite;
|
return sprite;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Grabs the sprite from the large image containing all the static sprites items
|
* Grabs the sprite from the large image containing all the static sprites items
|
||||||
*
|
*
|
||||||
* @param spriteSheet Sprite sheet instance
|
* @param spriteSheet Sprite sheet instance
|
||||||
* @param x Sub image horizontal offset on sprite sheet
|
* @param x Sub image horizontal offset on sprite sheet
|
||||||
* @param y Sub image vertical offset on sprite sheet
|
* @param y Sub image vertical offset on sprite sheet
|
||||||
* @param width Sub image width on sprite sheet
|
* @param width Sub image width on sprite sheet
|
||||||
* @param height Sub image height on sprite sheet
|
* @param height Sub image height on sprite sheet
|
||||||
* @return Target sub image
|
* @return Target sub image
|
||||||
*/
|
*/
|
||||||
public BufferedImage grabSprite(BufferedImage spriteSheet, int x, int y, int width, int height) {
|
public BufferedImage grabSprite(BufferedImage spriteSheet, int x, int y, int width, int height) {
|
||||||
BufferedImage subImage = spriteSheet.getSubimage(x, y, width, height);
|
BufferedImage subImage = spriteSheet.getSubimage(x, y, width, height);
|
||||||
|
|
||||||
this.sprite = subImage;
|
this.sprite = subImage;
|
||||||
return subImage;
|
return subImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the falling state of the object
|
* Gets the falling state of the object
|
||||||
*
|
*
|
||||||
* @return Whether object is falling or not
|
* @return Whether object is falling or not
|
||||||
*/
|
*/
|
||||||
public boolean isFalling() {
|
public boolean isFalling() {
|
||||||
return this.falling;
|
return this.falling;
|
||||||
@ -252,7 +252,7 @@ public abstract class DisplayableElementModel {
|
|||||||
/**
|
/**
|
||||||
* Sets the falling state of the object
|
* Sets the falling state of the object
|
||||||
*
|
*
|
||||||
* @param falling Whether object is falling or not
|
* @param falling Whether object is falling or not
|
||||||
*/
|
*/
|
||||||
public void setFalling(boolean falling) {
|
public void setFalling(boolean falling) {
|
||||||
this.falling = falling;
|
this.falling = falling;
|
||||||
@ -261,7 +261,7 @@ public abstract class DisplayableElementModel {
|
|||||||
/**
|
/**
|
||||||
* Gets the collide sound of the object
|
* Gets the collide sound of the object
|
||||||
*
|
*
|
||||||
* @return Collide sound
|
* @return Collide sound
|
||||||
*/
|
*/
|
||||||
public String getCollideSound() {
|
public String getCollideSound() {
|
||||||
return this.collideSound;
|
return this.collideSound;
|
||||||
@ -270,7 +270,7 @@ public abstract class DisplayableElementModel {
|
|||||||
/**
|
/**
|
||||||
* Sets the collide sound of the object
|
* Sets the collide sound of the object
|
||||||
*
|
*
|
||||||
* @param collideSound Collide sound
|
* @param collideSound Collide sound
|
||||||
*/
|
*/
|
||||||
public void setCollideSound(String collideSound) {
|
public void setCollideSound(String collideSound) {
|
||||||
this.collideSound = collideSound;
|
this.collideSound = collideSound;
|
||||||
@ -279,7 +279,7 @@ public abstract class DisplayableElementModel {
|
|||||||
/**
|
/**
|
||||||
* Gets the convertible value of the object
|
* Gets the convertible value of the object
|
||||||
*
|
*
|
||||||
* @return Convertible value
|
* @return Convertible value
|
||||||
*/
|
*/
|
||||||
public boolean isConvertible() {
|
public boolean isConvertible() {
|
||||||
return this.convertible;
|
return this.convertible;
|
||||||
@ -288,15 +288,17 @@ public abstract class DisplayableElementModel {
|
|||||||
/**
|
/**
|
||||||
* Sets the convertible value of the object
|
* Sets the convertible value of the object
|
||||||
*
|
*
|
||||||
* @param convertible Convertible value
|
* @param convertible Convertible value
|
||||||
*/
|
*/
|
||||||
public void setConvertibleValue(boolean convertible) {
|
public void setConvertibleValue(boolean convertible) {
|
||||||
this.convertible = convertible;
|
this.convertible = convertible;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to update the sprites
|
* Function to update the sprites
|
||||||
* @param currentTimeMillis Current time in milliseconds
|
*
|
||||||
*/
|
* @param currentTimeMillis Current time in milliseconds
|
||||||
public void update(long currentTimeMillis) {}
|
*/
|
||||||
|
public void update(long currentTimeMillis) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,43 +5,43 @@ import fr.enssat.BoulderDash.models.DisplayableElementModel;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* DoorModel
|
* DoorModel
|
||||||
*
|
* <p>
|
||||||
* Represents escape door.
|
* Represents escape door.
|
||||||
*
|
*
|
||||||
* @author Colin Leverger <me@colinleverger.fr>
|
* @author Colin Leverger <me@colinleverger.fr>
|
||||||
* @since 2015-06-19
|
* @since 2015-06-19
|
||||||
*/
|
*/
|
||||||
public class DoorModel extends DisplayableElementModel {
|
public class DoorModel extends DisplayableElementModel {
|
||||||
private static String spriteName;
|
private static String spriteName;
|
||||||
private static boolean isDestructible;
|
private static boolean isDestructible;
|
||||||
private static boolean canMove;
|
private static boolean canMove;
|
||||||
private static boolean impactExplosive;
|
private static boolean impactExplosive;
|
||||||
private static boolean animate;
|
private static boolean animate;
|
||||||
private static int priority;
|
private static int priority;
|
||||||
private static boolean falling;
|
private static boolean falling;
|
||||||
private static String collideSound;
|
private static String collideSound;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Static dataset
|
* Static dataset
|
||||||
* Specifies the physical parameters of the object
|
* Specifies the physical parameters of the object
|
||||||
*/
|
*/
|
||||||
static {
|
static {
|
||||||
spriteName = "door";
|
spriteName = "door";
|
||||||
isDestructible = false;
|
isDestructible = false;
|
||||||
canMove = false;
|
canMove = false;
|
||||||
impactExplosive = false;
|
impactExplosive = false;
|
||||||
animate = false;
|
animate = false;
|
||||||
priority = 0;
|
priority = 0;
|
||||||
falling = false;
|
falling = false;
|
||||||
collideSound = null;
|
collideSound = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor
|
* Class constructor
|
||||||
*/
|
*/
|
||||||
public DoorModel() {
|
public DoorModel() {
|
||||||
super(isDestructible, canMove, spriteName, priority, impactExplosive, animate, falling, collideSound);
|
super(isDestructible, canMove, spriteName, priority, impactExplosive, animate, falling, collideSound);
|
||||||
|
|
||||||
this.loadSprite(spriteName);
|
this.loadSprite(spriteName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,43 +5,43 @@ import fr.enssat.BoulderDash.models.DisplayableElementModel;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* EmptyModel
|
* EmptyModel
|
||||||
*
|
* <p>
|
||||||
* Represents "nothing".
|
* Represents "nothing".
|
||||||
*
|
*
|
||||||
* @author Colin Leverger <me@colinleverger.fr>
|
* @author Colin Leverger <me@colinleverger.fr>
|
||||||
* @since 2015-06-19
|
* @since 2015-06-19
|
||||||
*/
|
*/
|
||||||
public class EmptyModel extends DisplayableElementModel {
|
public class EmptyModel extends DisplayableElementModel {
|
||||||
private static String spriteName;
|
private static String spriteName;
|
||||||
private static boolean isDestructible;
|
private static boolean isDestructible;
|
||||||
private static boolean canMove;
|
private static boolean canMove;
|
||||||
private static boolean impactExplosive;
|
private static boolean impactExplosive;
|
||||||
private static boolean animate;
|
private static boolean animate;
|
||||||
private static int priority;
|
private static int priority;
|
||||||
private static boolean falling;
|
private static boolean falling;
|
||||||
private static String collideSound;
|
private static String collideSound;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Static dataset
|
* Static dataset
|
||||||
* Specifies the physical parameters of the object
|
* Specifies the physical parameters of the object
|
||||||
*/
|
*/
|
||||||
static {
|
static {
|
||||||
spriteName = "black";
|
spriteName = "black";
|
||||||
isDestructible = false;
|
isDestructible = false;
|
||||||
canMove = false;
|
canMove = false;
|
||||||
impactExplosive = false;
|
impactExplosive = false;
|
||||||
animate = false;
|
animate = false;
|
||||||
priority = 0;
|
priority = 0;
|
||||||
falling = false;
|
falling = false;
|
||||||
collideSound = null;
|
collideSound = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor
|
* Class constructor
|
||||||
*/
|
*/
|
||||||
public EmptyModel() {
|
public EmptyModel() {
|
||||||
super(isDestructible, canMove, spriteName, priority, impactExplosive, animate, falling, collideSound);
|
super(isDestructible, canMove, spriteName, priority, impactExplosive, animate, falling, collideSound);
|
||||||
|
|
||||||
this.loadSprite(spriteName);
|
this.loadSprite(spriteName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,42 +5,42 @@ import fr.enssat.BoulderDash.models.DisplayableElementModel;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* ExpandingWallModel
|
* ExpandingWallModel
|
||||||
*
|
* <p>
|
||||||
* Represents a ExpandingWall in the game.
|
* Represents a ExpandingWall in the game.
|
||||||
*
|
*
|
||||||
* @author Colin Leverger <me@colinleverger.fr>
|
* @author Colin Leverger <me@colinleverger.fr>
|
||||||
* @since 2015-06-19
|
* @since 2015-06-19
|
||||||
*/
|
*/
|
||||||
public class ExpandingWallModel extends DisplayableElementModel {
|
public class ExpandingWallModel extends DisplayableElementModel {
|
||||||
private static String spriteName;
|
private static String spriteName;
|
||||||
private static boolean destructible;
|
private static boolean destructible;
|
||||||
private static boolean canMove;
|
private static boolean canMove;
|
||||||
private static boolean impactExplosive;
|
private static boolean impactExplosive;
|
||||||
private static boolean animate;
|
private static boolean animate;
|
||||||
private static int priority;
|
private static int priority;
|
||||||
private static boolean falling;
|
private static boolean falling;
|
||||||
private static String collideSound;
|
private static String collideSound;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Static dataset
|
* Static dataset
|
||||||
* Specifies the physical parameters of the object
|
* Specifies the physical parameters of the object
|
||||||
*/
|
*/
|
||||||
static {
|
static {
|
||||||
spriteName = "expandingwall";
|
spriteName = "expandingwall";
|
||||||
destructible = false;
|
destructible = false;
|
||||||
canMove = false;
|
canMove = false;
|
||||||
impactExplosive = false;
|
impactExplosive = false;
|
||||||
animate = false;
|
animate = false;
|
||||||
priority = 10;
|
priority = 10;
|
||||||
falling = false;
|
falling = false;
|
||||||
collideSound = null;
|
collideSound = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor
|
* Class constructor
|
||||||
*/
|
*/
|
||||||
public ExpandingWallModel() {
|
public ExpandingWallModel() {
|
||||||
super(destructible, canMove, spriteName, priority, impactExplosive, animate, falling, collideSound);
|
super(destructible, canMove, spriteName, priority, impactExplosive, animate, falling, collideSound);
|
||||||
this.loadSprite(spriteName);
|
this.loadSprite(spriteName);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -6,109 +6,108 @@ import java.util.Observable;
|
|||||||
/**
|
/**
|
||||||
* GameInformationModel will contain all the data which will
|
* GameInformationModel will contain all the data which will
|
||||||
* go to the InformationPanel.
|
* go to the InformationPanel.
|
||||||
*
|
*
|
||||||
* @author Colin Leverger <me@colinleverger.fr>
|
* @author Colin Leverger <me@colinleverger.fr>
|
||||||
* @since 2015-06-19
|
* @since 2015-06-19
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class GameInformationModel extends Observable {
|
public class GameInformationModel extends Observable {
|
||||||
private int score;
|
private int score;
|
||||||
private int remainingsDiamonds;
|
private int remainingsDiamonds;
|
||||||
private int timer;
|
private int timer;
|
||||||
|
|
||||||
public GameInformationModel(int remainingsDiamonds) {
|
public GameInformationModel(int remainingsDiamonds) {
|
||||||
this.score = 0;
|
this.score = 0;
|
||||||
this.remainingsDiamonds = remainingsDiamonds;
|
this.remainingsDiamonds = remainingsDiamonds;
|
||||||
this.timer = 0;
|
this.timer = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the actual score
|
* Returns the actual score
|
||||||
*
|
*
|
||||||
* @return score
|
* @return score
|
||||||
*/
|
*/
|
||||||
public int getScore() {
|
public int getScore() {
|
||||||
return score;
|
return score;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the score
|
* Sets the score
|
||||||
*
|
*
|
||||||
* @param score Score
|
* @param score Score
|
||||||
*/
|
*/
|
||||||
public void setScore(int score) {
|
public void setScore(int score) {
|
||||||
this.score = score;
|
this.score = score;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the actual number of remaining diamonds
|
* Returns the actual number of remaining diamonds
|
||||||
*
|
*
|
||||||
* @return Remaining diamonds
|
* @return Remaining diamonds
|
||||||
*/
|
*/
|
||||||
public int getRemainingsDiamonds() {
|
public int getRemainingsDiamonds() {
|
||||||
return remainingsDiamonds;
|
return remainingsDiamonds;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the number of remainingDiamonds
|
* Sets the number of remainingDiamonds
|
||||||
*
|
*
|
||||||
* @param remainingDiamonds Remaining diamonds
|
* @param remainingDiamonds Remaining diamonds
|
||||||
*/
|
*/
|
||||||
public void setRemainingsDiamonds(int remainingDiamonds) {
|
public void setRemainingsDiamonds(int remainingDiamonds) {
|
||||||
this.remainingsDiamonds = remainingDiamonds;
|
this.remainingsDiamonds = remainingDiamonds;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the timer
|
* Gets the timer
|
||||||
*
|
*
|
||||||
* @return Timer
|
* @return Timer
|
||||||
*/
|
*/
|
||||||
public int getTimer() {
|
public int getTimer() {
|
||||||
return timer;
|
return timer;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the timer
|
* Sets the timer
|
||||||
*
|
*
|
||||||
* @param timer Timer
|
* @param timer Timer
|
||||||
*/
|
*/
|
||||||
public void setTimer(int timer) {
|
public void setTimer(int timer) {
|
||||||
this.timer = timer;
|
this.timer = timer;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Increments the score & notify observers
|
* Increments the score & notify observers
|
||||||
*/
|
*/
|
||||||
public void incrementScore() {
|
public void incrementScore() {
|
||||||
this.score += 1;
|
this.score += 1;
|
||||||
this.myNotify();
|
this.myNotify();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Generic function which will notify the observers.
|
|
||||||
*/
|
|
||||||
private void myNotify() {
|
|
||||||
this.notifyObservers();
|
|
||||||
this.setChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decrement of one the number total of remaining diamonds.
|
* Generic function which will notify the observers.
|
||||||
*/
|
*/
|
||||||
public void decrementRemainingsDiamonds() {
|
private void myNotify() {
|
||||||
if(remainingsDiamonds > 0){
|
this.notifyObservers();
|
||||||
this.remainingsDiamonds -= 1;
|
this.setChanged();
|
||||||
this.myNotify();
|
}
|
||||||
}
|
|
||||||
}
|
/**
|
||||||
|
* Decrement of one the number total of remaining diamonds.
|
||||||
|
*/
|
||||||
|
public void decrementRemainingsDiamonds() {
|
||||||
|
if (remainingsDiamonds > 0) {
|
||||||
|
this.remainingsDiamonds -= 1;
|
||||||
|
this.myNotify();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reset details about object
|
* Reset details about object
|
||||||
*/
|
*/
|
||||||
public void resetInformations() {
|
public void resetInformations() {
|
||||||
this.score = 0;
|
this.score = 0;
|
||||||
this.remainingsDiamonds = remainingsDiamonds;
|
this.remainingsDiamonds = remainingsDiamonds;
|
||||||
this.timer = 0;
|
this.timer = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -8,84 +8,84 @@ import fr.enssat.BoulderDash.models.DisplayableElementModel;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* MagicWallModel
|
* MagicWallModel
|
||||||
*
|
* <p>
|
||||||
* Represents the magic wall.
|
* Represents the magic wall.
|
||||||
*
|
*
|
||||||
* @author Colin Leverger <me@colinleverger.fr>
|
* @author Colin Leverger <me@colinleverger.fr>
|
||||||
* @since 2015-06-19
|
* @since 2015-06-19
|
||||||
*/
|
*/
|
||||||
public class MagicWallModel extends DisplayableElementModel {
|
public class MagicWallModel extends DisplayableElementModel {
|
||||||
private static String spriteName;
|
private static String spriteName;
|
||||||
private static boolean isDestructible;
|
private static boolean isDestructible;
|
||||||
private static boolean canMove;
|
private static boolean canMove;
|
||||||
private static boolean impactExplosive;
|
private static boolean impactExplosive;
|
||||||
private static boolean animate;
|
private static boolean animate;
|
||||||
private static int priority;
|
private static int priority;
|
||||||
private static boolean falling;
|
private static boolean falling;
|
||||||
private static String collideSound;
|
private static String collideSound;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores the frames
|
* Stores the frames
|
||||||
* Used for the sprites
|
* Used for the sprites
|
||||||
*/
|
*/
|
||||||
private ArrayList<BufferedImage> framesMagicWall;
|
private ArrayList<BufferedImage> framesMagicWall;
|
||||||
|
|
||||||
private long previousTime;
|
private long previousTime;
|
||||||
private int currentFrame;
|
private int currentFrame;
|
||||||
private long speed;
|
private long speed;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Static dataset
|
* Static dataset
|
||||||
* Specifies the physical parameters of the object
|
* Specifies the physical parameters of the object
|
||||||
*/
|
*/
|
||||||
static {
|
static {
|
||||||
spriteName = "magicwall";
|
spriteName = "magicwall";
|
||||||
isDestructible = false;
|
isDestructible = false;
|
||||||
canMove = false;
|
canMove = false;
|
||||||
impactExplosive = false;
|
impactExplosive = false;
|
||||||
animate = false;
|
animate = false;
|
||||||
priority = 3;
|
priority = 3;
|
||||||
falling = false;
|
falling = false;
|
||||||
collideSound = "touch";
|
collideSound = "touch";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor
|
* Class constructor
|
||||||
*/
|
*/
|
||||||
public MagicWallModel() {
|
public MagicWallModel() {
|
||||||
super(isDestructible, canMove, spriteName, priority, impactExplosive, animate, falling, collideSound);
|
super(isDestructible, canMove, spriteName, priority, impactExplosive, animate, falling, collideSound);
|
||||||
this.currentFrame = 0;
|
this.currentFrame = 0;
|
||||||
this.speed = 100;
|
this.speed = 100;
|
||||||
this.initSprites();
|
this.initSprites();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to animate the sprite
|
* Function to animate the sprite
|
||||||
*/
|
*/
|
||||||
public void update(long time) {
|
public void update(long time) {
|
||||||
if (time - previousTime >= speed) {
|
if (time - previousTime >= speed) {
|
||||||
// Update animation
|
// Update animation
|
||||||
previousTime = time;
|
previousTime = time;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
currentFrame += 1;
|
currentFrame += 1;
|
||||||
|
|
||||||
this.setSprite(framesMagicWall.get(this.currentFrame));
|
this.setSprite(framesMagicWall.get(this.currentFrame));
|
||||||
} catch (IndexOutOfBoundsException e) {
|
} catch (IndexOutOfBoundsException e) {
|
||||||
currentFrame = 0;
|
currentFrame = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Init the subimages
|
* Init the subimages
|
||||||
*/
|
*/
|
||||||
private void initSprites() {
|
private void initSprites() {
|
||||||
this.framesMagicWall = new ArrayList<BufferedImage>();
|
this.framesMagicWall = new ArrayList<BufferedImage>();
|
||||||
/* INIT SPRITE FOR DIAMOND */
|
/* INIT SPRITE FOR DIAMOND */
|
||||||
framesMagicWall.add(grabSprite(loadSprite(spriteName), 0, 0, 16, 16));
|
framesMagicWall.add(grabSprite(loadSprite(spriteName), 0, 0, 16, 16));
|
||||||
framesMagicWall.add(grabSprite(loadSprite(spriteName), 24, 0, 16, 16));
|
framesMagicWall.add(grabSprite(loadSprite(spriteName), 24, 0, 16, 16));
|
||||||
framesMagicWall.add(grabSprite(loadSprite(spriteName), 48, 0, 16, 16));
|
framesMagicWall.add(grabSprite(loadSprite(spriteName), 48, 0, 16, 16));
|
||||||
framesMagicWall.add(grabSprite(loadSprite(spriteName), 72, 0, 16, 16));
|
framesMagicWall.add(grabSprite(loadSprite(spriteName), 72, 0, 16, 16));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,182 +8,182 @@ import fr.enssat.BoulderDash.models.DisplayableElementModel;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* RockfordModel
|
* RockfordModel
|
||||||
*
|
* <p>
|
||||||
* Represents the hero of the game.
|
* Represents the hero of the game.
|
||||||
*
|
*
|
||||||
* @author Colin Leverger <me@colinleverger.fr>
|
* @author Colin Leverger <me@colinleverger.fr>
|
||||||
* @since 2015-06-19
|
* @since 2015-06-19
|
||||||
*/
|
*/
|
||||||
public class RockfordModel extends DisplayableElementModel {
|
public class RockfordModel extends DisplayableElementModel {
|
||||||
private static String spriteName;
|
private static String spriteName;
|
||||||
private static boolean isDestructible;
|
private static boolean isDestructible;
|
||||||
private static boolean canMove;
|
private static boolean canMove;
|
||||||
private static boolean impactExplosive;
|
private static boolean impactExplosive;
|
||||||
private static boolean animate;
|
private static boolean animate;
|
||||||
private static int priority;
|
private static int priority;
|
||||||
private static boolean falling;
|
private static boolean falling;
|
||||||
private static String collideSound;
|
private static String collideSound;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maps the sub images of the sprite file
|
* Maps the sub images of the sprite file
|
||||||
*/
|
*/
|
||||||
private static ArrayList<BufferedImage> framesBlinking;
|
private static ArrayList<BufferedImage> framesBlinking;
|
||||||
private static ArrayList<BufferedImage> framesRunningLeft;
|
private static ArrayList<BufferedImage> framesRunningLeft;
|
||||||
private static ArrayList<BufferedImage> framesRunningRight;
|
private static ArrayList<BufferedImage> framesRunningRight;
|
||||||
private static ArrayList<BufferedImage> framesRunningUpOrDown;
|
private static ArrayList<BufferedImage> framesRunningUpOrDown;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines the size of the sprite
|
* Defines the size of the sprite
|
||||||
*/
|
*/
|
||||||
private final int SIZ_X_OF_SPRITE = 16;
|
private final int SIZ_X_OF_SPRITE = 16;
|
||||||
private final int SIZ_Y_OF_SPRITE = 16;
|
private final int SIZ_Y_OF_SPRITE = 16;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines the current speed of the object
|
* Defines the current speed of the object
|
||||||
*/
|
*/
|
||||||
private long speed;
|
private long speed;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maps possible states for Rockford
|
* Maps possible states for Rockford
|
||||||
*/
|
*/
|
||||||
private boolean isCollisionDone = false;
|
private boolean isCollisionDone = false;
|
||||||
private boolean isStaying = true;
|
private boolean isStaying = true;
|
||||||
private boolean isRunningLeft = false;
|
private boolean isRunningLeft = false;
|
||||||
private boolean isRunningRight = false;
|
private boolean isRunningRight = false;
|
||||||
private boolean isRunningUp = false;
|
private boolean isRunningUp = false;
|
||||||
private boolean isRunningDown = false;
|
private boolean isRunningDown = false;
|
||||||
|
|
||||||
private long previousTime;
|
private long previousTime;
|
||||||
private int currentFrame;
|
private int currentFrame;
|
||||||
private boolean hasExploded;
|
private boolean hasExploded;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Static dataset
|
* Static dataset
|
||||||
* Specifies the physical parameters of the object
|
* Specifies the physical parameters of the object
|
||||||
*/
|
*/
|
||||||
static {
|
static {
|
||||||
spriteName = "rockford";
|
spriteName = "rockford";
|
||||||
isDestructible = true;
|
isDestructible = true;
|
||||||
canMove = true;
|
canMove = true;
|
||||||
impactExplosive = true;
|
impactExplosive = true;
|
||||||
animate = true;
|
animate = true;
|
||||||
priority = 1;
|
priority = 1;
|
||||||
falling = false;
|
falling = false;
|
||||||
collideSound = null;
|
collideSound = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor
|
* Class constructor
|
||||||
*/
|
*/
|
||||||
public RockfordModel() {
|
public RockfordModel() {
|
||||||
super(isDestructible, canMove, spriteName, priority, impactExplosive, animate, falling, collideSound);
|
super(isDestructible, canMove, spriteName, priority, impactExplosive, animate, falling, collideSound);
|
||||||
// Speed of the animation of the sprite
|
// Speed of the animation of the sprite
|
||||||
this.setSpeed(100);
|
this.setSpeed(100);
|
||||||
// Init the sprites in arrays
|
// Init the sprites in arrays
|
||||||
this.initSprites();
|
this.initSprites();
|
||||||
this.hasExploded = false;
|
this.hasExploded = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSpeed(int speed) {
|
public void setSpeed(int speed) {
|
||||||
this.speed = speed;
|
this.speed = speed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the sprite animation
|
* Updates the sprite animation
|
||||||
* (And only that single thing)
|
* (And only that single thing)
|
||||||
*/
|
*/
|
||||||
public void update(long time) {
|
public void update(long time) {
|
||||||
if (time - this.previousTime >= this.speed) {
|
if (time - this.previousTime >= this.speed) {
|
||||||
// Update the animation
|
// Update the animation
|
||||||
this.previousTime = time;
|
this.previousTime = time;
|
||||||
try {
|
try {
|
||||||
currentFrame += 1;
|
currentFrame += 1;
|
||||||
|
|
||||||
if (isStaying()) {
|
if (isStaying()) {
|
||||||
this.setSprite(framesBlinking.get(currentFrame));
|
this.setSprite(framesBlinking.get(currentFrame));
|
||||||
} else if (isRunningLeft()) {
|
} else if (isRunningLeft()) {
|
||||||
this.setSprite(framesRunningLeft.get(currentFrame));
|
this.setSprite(framesRunningLeft.get(currentFrame));
|
||||||
} else if (isRunningRight()) {
|
} else if (isRunningRight()) {
|
||||||
this.setSprite(framesRunningRight.get(currentFrame));
|
this.setSprite(framesRunningRight.get(currentFrame));
|
||||||
} else if (isRunningUpOrDown()) {
|
} else if (isRunningUpOrDown()) {
|
||||||
this.setSprite(framesRunningUpOrDown.get(currentFrame));
|
this.setSprite(framesRunningUpOrDown.get(currentFrame));
|
||||||
}
|
}
|
||||||
} catch (IndexOutOfBoundsException e) {
|
} catch (IndexOutOfBoundsException e) {
|
||||||
this.currentFrame = 0;
|
this.currentFrame = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stops the Rockford movement
|
* Stops the Rockford movement
|
||||||
*/
|
*/
|
||||||
public void startStaying() {
|
public void startStaying() {
|
||||||
isCollisionDone = false;
|
isCollisionDone = false;
|
||||||
isStaying = true;
|
isStaying = true;
|
||||||
isRunningLeft = false;
|
isRunningLeft = false;
|
||||||
isRunningRight = false;
|
isRunningRight = false;
|
||||||
isRunningUp = false;
|
isRunningUp = false;
|
||||||
isRunningDown = false;
|
isRunningDown = false;
|
||||||
previousTime = 0;
|
previousTime = 0;
|
||||||
currentFrame = 0;
|
currentFrame = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts moving Rockford to the left
|
* Starts moving Rockford to the left
|
||||||
*/
|
*/
|
||||||
public void startRunningLeft() {
|
public void startRunningLeft() {
|
||||||
isCollisionDone = false;
|
isCollisionDone = false;
|
||||||
isStaying = false;
|
isStaying = false;
|
||||||
isRunningLeft = true;
|
isRunningLeft = true;
|
||||||
isRunningRight = false;
|
isRunningRight = false;
|
||||||
isRunningUp = false;
|
isRunningUp = false;
|
||||||
isRunningDown = false;
|
isRunningDown = false;
|
||||||
previousTime = 0;
|
previousTime = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts moving Rockford to the right
|
* Starts moving Rockford to the right
|
||||||
*/
|
*/
|
||||||
public void startRunningRight() {
|
public void startRunningRight() {
|
||||||
isCollisionDone = false;
|
isCollisionDone = false;
|
||||||
isStaying = false;
|
isStaying = false;
|
||||||
isRunningLeft = false;
|
isRunningLeft = false;
|
||||||
isRunningRight = true;
|
isRunningRight = true;
|
||||||
isRunningUp = false;
|
isRunningUp = false;
|
||||||
isRunningDown = false;
|
isRunningDown = false;
|
||||||
previousTime = 0;
|
previousTime = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rockford running up
|
* Rockford running up
|
||||||
*/
|
*/
|
||||||
public void startRunningUp() {
|
public void startRunningUp() {
|
||||||
isCollisionDone = false;
|
isCollisionDone = false;
|
||||||
isStaying = false;
|
isStaying = false;
|
||||||
isRunningLeft = false;
|
isRunningLeft = false;
|
||||||
isRunningRight = false;
|
isRunningRight = false;
|
||||||
isRunningUp = true;
|
isRunningUp = true;
|
||||||
isRunningDown = false;
|
isRunningDown = false;
|
||||||
previousTime = 0;
|
previousTime = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rockford running down
|
* Rockford running down
|
||||||
*/
|
*/
|
||||||
public void startRunningDown() {
|
public void startRunningDown() {
|
||||||
isCollisionDone = false;
|
isCollisionDone = false;
|
||||||
isStaying = false;
|
isStaying = false;
|
||||||
isRunningLeft = false;
|
isRunningLeft = false;
|
||||||
isRunningRight = false;
|
isRunningRight = false;
|
||||||
isRunningUp = false;
|
isRunningUp = false;
|
||||||
isRunningDown = true;
|
isRunningDown = true;
|
||||||
previousTime = 0;
|
previousTime = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets whether Rockford collision has been handled or not
|
* Gets whether Rockford collision has been handled or not
|
||||||
*
|
*
|
||||||
* @return Rockford collision handled or not
|
* @return Rockford collision handled or not
|
||||||
*/
|
*/
|
||||||
public boolean isCollisionDone() {
|
public boolean isCollisionDone() {
|
||||||
return this.isCollisionDone;
|
return this.isCollisionDone;
|
||||||
@ -192,111 +192,111 @@ public class RockfordModel extends DisplayableElementModel {
|
|||||||
/**
|
/**
|
||||||
* Sets whether Rockford collision has been handled or not
|
* Sets whether Rockford collision has been handled or not
|
||||||
*
|
*
|
||||||
* @param isCollisionDone Rockford collision handled or not
|
* @param isCollisionDone Rockford collision handled or not
|
||||||
*/
|
*/
|
||||||
public void setCollisionDone(boolean isCollisionDone) {
|
public void setCollisionDone(boolean isCollisionDone) {
|
||||||
this.isCollisionDone = isCollisionDone;
|
this.isCollisionDone = isCollisionDone;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets whether Rockford is standing still or not
|
* Gets whether Rockford is standing still or not
|
||||||
*
|
*
|
||||||
* @return Rockford staying or not
|
* @return Rockford staying or not
|
||||||
*/
|
*/
|
||||||
public boolean isStaying() {
|
public boolean isStaying() {
|
||||||
return this.isStaying;
|
return this.isStaying;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets whether Rockford is running to the left or not
|
* Gets whether Rockford is running to the left or not
|
||||||
*
|
*
|
||||||
* @return Rockford running to the left or not
|
* @return Rockford running to the left or not
|
||||||
*/
|
*/
|
||||||
public boolean isRunningLeft() {
|
public boolean isRunningLeft() {
|
||||||
return this.isRunningLeft;
|
return this.isRunningLeft;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets whether Rockford is running to the right or not
|
* Gets whether Rockford is running to the right or not
|
||||||
*
|
*
|
||||||
* @return Rockford running to the right or not
|
* @return Rockford running to the right or not
|
||||||
*/
|
*/
|
||||||
public boolean isRunningRight() {
|
public boolean isRunningRight() {
|
||||||
return this.isRunningRight;
|
return this.isRunningRight;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets whether Rockford is running up or not
|
* Gets whether Rockford is running up or not
|
||||||
*
|
*
|
||||||
* @return Rockford running up, or not
|
* @return Rockford running up, or not
|
||||||
*/
|
*/
|
||||||
public boolean isRunningUp() {
|
public boolean isRunningUp() {
|
||||||
return this.isRunningUp;
|
return this.isRunningUp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets whether Rockford is running down or not
|
* Gets whether Rockford is running down or not
|
||||||
*
|
*
|
||||||
* @return Rockford running down, or not
|
* @return Rockford running down, or not
|
||||||
*/
|
*/
|
||||||
public boolean isRunningDown() {
|
public boolean isRunningDown() {
|
||||||
return this.isRunningDown;
|
return this.isRunningDown;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets whether Rockford is running up or down, or not
|
* Gets whether Rockford is running up or down, or not
|
||||||
*
|
*
|
||||||
* @return Rockford running up or down, or not
|
* @return Rockford running up or down, or not
|
||||||
*/
|
*/
|
||||||
public boolean isRunningUpOrDown() {
|
public boolean isRunningUpOrDown() {
|
||||||
return this.isRunningUp() || this.isRunningDown();
|
return this.isRunningUp() || this.isRunningDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes all sprites from the main image
|
* Initializes all sprites from the main image
|
||||||
* Takes the sub images and append them into storage arrays
|
* Takes the sub images and append them into storage arrays
|
||||||
*/
|
*/
|
||||||
private void initSprites() {
|
private void initSprites() {
|
||||||
framesBlinking = new ArrayList<BufferedImage>();
|
framesBlinking = new ArrayList<BufferedImage>();
|
||||||
framesRunningLeft = new ArrayList<BufferedImage>();
|
framesRunningLeft = new ArrayList<BufferedImage>();
|
||||||
framesRunningRight = new ArrayList<BufferedImage>();
|
framesRunningRight = new ArrayList<BufferedImage>();
|
||||||
framesRunningUpOrDown = new ArrayList<BufferedImage>();
|
framesRunningUpOrDown = new ArrayList<BufferedImage>();
|
||||||
|
|
||||||
/* INIT SPRITE ARRAYS FOR ROCKFORD */
|
/* INIT SPRITE ARRAYS FOR ROCKFORD */
|
||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
framesBlinking.add(
|
framesBlinking.add(
|
||||||
this.grabSprite(this.loadSprite(spriteName), 7 + (24 * i), 79, SIZ_X_OF_SPRITE, SIZ_Y_OF_SPRITE)
|
this.grabSprite(this.loadSprite(spriteName), 7 + (24 * i), 79, SIZ_X_OF_SPRITE, SIZ_Y_OF_SPRITE)
|
||||||
);
|
);
|
||||||
|
|
||||||
framesRunningLeft.add(
|
framesRunningLeft.add(
|
||||||
this.grabSprite(this.loadSprite(spriteName), 7 + (24 * i), 103, SIZ_X_OF_SPRITE, SIZ_Y_OF_SPRITE)
|
this.grabSprite(this.loadSprite(spriteName), 7 + (24 * i), 103, SIZ_X_OF_SPRITE, SIZ_Y_OF_SPRITE)
|
||||||
);
|
);
|
||||||
|
|
||||||
framesRunningRight.add(
|
framesRunningRight.add(
|
||||||
this.grabSprite(this.loadSprite(spriteName), 7 + (24 * i), 127, SIZ_X_OF_SPRITE, SIZ_Y_OF_SPRITE)
|
this.grabSprite(this.loadSprite(spriteName), 7 + (24 * i), 127, SIZ_X_OF_SPRITE, SIZ_Y_OF_SPRITE)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
framesRunningUpOrDown.add(
|
framesRunningUpOrDown.add(
|
||||||
this.grabSprite(this.loadSprite(spriteName), 7, 7, SIZ_X_OF_SPRITE, SIZ_Y_OF_SPRITE)
|
this.grabSprite(this.loadSprite(spriteName), 7, 7, SIZ_X_OF_SPRITE, SIZ_Y_OF_SPRITE)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return true if rockford has exploded (you = lose)
|
* Return true if rockford has exploded (you = lose)
|
||||||
*
|
*
|
||||||
* @return Whether Rockford has exploded or not
|
* @return Whether Rockford has exploded or not
|
||||||
*/
|
*/
|
||||||
public boolean getHasExplosed() {
|
public boolean getHasExplosed() {
|
||||||
return hasExploded;
|
return hasExploded;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set rockford exploded state
|
* Set rockford exploded state
|
||||||
*
|
*
|
||||||
* @param hasExploded Whether Rockford has exploded or not
|
* @param hasExploded Whether Rockford has exploded or not
|
||||||
*/
|
*/
|
||||||
public void setHasExplosed(boolean hasExploded){
|
public void setHasExplosed(boolean hasExploded) {
|
||||||
this.hasExploded = hasExploded;
|
this.hasExploded = hasExploded;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,42 +5,42 @@ import fr.enssat.BoulderDash.models.DisplayableElementModel;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* SteelWallModel
|
* SteelWallModel
|
||||||
*
|
* <p>
|
||||||
* Represents the steelWall
|
* Represents the steelWall
|
||||||
*
|
*
|
||||||
* @author Colin Leverger <me@colinleverger.fr>
|
* @author Colin Leverger <me@colinleverger.fr>
|
||||||
* @since 2015-06-19
|
* @since 2015-06-19
|
||||||
*/
|
*/
|
||||||
public class SteelWallModel extends DisplayableElementModel {
|
public class SteelWallModel extends DisplayableElementModel {
|
||||||
private static String spriteName;
|
private static String spriteName;
|
||||||
private static boolean isDestructible;
|
private static boolean isDestructible;
|
||||||
private static boolean canMove;
|
private static boolean canMove;
|
||||||
private static boolean impactExplosive;
|
private static boolean impactExplosive;
|
||||||
private static boolean animate;
|
private static boolean animate;
|
||||||
private static int priority;
|
private static int priority;
|
||||||
private static boolean falling;
|
private static boolean falling;
|
||||||
private static String collideSound;
|
private static String collideSound;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Static dataset
|
* Static dataset
|
||||||
* Specifies the physical parameters of the object
|
* Specifies the physical parameters of the object
|
||||||
*/
|
*/
|
||||||
static {
|
static {
|
||||||
spriteName = "steelwall";
|
spriteName = "steelwall";
|
||||||
isDestructible = false;
|
isDestructible = false;
|
||||||
canMove = false;
|
canMove = false;
|
||||||
impactExplosive = false;
|
impactExplosive = false;
|
||||||
animate = false;
|
animate = false;
|
||||||
priority = 3;
|
priority = 3;
|
||||||
falling = false;
|
falling = false;
|
||||||
collideSound = "touch";
|
collideSound = "touch";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor
|
* Class constructor
|
||||||
*/
|
*/
|
||||||
public SteelWallModel() {
|
public SteelWallModel() {
|
||||||
super(isDestructible, canMove, spriteName, priority, impactExplosive, animate, falling, collideSound);
|
super(isDestructible, canMove, spriteName, priority, impactExplosive, animate, falling, collideSound);
|
||||||
this.loadSprite(spriteName);
|
this.loadSprite(spriteName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,11 +11,11 @@ import fr.enssat.BoulderDash.views.LevelEditorView;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* AssetsLevelEditorComponent
|
* AssetsLevelEditorComponent
|
||||||
*
|
* <p>
|
||||||
* Information panel element.
|
* Information panel element.
|
||||||
*
|
*
|
||||||
* @author Valerian Saliou <valerian@valeriansaliou.name>
|
* @author Valerian Saliou <valerian@valeriansaliou.name>
|
||||||
* @since 2015-06-22
|
* @since 2015-06-22
|
||||||
*/
|
*/
|
||||||
public class AssetsLevelEditorComponent extends JPanel implements ActionListener {
|
public class AssetsLevelEditorComponent extends JPanel implements ActionListener {
|
||||||
private LevelEditorView levelEditorView;
|
private LevelEditorView levelEditorView;
|
||||||
@ -30,18 +30,18 @@ public class AssetsLevelEditorComponent extends JPanel implements ActionListener
|
|||||||
/**
|
/**
|
||||||
* Class constructor
|
* Class constructor
|
||||||
*
|
*
|
||||||
* @param levelEditorView Controller for level editor
|
* @param levelEditorView Controller for level editor
|
||||||
*/
|
*/
|
||||||
public AssetsLevelEditorComponent(LevelEditorView levelEditorView) {
|
public AssetsLevelEditorComponent(LevelEditorView levelEditorView) {
|
||||||
super(new BorderLayout());
|
super(new BorderLayout());
|
||||||
|
|
||||||
this.levelEditorView = levelEditorView;
|
this.levelEditorView = levelEditorView;
|
||||||
ButtonGroup buttonGroup = new ButtonGroup();
|
ButtonGroup buttonGroup = new ButtonGroup();
|
||||||
JPanel radioPanel = new JPanel(new GridLayout(0, 1));
|
JPanel radioPanel = new JPanel(new GridLayout(0, 1));
|
||||||
|
|
||||||
String curListChoice;
|
String curListChoice;
|
||||||
|
|
||||||
for(int i = 0; i < choiceList.size(); i++) {
|
for (int i = 0; i < choiceList.size(); i++) {
|
||||||
curListChoice = choiceList.get(i);
|
curListChoice = choiceList.get(i);
|
||||||
|
|
||||||
// Create radio buttons from list
|
// Create radio buttons from list
|
||||||
@ -66,7 +66,7 @@ public class AssetsLevelEditorComponent extends JPanel implements ActionListener
|
|||||||
/**
|
/**
|
||||||
* Listens for action events
|
* Listens for action events
|
||||||
*
|
*
|
||||||
* @param e Action event
|
* @param e Action event
|
||||||
*/
|
*/
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
JRadioButton sourceButton = (JRadioButton) e.getSource();
|
JRadioButton sourceButton = (JRadioButton) e.getSource();
|
||||||
|
@ -11,11 +11,11 @@ import java.awt.*;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* GameFieldView
|
* GameFieldView
|
||||||
*
|
* <p>
|
||||||
* Game field view for the game itself.
|
* Game field view for the game itself.
|
||||||
*
|
*
|
||||||
* @author Valerian Saliou <valerian@valeriansaliou.name>
|
* @author Valerian Saliou <valerian@valeriansaliou.name>
|
||||||
* @since 2015-06-21
|
* @since 2015-06-21
|
||||||
*/
|
*/
|
||||||
public class GameGroundView extends GroundView {
|
public class GameGroundView extends GroundView {
|
||||||
private GameController gameController;
|
private GameController gameController;
|
||||||
@ -23,8 +23,8 @@ public class GameGroundView extends GroundView {
|
|||||||
/**
|
/**
|
||||||
* Class constructor
|
* Class constructor
|
||||||
*
|
*
|
||||||
* @param gameController Game controller
|
* @param gameController Game controller
|
||||||
* @param levelModel Level model
|
* @param levelModel Level model
|
||||||
*/
|
*/
|
||||||
public GameGroundView(GameController gameController, LevelModel levelModel) {
|
public GameGroundView(GameController gameController, LevelModel levelModel) {
|
||||||
super(levelModel);
|
super(levelModel);
|
||||||
|
@ -14,34 +14,34 @@ import fr.enssat.BoulderDash.views.InformationPanel;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* GameView
|
* GameView
|
||||||
*
|
* <p>
|
||||||
* Specifies the game view itself.
|
* Specifies the game view itself.
|
||||||
*
|
*
|
||||||
* @author Colin Leverger <me@colinleverger.fr>
|
* @author Colin Leverger <me@colinleverger.fr>
|
||||||
* @since 2015-06-19
|
* @since 2015-06-19
|
||||||
*/
|
*/
|
||||||
public class GameView extends JFrame implements Observer {
|
public class GameView extends JFrame implements Observer {
|
||||||
private GameGroundView gameGroundView;
|
private GameGroundView gameGroundView;
|
||||||
private JPanel actionPanel;
|
private JPanel actionPanel;
|
||||||
private JPanel informationPanel;
|
private JPanel informationPanel;
|
||||||
private GameController gameController;
|
private GameController gameController;
|
||||||
private LevelModel levelModel;
|
private LevelModel levelModel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor
|
* Class constructor
|
||||||
*
|
*
|
||||||
* @param gameController Game controller
|
* @param gameController Game controller
|
||||||
* @param levelModel Level model
|
* @param levelModel Level model
|
||||||
*/
|
*/
|
||||||
public GameView(GameController gameController, LevelModel levelModel) {
|
public GameView(GameController gameController, LevelModel levelModel) {
|
||||||
this.gameController = gameController;
|
this.gameController = gameController;
|
||||||
this.levelModel = levelModel;
|
this.levelModel = levelModel;
|
||||||
|
|
||||||
this.initializeView();
|
this.initializeView();
|
||||||
this.createLayout();
|
this.createLayout();
|
||||||
|
|
||||||
this.gameGroundView.grabFocus();
|
this.gameGroundView.grabFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the view
|
* Initializes the view
|
||||||
@ -84,36 +84,36 @@ public class GameView extends JFrame implements Observer {
|
|||||||
/**
|
/**
|
||||||
* Gets the game field view
|
* Gets the game field view
|
||||||
*
|
*
|
||||||
* @return Game field view
|
* @return Game field view
|
||||||
*/
|
*/
|
||||||
public GameGroundView getGameFieldView() {
|
public GameGroundView getGameFieldView() {
|
||||||
return this.gameGroundView;
|
return this.gameGroundView;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the given button
|
* Creates the given button
|
||||||
*
|
*
|
||||||
* @param name Button name
|
* @param name Button name
|
||||||
* @return Created button
|
* @return Created button
|
||||||
*/
|
*/
|
||||||
public JButton createButton(String id, String name) {
|
public JButton createButton(String id, String name) {
|
||||||
JButton button = new JButton(name);
|
JButton button = new JButton(name);
|
||||||
button.addActionListener(this.gameController);
|
button.addActionListener(this.gameController);
|
||||||
button.setActionCommand(id);
|
button.setActionCommand(id);
|
||||||
|
|
||||||
this.actionPanel.add(button);
|
this.actionPanel.add(button);
|
||||||
|
|
||||||
return button;
|
return button;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the frame
|
* Updates the frame
|
||||||
*
|
*
|
||||||
* @param obs Observable item
|
* @param obs Observable item
|
||||||
* @param obj Object item
|
* @param obj Object item
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void update(Observable obs, Object obj) {
|
public void update(Observable obs, Object obj) {
|
||||||
// Nothing done.
|
// Nothing done.
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -10,101 +10,100 @@ import java.util.Observer;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* FieldView
|
* FieldView
|
||||||
*
|
* <p>
|
||||||
* FieldView, created by controller; we notice that we don't need to make
|
* FieldView, created by controller; we notice that we don't need to make
|
||||||
* levelModel observable; Because of the sprites we have to refresh the game
|
* levelModel observable; Because of the sprites we have to refresh the game
|
||||||
* windows very often so don't need of observers/observable mechanism
|
* windows very often so don't need of observers/observable mechanism
|
||||||
*
|
*
|
||||||
* @author Colin Leverger <me@colinleverger.fr>
|
* @author Colin Leverger <me@colinleverger.fr>
|
||||||
* @since 2015-06-19
|
* @since 2015-06-19
|
||||||
*
|
* <p>
|
||||||
* This view is basically drawing into the Frame the levelModel.
|
* This view is basically drawing into the Frame the levelModel.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public abstract class GroundView extends JPanel implements Observer {
|
public abstract class GroundView extends JPanel implements Observer {
|
||||||
protected LevelModel levelModel;
|
protected LevelModel levelModel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor
|
* Class constructor
|
||||||
*
|
*
|
||||||
* @param levelModel Level model
|
* @param levelModel Level model
|
||||||
*/
|
*/
|
||||||
public GroundView(LevelModel levelModel) {
|
public GroundView(LevelModel levelModel) {
|
||||||
this.levelModel = levelModel;
|
this.levelModel = levelModel;
|
||||||
this.levelModel.addObserver(this);
|
this.levelModel.addObserver(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Draws the map
|
* Draws the map
|
||||||
*
|
*
|
||||||
* @param width Map width
|
* @param width Map width
|
||||||
* @param height Map height
|
* @param height Map height
|
||||||
* @param g Map graphical object
|
* @param g Map graphical object
|
||||||
*/
|
*/
|
||||||
public void drawTerrain(int width, int height, Graphics g) {
|
public void drawTerrain(int width, int height, Graphics g) {
|
||||||
// Draw items
|
// Draw items
|
||||||
if (this.levelModel.getMode() == "game") {
|
if (this.levelModel.getMode() == "game") {
|
||||||
for (int x = 0; x < width; x++) {
|
for (int x = 0; x < width; x++) {
|
||||||
for (int y = 0; y < height; y++) {
|
for (int y = 0; y < height; y++) {
|
||||||
g.drawImage(this.levelModel.getImage(x, y), (x * 16), (y * 16), this);
|
g.drawImage(this.levelModel.getImage(x, y), (x * 16), (y * 16), this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!this.levelModel.isGameRunning()) {
|
if (!this.levelModel.isGameRunning()) {
|
||||||
if(!this.levelModel.getRockford().getHasExplosed()) {
|
if (!this.levelModel.getRockford().getHasExplosed()) {
|
||||||
this.displayWin();
|
this.displayWin();
|
||||||
} else {
|
} else {
|
||||||
this.displayLose();
|
this.displayLose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (int x = 0; x < width; x++) {
|
for (int x = 0; x < width; x++) {
|
||||||
for (int y = 0; y < height; y++) {
|
for (int y = 0; y < height; y++) {
|
||||||
g.drawImage(this.levelModel.getImage(x, y), (x * 16), (y * 16), this);
|
g.drawImage(this.levelModel.getImage(x, y), (x * 16), (y * 16), this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.levelModel.getShowCursor()) {
|
if (this.levelModel.getShowCursor()) {
|
||||||
g.drawImage(
|
g.drawImage(
|
||||||
this.levelModel.getCursorImage(),
|
this.levelModel.getCursorImage(),
|
||||||
((this.levelModel.getCursorXPosition() + 1) * 16),
|
((this.levelModel.getCursorXPosition() + 1) * 16),
|
||||||
((this.levelModel.getCursorYPosition() + 1) * 16),
|
((this.levelModel.getCursorYPosition() + 1) * 16),
|
||||||
this
|
this
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the view to inform the user that he won
|
* Set the view to inform the user that he won
|
||||||
*/
|
*/
|
||||||
private void displayWin() {
|
private void displayWin() {
|
||||||
new WinLoseView("win");
|
new WinLoseView("win");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the view to inform the user that he is not good at this game
|
* Set the view to inform the user that he is not good at this game
|
||||||
*/
|
*/
|
||||||
private void displayLose() {
|
private void displayLose() {
|
||||||
new WinLoseView("lose");
|
new WinLoseView("lose");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Paints the map
|
* Paints the map
|
||||||
*
|
*
|
||||||
* @param g Map graphical object
|
* @param g Map graphical object
|
||||||
*/
|
*/
|
||||||
public void paint(Graphics g) {
|
public void paint(Graphics g) {
|
||||||
this.drawTerrain(this.levelModel.getSizeWidth(), this.levelModel.getSizeHeight(), g);
|
this.drawTerrain(this.levelModel.getSizeWidth(), this.levelModel.getSizeHeight(), g);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the view
|
* Updates the view
|
||||||
*
|
*
|
||||||
* @param obs Observable item
|
* @param obs Observable item
|
||||||
* @param obj Object item
|
* @param obj Object item
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void update(Observable obs, Object obj) {
|
public void update(Observable obs, Object obj) {
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -5,15 +5,15 @@ import java.awt.BorderLayout;
|
|||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JTextArea;
|
import javax.swing.JTextArea;
|
||||||
|
|
||||||
public class HelpView extends JFrame{
|
public class HelpView extends JFrame {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate the HelpView
|
* Generate the HelpView
|
||||||
*/
|
*/
|
||||||
public HelpView(){
|
public HelpView() {
|
||||||
this.initializeView();
|
this.initializeView();
|
||||||
this.createLayout();
|
this.createLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the view
|
* Initializes the view
|
||||||
@ -33,18 +33,18 @@ public class HelpView extends JFrame{
|
|||||||
/**
|
/**
|
||||||
* Creates the view layout
|
* Creates the view layout
|
||||||
*/
|
*/
|
||||||
private void createLayout() {
|
private void createLayout() {
|
||||||
JTextArea help = new JTextArea();
|
JTextArea help = new JTextArea();
|
||||||
help.setEditable(false);
|
help.setEditable(false);
|
||||||
help.setText("To use the editor, you should :\n"
|
help.setText("To use the editor, you should :\n"
|
||||||
+ "- Select an item on the list,\n"
|
+ "- Select an item on the list,\n"
|
||||||
+ "- Move the RED cursur with the arrows\n"
|
+ "- Move the RED cursur with the arrows\n"
|
||||||
+ "- To place the selected item on the field, use SPACEBAR.\n"
|
+ "- To place the selected item on the field, use SPACEBAR.\n"
|
||||||
+ "If you want to lock the placement of the things, hit shift once (to unlock, rehit shift)\n"
|
+ "If you want to lock the placement of the things, hit shift once (to unlock, rehit shift)\n"
|
||||||
+ "Then, you can save & load your creation on game.\n"
|
+ "Then, you can save & load your creation on game.\n"
|
||||||
+ "You have to place at least 3 diamonds and 1 rockford!\n"
|
+ "You have to place at least 3 diamonds and 1 rockford!\n"
|
||||||
+ "Have fun ;-)");
|
+ "Have fun ;-)");
|
||||||
|
|
||||||
this.add(help, BorderLayout.CENTER);
|
this.add(help, BorderLayout.CENTER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,44 +11,44 @@ import fr.enssat.BoulderDash.models.LevelModel;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* InformationPanel
|
* InformationPanel
|
||||||
*
|
* <p>
|
||||||
* Information panel element.
|
* Information panel element.
|
||||||
*
|
*
|
||||||
* @author Colin Leverger <me@colinleverger.fr>
|
* @author Colin Leverger <me@colinleverger.fr>
|
||||||
* @since 2015-06-20
|
* @since 2015-06-20
|
||||||
*/
|
*/
|
||||||
public class InformationPanel extends JPanel implements Observer {
|
public class InformationPanel extends JPanel implements Observer {
|
||||||
private LevelModel levelModel;
|
private LevelModel levelModel;
|
||||||
private JTextArea text;
|
private JTextArea text;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor
|
* Class constructor
|
||||||
*/
|
*/
|
||||||
public InformationPanel(LevelModel levelModel) {
|
public InformationPanel(LevelModel levelModel) {
|
||||||
this.levelModel = levelModel;
|
this.levelModel = levelModel;
|
||||||
this.text = new JTextArea();
|
this.text = new JTextArea();
|
||||||
this.text.setEditable(false);
|
this.text.setEditable(false);
|
||||||
this.levelModel.getGameInformationModel().addObserver(this);
|
this.levelModel.getGameInformationModel().addObserver(this);
|
||||||
|
|
||||||
this.text.setText(
|
this.text.setText(
|
||||||
"Score : " + levelModel.getGameInformationModel().getScore() +
|
"Score : " + levelModel.getGameInformationModel().getScore() +
|
||||||
"\nRemaining diamonds : " + levelModel.getGameInformationModel().getRemainingsDiamonds()
|
"\nRemaining diamonds : " + levelModel.getGameInformationModel().getRemainingsDiamonds()
|
||||||
);
|
);
|
||||||
|
|
||||||
this.add(this.text);
|
this.add(this.text);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the panel
|
* Updates the panel
|
||||||
*
|
*
|
||||||
* @param o Observable item
|
* @param o Observable item
|
||||||
* @param arg Object item
|
* @param arg Object item
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void update(Observable o, Object arg) {
|
public void update(Observable o, Object arg) {
|
||||||
this.text.setText(
|
this.text.setText(
|
||||||
"Score : " + this.levelModel.getGameInformationModel().getScore() +
|
"Score : " + this.levelModel.getGameInformationModel().getScore() +
|
||||||
"\nRemaining diamonds : " + this.levelModel.getGameInformationModel().getRemainingsDiamonds()
|
"\nRemaining diamonds : " + this.levelModel.getGameInformationModel().getRemainingsDiamonds()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,17 +8,17 @@ import fr.enssat.BoulderDash.models.LevelModel;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* LevelEditorFieldView
|
* LevelEditorFieldView
|
||||||
*
|
* <p>
|
||||||
* Game field view for the level editor.
|
* Game field view for the level editor.
|
||||||
*
|
*
|
||||||
* @author Valerian Saliou <valerian@valeriansaliou.name>
|
* @author Valerian Saliou <valerian@valeriansaliou.name>
|
||||||
* @since 2015-06-21
|
* @since 2015-06-21
|
||||||
*/
|
*/
|
||||||
public class LevelEditorGroundView extends GroundView {
|
public class LevelEditorGroundView extends GroundView {
|
||||||
/**
|
/**
|
||||||
* Class constructor
|
* Class constructor
|
||||||
*
|
*
|
||||||
* @param levelModel Level model
|
* @param levelModel Level model
|
||||||
*/
|
*/
|
||||||
public LevelEditorGroundView(LevelModel levelModel, LevelEditorView levelEditorView) {
|
public LevelEditorGroundView(LevelModel levelModel, LevelEditorView levelEditorView) {
|
||||||
super(levelModel);
|
super(levelModel);
|
||||||
|
@ -16,11 +16,11 @@ import fr.enssat.BoulderDash.views.MenuLevelSelector;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* LevelEditorView
|
* LevelEditorView
|
||||||
*
|
* <p>
|
||||||
* Specifies the level editor view.
|
* Specifies the level editor view.
|
||||||
*
|
*
|
||||||
* @author Colin Leverger <me@colinleverger.fr>
|
* @author Colin Leverger <me@colinleverger.fr>
|
||||||
* @since 2015-06-19
|
* @since 2015-06-19
|
||||||
*/
|
*/
|
||||||
public class LevelEditorView extends JFrame implements Observer {
|
public class LevelEditorView extends JFrame implements Observer {
|
||||||
private LevelEditorGroundView fieldPanel;
|
private LevelEditorGroundView fieldPanel;
|
||||||
@ -39,23 +39,23 @@ public class LevelEditorView extends JFrame implements Observer {
|
|||||||
/**
|
/**
|
||||||
* Class constructor
|
* Class constructor
|
||||||
*/
|
*/
|
||||||
public LevelEditorView(LevelEditorController levelEditorController, LevelModel levelModel, NavigationBetweenViewController nav) {
|
public LevelEditorView(LevelEditorController levelEditorController, LevelModel levelModel, NavigationBetweenViewController nav) {
|
||||||
this.levelEditorController = levelEditorController;
|
this.levelEditorController = levelEditorController;
|
||||||
this.levelModel = levelModel;
|
this.levelModel = levelModel;
|
||||||
this.nav = nav;
|
this.nav = nav;
|
||||||
|
|
||||||
this.levelModel.addObserver(this);
|
this.levelModel.addObserver(this);
|
||||||
|
|
||||||
this.initializeView();
|
this.initializeView();
|
||||||
this.createLayout();
|
this.createLayout();
|
||||||
|
|
||||||
this.fieldPanel.grabFocus();
|
this.fieldPanel.grabFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the view layout
|
* Initializes the view layout
|
||||||
*/
|
*/
|
||||||
private void initializeView() {
|
private void initializeView() {
|
||||||
this.setFocusable(true);
|
this.setFocusable(true);
|
||||||
this.setVisible(false);
|
this.setVisible(false);
|
||||||
this.setResizable(false);
|
this.setResizable(false);
|
||||||
@ -70,18 +70,18 @@ public class LevelEditorView extends JFrame implements Observer {
|
|||||||
|
|
||||||
Image appIcon = Toolkit.getDefaultToolkit().getImage("./res/app/app_icon.png");
|
Image appIcon = Toolkit.getDefaultToolkit().getImage("./res/app/app_icon.png");
|
||||||
this.setIconImage(appIcon);
|
this.setIconImage(appIcon);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the view layout
|
* Creates the view layout
|
||||||
*/
|
*/
|
||||||
private void createLayout() {
|
private void createLayout() {
|
||||||
// List of levels
|
// List of levels
|
||||||
LevelSelectorHelper levelSelectorHelper = new LevelSelectorHelper(true, this);
|
LevelSelectorHelper levelSelectorHelper = new LevelSelectorHelper(true, this);
|
||||||
this.menuLevelSelector = levelSelectorHelper.createLevelList();
|
this.menuLevelSelector = levelSelectorHelper.createLevelList();
|
||||||
|
|
||||||
// Field + select panels
|
// Field + select panels
|
||||||
this.fieldPanel = new LevelEditorGroundView(this.levelModel, this);
|
this.fieldPanel = new LevelEditorGroundView(this.levelModel, this);
|
||||||
this.selectPanel = new JPanel();
|
this.selectPanel = new JPanel();
|
||||||
|
|
||||||
this.assetsComponent = new AssetsLevelEditorComponent(this);
|
this.assetsComponent = new AssetsLevelEditorComponent(this);
|
||||||
@ -104,14 +104,14 @@ public class LevelEditorView extends JFrame implements Observer {
|
|||||||
// Add top components
|
// Add top components
|
||||||
this.add(this.fieldPanel, BorderLayout.CENTER);
|
this.add(this.fieldPanel, BorderLayout.CENTER);
|
||||||
this.add(this.selectPanel, BorderLayout.WEST);
|
this.add(this.selectPanel, BorderLayout.WEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the given button
|
* Creates the given button
|
||||||
*
|
*
|
||||||
* @param id Button identifier
|
* @param id Button identifier
|
||||||
* @param name Button name
|
* @param name Button name
|
||||||
* @return Created button
|
* @return Created button
|
||||||
*/
|
*/
|
||||||
public JButton createButton(String id, String name) {
|
public JButton createButton(String id, String name) {
|
||||||
JButton button = new JButton(name);
|
JButton button = new JButton(name);
|
||||||
@ -124,7 +124,7 @@ public class LevelEditorView extends JFrame implements Observer {
|
|||||||
/**
|
/**
|
||||||
* Gets the level editor field view
|
* Gets the level editor field view
|
||||||
*
|
*
|
||||||
* @return Level editor field view
|
* @return Level editor field view
|
||||||
*/
|
*/
|
||||||
public LevelEditorGroundView getLevelEditorGroundView() {
|
public LevelEditorGroundView getLevelEditorGroundView() {
|
||||||
return this.fieldPanel;
|
return this.fieldPanel;
|
||||||
@ -133,7 +133,7 @@ public class LevelEditorView extends JFrame implements Observer {
|
|||||||
/**
|
/**
|
||||||
* Gets picked block value
|
* Gets picked block value
|
||||||
*
|
*
|
||||||
* @return Picked block value
|
* @return Picked block value
|
||||||
*/
|
*/
|
||||||
public String getPickedBlockValue() {
|
public String getPickedBlockValue() {
|
||||||
return this.pickedBlockValue;
|
return this.pickedBlockValue;
|
||||||
@ -142,7 +142,7 @@ public class LevelEditorView extends JFrame implements Observer {
|
|||||||
/**
|
/**
|
||||||
* Sets picked block value
|
* Sets picked block value
|
||||||
*
|
*
|
||||||
* @param pickedBlockValue Picked block value
|
* @param pickedBlockValue Picked block value
|
||||||
*/
|
*/
|
||||||
public void setPickedBlockValue(String pickedBlockValue) {
|
public void setPickedBlockValue(String pickedBlockValue) {
|
||||||
this.pickedBlockValue = pickedBlockValue;
|
this.pickedBlockValue = pickedBlockValue;
|
||||||
@ -151,8 +151,8 @@ public class LevelEditorView extends JFrame implements Observer {
|
|||||||
/**
|
/**
|
||||||
* Updates the view
|
* Updates the view
|
||||||
*
|
*
|
||||||
* @param obs Observable item
|
* @param obs Observable item
|
||||||
* @param obj Object item
|
* @param obj Object item
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void update(Observable obs, Object obj) {
|
public void update(Observable obs, Object obj) {
|
||||||
@ -162,12 +162,12 @@ public class LevelEditorView extends JFrame implements Observer {
|
|||||||
/**
|
/**
|
||||||
* Change opened level
|
* Change opened level
|
||||||
*
|
*
|
||||||
* @param selectedLevelValue Selected level value
|
* @param selectedLevelValue Selected level value
|
||||||
*/
|
*/
|
||||||
public void openedLevelChange(String selectedLevelValue) {
|
public void openedLevelChange(String selectedLevelValue) {
|
||||||
LevelModel pickedLevelModel;
|
LevelModel pickedLevelModel;
|
||||||
|
|
||||||
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, this.nav.getAudioLoadHelper(), "editor");
|
||||||
} else {
|
} else {
|
||||||
@ -195,13 +195,13 @@ public class LevelEditorView extends JFrame implements Observer {
|
|||||||
/**
|
/**
|
||||||
* Menu level selector change handler
|
* Menu level selector change handler
|
||||||
*
|
*
|
||||||
* @param changedSelector Changed selector
|
* @param changedSelector Changed selector
|
||||||
*/
|
*/
|
||||||
public void menuLevelSelectorChanged(MenuLevelSelector changedSelector) {
|
public void menuLevelSelectorChanged(MenuLevelSelector changedSelector) {
|
||||||
String selectedLevelValue = changedSelector.getChoiceValue().toString();
|
String selectedLevelValue = changedSelector.getChoiceValue().toString();
|
||||||
|
|
||||||
// Value didn't change?
|
// Value didn't change?
|
||||||
if(selectedLevelValue.equals(this.getSelectedLevel())) {
|
if (selectedLevelValue.equals(this.getSelectedLevel())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,7 +211,7 @@ public class LevelEditorView extends JFrame implements Observer {
|
|||||||
/**
|
/**
|
||||||
* Gets selected level
|
* Gets selected level
|
||||||
*
|
*
|
||||||
* @return Selected level
|
* @return Selected level
|
||||||
*/
|
*/
|
||||||
public String getSelectedLevel() {
|
public String getSelectedLevel() {
|
||||||
return this.selectedLevel;
|
return this.selectedLevel;
|
||||||
@ -220,9 +220,9 @@ public class LevelEditorView extends JFrame implements Observer {
|
|||||||
/**
|
/**
|
||||||
* Sets selected level
|
* Sets selected level
|
||||||
*
|
*
|
||||||
* @param level Selected level
|
* @param level Selected level
|
||||||
*/
|
*/
|
||||||
public void setSelectedLevel(String level) {
|
public void setSelectedLevel(String level) {
|
||||||
this.selectedLevel = level;
|
this.selectedLevel = level;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -10,11 +10,11 @@ import javax.swing.JPanel;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* MenuImage
|
* MenuImage
|
||||||
*
|
* <p>
|
||||||
* Specifies the menu image
|
* Specifies the menu image
|
||||||
*
|
*
|
||||||
* @author Valerian Saliou <valerian@valeriansaliou.name>
|
* @author Valerian Saliou <valerian@valeriansaliou.name>
|
||||||
* @since 2015-06-23
|
* @since 2015-06-23
|
||||||
*/
|
*/
|
||||||
public class MenuImage extends JPanel {
|
public class MenuImage extends JPanel {
|
||||||
private BufferedImage imageFile;
|
private BufferedImage imageFile;
|
||||||
@ -34,7 +34,7 @@ public class MenuImage extends JPanel {
|
|||||||
/**
|
/**
|
||||||
* Paints the component itself
|
* Paints the component itself
|
||||||
*
|
*
|
||||||
* @param g Graphics element
|
* @param g Graphics element
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void paintComponent(Graphics g) {
|
protected void paintComponent(Graphics g) {
|
||||||
|
@ -8,11 +8,11 @@ import fr.enssat.BoulderDash.views.LevelEditorView;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* MenuLevelSelector
|
* MenuLevelSelector
|
||||||
*
|
* <p>
|
||||||
* Specifies the menu level selector
|
* Specifies the menu level selector
|
||||||
*
|
*
|
||||||
* @author Valerian Saliou <valerian@valeriansaliou.name>
|
* @author Valerian Saliou <valerian@valeriansaliou.name>
|
||||||
* @since 2015-06-23
|
* @since 2015-06-23
|
||||||
*/
|
*/
|
||||||
public class MenuLevelSelector extends JComboBox {
|
public class MenuLevelSelector extends JComboBox {
|
||||||
private String choiceValue;
|
private String choiceValue;
|
||||||
@ -33,13 +33,13 @@ public class MenuLevelSelector extends JComboBox {
|
|||||||
/**
|
/**
|
||||||
* Called when an action is performed
|
* Called when an action is performed
|
||||||
*
|
*
|
||||||
* @param e Action event
|
* @param e Action event
|
||||||
*/
|
*/
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
JComboBox comboBoxSource = (JComboBox) e.getSource();
|
JComboBox comboBoxSource = (JComboBox) e.getSource();
|
||||||
this.choiceValue = (String) comboBoxSource.getSelectedItem();
|
this.choiceValue = (String) comboBoxSource.getSelectedItem();
|
||||||
|
|
||||||
if(this.levelEditorView != null) {
|
if (this.levelEditorView != null) {
|
||||||
this.levelEditorView.menuLevelSelectorChanged(this);
|
this.levelEditorView.menuLevelSelectorChanged(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -47,7 +47,7 @@ public class MenuLevelSelector extends JComboBox {
|
|||||||
/**
|
/**
|
||||||
* Gets the choice value
|
* Gets the choice value
|
||||||
*
|
*
|
||||||
* @return Choice value
|
* @return Choice value
|
||||||
*/
|
*/
|
||||||
public String getChoiceValue() {
|
public String getChoiceValue() {
|
||||||
return this.choiceValue;
|
return this.choiceValue;
|
||||||
@ -56,7 +56,7 @@ public class MenuLevelSelector extends JComboBox {
|
|||||||
/**
|
/**
|
||||||
* Selects a given value
|
* Selects a given value
|
||||||
*
|
*
|
||||||
* @param value Value to be selected
|
* @param value Value to be selected
|
||||||
*/
|
*/
|
||||||
public void setSelectedValue(String value) {
|
public void setSelectedValue(String value) {
|
||||||
for (int i = 0; i < this.getItemCount(); i++) {
|
for (int i = 0; i < this.getItemCount(); i++) {
|
||||||
@ -70,7 +70,7 @@ public class MenuLevelSelector extends JComboBox {
|
|||||||
/**
|
/**
|
||||||
* Sets the choice value
|
* Sets the choice value
|
||||||
*
|
*
|
||||||
* @param choiceValue Choice value
|
* @param choiceValue Choice value
|
||||||
*/
|
*/
|
||||||
public void setChoiceValue(String choiceValue) {
|
public void setChoiceValue(String choiceValue) {
|
||||||
this.choiceValue = choiceValue;
|
this.choiceValue = choiceValue;
|
||||||
|
@ -12,27 +12,27 @@ import fr.enssat.BoulderDash.controllers.NavigationBetweenViewController;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* MenuView
|
* MenuView
|
||||||
*
|
* <p>
|
||||||
* Menu view
|
* Menu view
|
||||||
*
|
*
|
||||||
* @author Valerian Saliou <valerian@valeriansaliou.name>
|
* @author Valerian Saliou <valerian@valeriansaliou.name>
|
||||||
* @since 2015-06-23
|
* @since 2015-06-23
|
||||||
*/
|
*/
|
||||||
public class MenuView extends JFrame {
|
public class MenuView extends JFrame {
|
||||||
private NavigationBetweenViewController navigationBetweenViewController;
|
private NavigationBetweenViewController navigationBetweenViewController;
|
||||||
private MenuImage menuImage;
|
private MenuImage menuImage;
|
||||||
private MenuLevelSelector menuLevelSelector;
|
private MenuLevelSelector menuLevelSelector;
|
||||||
private JPanel actionPanel;
|
private JPanel actionPanel;
|
||||||
private JPanel targetPanel;
|
private JPanel targetPanel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor
|
* Class constructor
|
||||||
*/
|
*/
|
||||||
public MenuView(NavigationBetweenViewController navigationBetweenViewController) {
|
public MenuView(NavigationBetweenViewController navigationBetweenViewController) {
|
||||||
this.navigationBetweenViewController = navigationBetweenViewController;
|
this.navigationBetweenViewController = navigationBetweenViewController;
|
||||||
this.initializeView();
|
this.initializeView();
|
||||||
this.createLayout();
|
this.createLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the view
|
* Initializes the view
|
||||||
@ -60,8 +60,8 @@ public class MenuView extends JFrame {
|
|||||||
this.targetPanel = new JPanel();
|
this.targetPanel = new JPanel();
|
||||||
|
|
||||||
this.menuImage = new MenuImage();
|
this.menuImage = new MenuImage();
|
||||||
this.actionPanel = new JPanel();
|
this.actionPanel = new JPanel();
|
||||||
|
|
||||||
// Add some buttons on the actionPanel
|
// Add some buttons on the actionPanel
|
||||||
this.createButton("game", "Game");
|
this.createButton("game", "Game");
|
||||||
this.createButton("editor", "Editor");
|
this.createButton("editor", "Editor");
|
||||||
@ -77,23 +77,23 @@ public class MenuView extends JFrame {
|
|||||||
/**
|
/**
|
||||||
* Creates the given button
|
* Creates the given button
|
||||||
*
|
*
|
||||||
* @param name Button name
|
* @param name Button name
|
||||||
* @return Created button
|
* @return Created button
|
||||||
*/
|
*/
|
||||||
public JButton createButton(String id, String name) {
|
public JButton createButton(String id, String name) {
|
||||||
JButton button = new JButton(name);
|
JButton button = new JButton(name);
|
||||||
button.addActionListener(this.navigationBetweenViewController);
|
button.addActionListener(this.navigationBetweenViewController);
|
||||||
button.setActionCommand(id);
|
button.setActionCommand(id);
|
||||||
|
|
||||||
this.actionPanel.add(button);
|
this.actionPanel.add(button);
|
||||||
|
|
||||||
return button;
|
return button;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the selected level identifier!
|
* Gets the selected level identifier!
|
||||||
*
|
*
|
||||||
* @return Level identifier
|
* @return Level identifier
|
||||||
*/
|
*/
|
||||||
public String getLevelIdentifier() {
|
public String getLevelIdentifier() {
|
||||||
return this.menuLevelSelector.getChoiceValue();
|
return this.menuLevelSelector.getChoiceValue();
|
||||||
|
@ -5,18 +5,18 @@ import java.awt.BorderLayout;
|
|||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JTextArea;
|
import javax.swing.JTextArea;
|
||||||
|
|
||||||
public class WinLoseView extends JFrame{
|
public class WinLoseView extends JFrame {
|
||||||
|
|
||||||
private String winOrLose;
|
|
||||||
|
|
||||||
/**
|
private String winOrLose;
|
||||||
* Generate the HelpView
|
|
||||||
*/
|
/**
|
||||||
public WinLoseView(String winOrLose){
|
* Generate the HelpView
|
||||||
this.winOrLose = winOrLose;
|
*/
|
||||||
this.initializeView();
|
public WinLoseView(String winOrLose) {
|
||||||
this.createLayout();
|
this.winOrLose = winOrLose;
|
||||||
}
|
this.initializeView();
|
||||||
|
this.createLayout();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the view
|
* Initializes the view
|
||||||
@ -36,14 +36,14 @@ public class WinLoseView extends JFrame{
|
|||||||
/**
|
/**
|
||||||
* Creates the view layout
|
* Creates the view layout
|
||||||
*/
|
*/
|
||||||
private void createLayout() {
|
private void createLayout() {
|
||||||
JTextArea help = new JTextArea();
|
JTextArea help = new JTextArea();
|
||||||
help.setEditable(false);
|
help.setEditable(false);
|
||||||
if(winOrLose.equals("win"))
|
if (winOrLose.equals("win"))
|
||||||
help.setText("YOU WIN THE GAME :-)");
|
help.setText("YOU WIN THE GAME :-)");
|
||||||
else
|
else
|
||||||
help.setText("YOU LOSE THE GAME :-( TRY AGAIN!");
|
help.setText("YOU LOSE THE GAME :-( TRY AGAIN!");
|
||||||
|
|
||||||
this.add(help);
|
this.add(help);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user