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