ueb02.2b
This commit is contained in:
parent
aa482c8e5d
commit
fc1375dd0e
@ -16,6 +16,7 @@ import fr.enssat.BoulderDash.models.DirtModel;
|
||||
import fr.enssat.BoulderDash.models.ExpandingWallModel;
|
||||
import fr.enssat.BoulderDash.models.CursorModel;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Observable;
|
||||
|
||||
@ -32,18 +33,21 @@ import java.util.Observable;
|
||||
*/
|
||||
public class LevelModel extends Observable implements Runnable {
|
||||
private DisplayableElementModel[][] groundGrid;
|
||||
private String levelName;
|
||||
private AudioLoadHelper audioLoadHelper;
|
||||
private int sizeWidth = 0;
|
||||
private int sizeHeight = 0;
|
||||
private int cursorXPosition = 0;
|
||||
private int cursorYPosition = 0;
|
||||
private AudioLoadHelper audioLoadHelper;
|
||||
private LevelLoadHelper levelLoadHelper;
|
||||
|
||||
/**
|
||||
* width = size.x
|
||||
* height = size.y
|
||||
*/
|
||||
private final Point size = new Point(0, 0);
|
||||
private final Point cursorPosition = new Point(0, 0);
|
||||
private int rockfordPositionX, rockfordPositionY;
|
||||
|
||||
private boolean showCursor = false;
|
||||
private CursorModel cursorModel;
|
||||
private LevelLoadHelper levelLoadHelper;
|
||||
private RockfordModel rockford;
|
||||
private GameInformationModel gameInformationModel;
|
||||
private int rockfordPositionX, rockfordPositionY;
|
||||
private boolean gameRunning;
|
||||
private boolean gamePaused;
|
||||
// Are we in editor or game mode ?
|
||||
@ -54,12 +58,7 @@ public class LevelModel extends Observable implements Runnable {
|
||||
*/
|
||||
private Thread spriteAnimator;
|
||||
|
||||
/**
|
||||
* Animation speed
|
||||
*/
|
||||
private final int DELAY = 25;
|
||||
|
||||
/**
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param levelName Level name
|
||||
@ -67,17 +66,16 @@ public class LevelModel extends Observable implements Runnable {
|
||||
* @param mode Instance mode
|
||||
*/
|
||||
public LevelModel(String levelName, AudioLoadHelper audioLoadHelper, String mode) {
|
||||
this.levelName = levelName;
|
||||
this.audioLoadHelper = audioLoadHelper;
|
||||
this.audioLoadHelper = audioLoadHelper;
|
||||
this.gamePaused = false;
|
||||
this.gameRunning = true;
|
||||
this.mode = mode;
|
||||
|
||||
this.levelLoadHelper = new LevelLoadHelper(this.levelName);
|
||||
this.levelLoadHelper = new LevelLoadHelper(levelName);
|
||||
|
||||
this.groundGrid = this.levelLoadHelper.getGroundGrid();
|
||||
this.sizeWidth = this.levelLoadHelper.getWidthSizeValue();
|
||||
this.sizeHeight = this.levelLoadHelper.getHeightSizeValue();
|
||||
this.setSizeWidth(this.levelLoadHelper.getWidthSizeValue());
|
||||
this.setSizeHeight(this.levelLoadHelper.getHeightSizeValue());
|
||||
|
||||
this.cursorModel = new CursorModel();
|
||||
this.gameInformationModel = new GameInformationModel(this.levelLoadHelper.getDiamondsToCatch());
|
||||
@ -110,14 +108,14 @@ public class LevelModel extends Observable implements Runnable {
|
||||
this.gameRunning = false;
|
||||
this.mode = "editor";
|
||||
|
||||
this.sizeWidth = 25 + 2;
|
||||
this.sizeHeight = 25 + 2;
|
||||
this.setSizeWidth(25 + 2);
|
||||
this.setSizeHeight(25 + 2);
|
||||
|
||||
// Generate dirt
|
||||
this.groundGrid = new DisplayableElementModel[this.sizeWidth][this.sizeHeight];
|
||||
this.groundGrid = new DisplayableElementModel[this.getSizeWidth()][this.getSizeHeight()];
|
||||
|
||||
for (int x = 0; x < this.sizeWidth; x++) {
|
||||
for (int y = 0; y < this.sizeHeight; y++) {
|
||||
for (int x = 0; x < this.getSizeWidth(); x++) {
|
||||
for (int y = 0; y < this.getSizeHeight(); y++) {
|
||||
this.groundGrid[x][y] = new DirtModel();
|
||||
}
|
||||
}
|
||||
@ -146,14 +144,14 @@ public class LevelModel extends Observable implements Runnable {
|
||||
* Creates the limits Puts steel walls all around the game panel
|
||||
*/
|
||||
private void createLimits() {
|
||||
int maxWidth = this.sizeWidth - 1;
|
||||
int maxHeight = this.sizeHeight - 1;
|
||||
int maxWidth = this.getSizeWidth() - 1;
|
||||
int maxHeight = this.getSizeHeight() - 1;
|
||||
|
||||
for (int x = 0; x < this.sizeWidth; x++) {
|
||||
for (int x = 0; x < this.getSizeWidth(); x++) {
|
||||
this.groundGrid[x][0] = new SteelWallModel();
|
||||
this.groundGrid[x][maxHeight] = new SteelWallModel();
|
||||
}
|
||||
for (int y = 0; y < this.sizeHeight; y++) {
|
||||
for (int y = 0; y < this.getSizeHeight(); y++) {
|
||||
this.groundGrid[0][y] = new SteelWallModel();
|
||||
this.groundGrid[maxWidth][y] = new SteelWallModel();
|
||||
}
|
||||
@ -426,7 +424,7 @@ public class LevelModel extends Observable implements Runnable {
|
||||
* @return Horizontal size
|
||||
*/
|
||||
public int getSizeWidth() {
|
||||
return this.sizeWidth;
|
||||
return this.size.x;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -435,7 +433,7 @@ public class LevelModel extends Observable implements Runnable {
|
||||
* @param sizeWidth Horizontal size
|
||||
*/
|
||||
public void setSizeWidth(int sizeWidth) {
|
||||
this.sizeWidth = sizeWidth;
|
||||
this.size.x = sizeWidth;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -444,7 +442,7 @@ public class LevelModel extends Observable implements Runnable {
|
||||
* @return Vertical size
|
||||
*/
|
||||
public int getSizeHeight() {
|
||||
return this.sizeHeight;
|
||||
return this.size.y;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -453,7 +451,7 @@ public class LevelModel extends Observable implements Runnable {
|
||||
* @return sizeHeight Vertical size
|
||||
*/
|
||||
public void setSizeHeight(int sizeHeight) {
|
||||
this.sizeHeight = sizeHeight;
|
||||
this.size.y = sizeHeight;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -502,7 +500,11 @@ public class LevelModel extends Observable implements Runnable {
|
||||
}
|
||||
|
||||
try {
|
||||
Thread.sleep(DELAY);
|
||||
/**
|
||||
* Animation speed
|
||||
*/
|
||||
int delay = 25;
|
||||
Thread.sleep(delay);
|
||||
} catch (InterruptedException e) {
|
||||
System.out.println("Interrupted: " + e.getMessage());
|
||||
}
|
||||
@ -531,7 +533,10 @@ public class LevelModel extends Observable implements Runnable {
|
||||
* @return Cursor position X value
|
||||
*/
|
||||
public int getCursorXPosition() {
|
||||
return this.cursorXPosition;
|
||||
return this.cursorPosition.x;
|
||||
}
|
||||
public int setCursorXPosition(int x) {
|
||||
return this.cursorPosition.x = x;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -540,7 +545,10 @@ public class LevelModel extends Observable implements Runnable {
|
||||
* @return Cursor position Y value
|
||||
*/
|
||||
public int getCursorYPosition() {
|
||||
return this.cursorYPosition;
|
||||
return this.cursorPosition.y;
|
||||
}
|
||||
public int setCursorYPosition(int y) {
|
||||
return this.cursorPosition.y = y;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -549,8 +557,8 @@ public class LevelModel extends Observable implements Runnable {
|
||||
* @return Cursor position new X value
|
||||
*/
|
||||
public int incrementCursorXPosition() {
|
||||
if (this.cursorXPosition < (this.getSizeWidth() - 1 - 2)) {
|
||||
this.cursorXPosition = this.cursorXPosition + 1;
|
||||
if (this.getCursorXPosition() < (this.getSizeWidth() - 1 - 2)) {
|
||||
this.setCursorXPosition(this.getCursorXPosition() + 1);
|
||||
}
|
||||
|
||||
this.localNotifyObservers();
|
||||
@ -563,8 +571,8 @@ public class LevelModel extends Observable implements Runnable {
|
||||
* @return Cursor position new X value
|
||||
*/
|
||||
public int decrementCursorXPosition() {
|
||||
if (this.cursorXPosition > 0) {
|
||||
this.cursorXPosition = this.cursorXPosition - 1;
|
||||
if (this.getCursorXPosition() > 0) {
|
||||
this.setCursorXPosition(this.getCursorXPosition() - 1);
|
||||
}
|
||||
|
||||
this.localNotifyObservers();
|
||||
@ -577,8 +585,8 @@ public class LevelModel extends Observable implements Runnable {
|
||||
* @return Cursor position new Y value
|
||||
*/
|
||||
public int incrementCursorYPosition() {
|
||||
if (this.cursorYPosition < (this.getSizeHeight() - 1 - 2)) {
|
||||
this.cursorYPosition = this.cursorYPosition + 1;
|
||||
if (this.getCursorYPosition() < (this.getSizeHeight() - 1 - 2)) {
|
||||
this.setCursorYPosition(this.getCursorYPosition() + 1);
|
||||
}
|
||||
|
||||
this.localNotifyObservers();
|
||||
@ -591,8 +599,8 @@ public class LevelModel extends Observable implements Runnable {
|
||||
* @return Cursor position new Y value
|
||||
*/
|
||||
public int decrementCursorYPosition() {
|
||||
if (this.cursorYPosition > 0) {
|
||||
this.cursorYPosition = this.cursorYPosition - 1;
|
||||
if (this.getCursorYPosition() > 0) {
|
||||
this.setCursorYPosition(this.getCursorYPosition() - 1);
|
||||
}
|
||||
|
||||
this.localNotifyObservers();
|
||||
|
Loading…
x
Reference in New Issue
Block a user