Merge branch 'ueb03-semenovykh' into ueb03
# Conflicts: # .idea/misc.xml # src/fr/enssat/BoulderDash/controllers/BoulderAndDiamondController.java # src/fr/enssat/BoulderDash/models/LevelModel.java
This commit is contained in:
commit
32647ef118
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@ -3,7 +3,7 @@
|
|||||||
<component name="PDMPlugin">
|
<component name="PDMPlugin">
|
||||||
<option name="skipTestSources" value="false" />
|
<option name="skipTestSources" value="false" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="openjdk-21" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="openjdk-21" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/classes" />
|
<output url="file://$PROJECT_DIR$/classes" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
@ -37,7 +37,7 @@ public class BoulderAndDiamondController extends AbstractLevelController impleme
|
|||||||
*/
|
*/
|
||||||
public void run() {
|
public void run() {
|
||||||
while (this.levelModel.isGameRunning()) {
|
while (this.levelModel.isGameRunning()) {
|
||||||
if (!this.levelModel.getGamePaused()) {
|
if(!this.levelModel.getGamePaused()){
|
||||||
this.manageFallingObject();
|
this.manageFallingObject();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@ -57,9 +57,9 @@ public class BoulderAndDiamondController extends AbstractLevelController impleme
|
|||||||
for (int x = this.levelModel.getSizeWidth() - 1; x >= 0; x--) {
|
for (int x = this.levelModel.getSizeWidth() - 1; x >= 0; x--) {
|
||||||
for (int y = this.levelModel.getSizeHeight() - 1; y >= 0; y--) {
|
for (int y = this.levelModel.getSizeHeight() - 1; y >= 0; y--) {
|
||||||
// Gets the spriteName of actual DisplayableElementModel object scanned
|
// Gets the spriteName of actual DisplayableElementModel object scanned
|
||||||
DisplayableElementModel elementModel = this.levelModel.getGroundLevelModel()[x][y];
|
DisplayableElementModel elementModel = this.levelModel.getElement(x, y);
|
||||||
|
|
||||||
if (elementModel == null) {
|
if(elementModel == null) {
|
||||||
elementModel = new DirtModel();
|
elementModel = new DirtModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,9 +67,9 @@ public class BoulderAndDiamondController extends AbstractLevelController impleme
|
|||||||
|
|
||||||
// If it is a boulder or a diamond...
|
// If it is a boulder or a diamond...
|
||||||
if (spriteName == "boulder" || spriteName == "diamond") {
|
if (spriteName == "boulder" || spriteName == "diamond") {
|
||||||
this.manageFall(x, y);
|
this.manageFallingObjectBehavior(x, y);
|
||||||
} else if (spriteName == "expandingwall") {
|
} else if(spriteName == "expandingwall"){
|
||||||
if (this.expandWall(x, y).equals("left")) {
|
if(this.expandWall(x,y).equals("left")){
|
||||||
x -= 1;
|
x -= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -84,18 +84,19 @@ public class BoulderAndDiamondController extends AbstractLevelController impleme
|
|||||||
* @param y Vertical position
|
* @param y Vertical position
|
||||||
*/
|
*/
|
||||||
private String expandWall(int x, int y) {
|
private String expandWall(int x, int y) {
|
||||||
DisplayableElementModel elementLeft = this.levelModel.getGroundLevelModel()[x - 1][y];
|
DisplayableElementModel elementLeft = this.levelModel.getElementLeft(x, y);
|
||||||
DisplayableElementModel elementRight = this.levelModel.getGroundLevelModel()[x + 1][y];
|
DisplayableElementModel elementRight = this.levelModel.getElementRight(x, y);
|
||||||
|
|
||||||
String spriteNameLeft = elementLeft.getSpriteName();
|
String spriteNameLeft = elementLeft.getSpriteName();
|
||||||
String spriteNameRight = elementRight.getSpriteName();
|
String spriteNameRight = elementRight.getSpriteName();
|
||||||
|
|
||||||
String way = "";
|
String way = "";
|
||||||
if (spriteNameLeft == "black") {
|
if(spriteNameLeft == "black"){
|
||||||
this.levelModel.expandThisWallToLeft(x, y);
|
this.levelModel.expandThisWallToLeft(x,y);
|
||||||
way = "left";
|
way = "left";
|
||||||
}
|
}
|
||||||
if (spriteNameRight == "black") {
|
if(spriteNameRight == "black"){
|
||||||
this.levelModel.expandThisWallToRight(x, y);
|
this.levelModel.expandThisWallToRight(x,y);
|
||||||
way = "right";
|
way = "right";
|
||||||
}
|
}
|
||||||
return way;
|
return way;
|
||||||
@ -107,11 +108,16 @@ public class BoulderAndDiamondController extends AbstractLevelController impleme
|
|||||||
* @param x Horizontal position
|
* @param x Horizontal position
|
||||||
* @param y Vertical position
|
* @param y Vertical position
|
||||||
*/
|
*/
|
||||||
private void manageFall(int x, int y) {
|
private void manageFallingObjectBehavior(int x, int y) {
|
||||||
|
|
||||||
|
// Task3 - Variable to get rig of calling one Method in if-clause several times
|
||||||
|
DisplayableElementModel element = this.levelModel.getElement(x, y);
|
||||||
|
DisplayableElementModel elementTwoBelow = this.levelModel.getElementTwoBelow(x, y);
|
||||||
|
|
||||||
// Get informed about Rockford surroundings
|
// Get informed about Rockford surroundings
|
||||||
DisplayableElementModel elementBelow = this.levelModel.getGroundLevelModel()[x][y + 1];
|
DisplayableElementModel elementBelow = this.levelModel.getElementBelow(x, y);
|
||||||
DisplayableElementModel elementLeft = this.levelModel.getGroundLevelModel()[x - 1][y];
|
DisplayableElementModel elementLeft = this.levelModel.getElementLeft(x, y);
|
||||||
DisplayableElementModel elementRight = this.levelModel.getGroundLevelModel()[x + 1][y];
|
DisplayableElementModel elementRight = this.levelModel.getElementRight(x, y);
|
||||||
|
|
||||||
String spriteNameBelow = elementBelow.getSpriteName();
|
String spriteNameBelow = elementBelow.getSpriteName();
|
||||||
String spriteNameLeft = elementLeft.getSpriteName();
|
String spriteNameLeft = elementLeft.getSpriteName();
|
||||||
@ -122,12 +128,13 @@ public class BoulderAndDiamondController extends AbstractLevelController impleme
|
|||||||
this.levelModel.makeThisDisplayableElementFall(x, y);
|
this.levelModel.makeThisDisplayableElementFall(x, y);
|
||||||
} else if (spriteNameBelow == "boulder") {
|
} else if (spriteNameBelow == "boulder") {
|
||||||
// Boulders have to roll if they hit another boulder
|
// Boulders have to roll if they hit another boulder
|
||||||
if (this.levelModel.getGroundLevelModel()[x - 1][y + 1].getSpriteName() == "black") {
|
if (this.levelModel.getElementBelowLeft(x, y).getSpriteName() == "black") {
|
||||||
this.levelModel.makeThisBoulderSlideLeft(x, y);
|
this.levelModel.makeThisBoulderSlideLeft(x, y);
|
||||||
} else if (this.levelModel.getGroundLevelModel()[x + 1][y + 1].getSpriteName() == "black") {
|
} else if (this.levelModel.getElementBelowRight(x, y).getSpriteName() == "black") {
|
||||||
this.levelModel.makeThisBoulderSlideRight(x, y);
|
this.levelModel.makeThisBoulderSlideRight(x, y);
|
||||||
}
|
}
|
||||||
} else if (spriteNameBelow == "rockford" && this.levelModel.getGroundLevelModel()[x][y].isFalling()) {
|
} else {
|
||||||
|
if (spriteNameBelow == "rockford" && element.isFalling()) {
|
||||||
this.levelModel.exploseGround(x, y + 1);
|
this.levelModel.exploseGround(x, y + 1);
|
||||||
|
|
||||||
AUDIO_LOAD_HELPER.playSound("die");
|
AUDIO_LOAD_HELPER.playSound("die");
|
||||||
@ -140,23 +147,26 @@ public class BoulderAndDiamondController extends AbstractLevelController impleme
|
|||||||
|
|
||||||
this.levelModel.setGameRunning(false);
|
this.levelModel.setGameRunning(false);
|
||||||
} else if (spriteNameBelow == "magicwall") {
|
} else if (spriteNameBelow == "magicwall") {
|
||||||
if (this.levelModel.getGroundLevelModel()[x][y].getSpriteName() == "boulder"
|
if (element.getSpriteName() == "boulder"
|
||||||
&& (this.levelModel.getGroundLevelModel()[x][y + 2].getSpriteName() == "dirt" ||
|
&& (elementTwoBelow.getSpriteName() == "dirt" ||
|
||||||
this.levelModel.getGroundLevelModel()[x][y + 2].getSpriteName() == "black")) {
|
elementTwoBelow.getSpriteName() == "black")) {
|
||||||
if (this.levelModel.getGroundLevelModel()[x][y].isConvertible()) {
|
if(element.isConvertible()) {
|
||||||
this.levelModel.transformThisBoulderIntoADiamond(x, y);
|
this.levelModel.transformThisBoulderIntoADiamond(x, y);
|
||||||
} else {
|
} else {
|
||||||
this.levelModel.deleteThisBoulder(x, y);
|
this.levelModel.deleteThisBoulder(x, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (elementBelow.isDestructible() && spriteNameBelow != "dirt" && this.levelModel.getGroundLevelModel()[x][y].isFalling()) {
|
} else if (elementBelow.isDestructible() && spriteNameBelow != "dirt" && element.isFalling()) {
|
||||||
this.levelModel.exploseThisBrickWall(x, y);
|
this.levelModel.exploseThisBrickWall(x, y);
|
||||||
} else if (spriteNameLeft == "rockford" && this.levelModel.getRockford().isRunningRight() && this.levelModel.getGroundLevelModel()[x + 1][y].getSpriteName() == "black") {
|
} else if (spriteNameLeft == "rockford" && this.levelModel.getRockford().isRunningRight() && elementRight.getSpriteName() == "black") {
|
||||||
this.levelModel.moveThisBoulderToRight(x, y);
|
this.levelModel.moveThisBoulderToRight(x, y);
|
||||||
} else if (spriteNameRight == "rockford" && this.levelModel.getRockford().isRunningLeft() && this.levelModel.getGroundLevelModel()[x - 1][y].getSpriteName() == "black") {
|
} else if (spriteNameRight == "rockford" && this.levelModel.getRockford().isRunningLeft() && elementLeft.getSpriteName() == "black") {
|
||||||
this.levelModel.moveThisBoulderToLeft(x, y);
|
this.levelModel.moveThisBoulderToLeft(x, y);
|
||||||
} else {
|
} else {
|
||||||
this.levelModel.getGroundLevelModel()[x][y].setFalling(false);
|
element.setFalling(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ import static fr.enssat.BoulderDash.helpers.AudioLoadHelper.AUDIO_LOAD_HELPER;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* LevelModel
|
* LevelModel
|
||||||
* <p>
|
*
|
||||||
* Levels are loaded from XML file. The view knows the model, the controller is
|
* Levels are loaded from XML file. The view knows the model, the controller is
|
||||||
* going to modify the model in function of the game panel. The model notifies
|
* going to modify the model in function of the game panel. The model notifies
|
||||||
* the view when there are changes on it.
|
* the view when there are changes on it.
|
||||||
@ -72,7 +72,7 @@ public class LevelModel extends Observable implements Runnable {
|
|||||||
|
|
||||||
this.createLimits();
|
this.createLimits();
|
||||||
|
|
||||||
if (this.mode.equals("game")) {
|
if(this.mode.equals("game")) {
|
||||||
this.initRockford();
|
this.initRockford();
|
||||||
this.initThreadAnimator();
|
this.initThreadAnimator();
|
||||||
}
|
}
|
||||||
@ -258,12 +258,12 @@ public class LevelModel extends Observable implements Runnable {
|
|||||||
*/
|
*/
|
||||||
public void triggerBlockChange(String blockValue) {
|
public void triggerBlockChange(String blockValue) {
|
||||||
// No block value?
|
// No block value?
|
||||||
if (blockValue == null || blockValue.isEmpty()) {
|
if(blockValue == null || blockValue.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cancel if Rockford is already in model
|
// Cancel if Rockford is already in model
|
||||||
if ((blockValue.equals("Rockford") || blockValue.equals("rockford")) && this.isRockfordInModel()) {
|
if((blockValue.equals("Rockford") || blockValue.equals("rockford")) && this.isRockfordInModel()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -327,7 +327,7 @@ public class LevelModel extends Observable implements Runnable {
|
|||||||
public BufferedImage getImage(int x, int y) {
|
public BufferedImage getImage(int x, int y) {
|
||||||
DisplayableElementModel elementModel = this.getDisplayableElement(x, y);
|
DisplayableElementModel elementModel = this.getDisplayableElement(x, y);
|
||||||
|
|
||||||
if (elementModel == null) {
|
if(elementModel == null) {
|
||||||
return new DirtModel().getSprite();
|
return new DirtModel().getSprite();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -360,7 +360,7 @@ public class LevelModel extends Observable implements Runnable {
|
|||||||
// Iterate and catch it!
|
// Iterate and catch it!
|
||||||
for (int x = 0; x < this.getSizeWidth() && !isInModel; x++) {
|
for (int x = 0; x < this.getSizeWidth() && !isInModel; x++) {
|
||||||
for (int y = 0; y < this.getSizeHeight() && !isInModel; y++) {
|
for (int y = 0; y < this.getSizeHeight() && !isInModel; y++) {
|
||||||
if (this.groundGrid[x][y] != null && this.groundGrid[x][y].getSpriteName() == "rockford") {
|
if(this.groundGrid[x][y] != null && this.groundGrid[x][y].getSpriteName() == "rockford") {
|
||||||
isInModel = true;
|
isInModel = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -380,7 +380,7 @@ public class LevelModel extends Observable implements Runnable {
|
|||||||
// Iterate and catch it!
|
// Iterate and catch it!
|
||||||
for (int x = 0; x < this.getSizeWidth(); x++) {
|
for (int x = 0; x < this.getSizeWidth(); x++) {
|
||||||
for (int y = 0; y < this.getSizeHeight(); y++) {
|
for (int y = 0; y < this.getSizeHeight(); y++) {
|
||||||
if (this.groundGrid[x][y] != null && this.groundGrid[x][y].getSpriteName() == "diamond") {
|
if(this.groundGrid[x][y] != null && this.groundGrid[x][y].getSpriteName() == "diamond") {
|
||||||
numberOfDiamonds += 1;
|
numberOfDiamonds += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -394,12 +394,12 @@ public class LevelModel extends Observable implements Runnable {
|
|||||||
*/
|
*/
|
||||||
public void checkConstraints() throws LevelConstraintNotRespectedException {
|
public void checkConstraints() throws LevelConstraintNotRespectedException {
|
||||||
// Diamonds number?
|
// Diamonds number?
|
||||||
if (this.countDiamonds() < 3) {
|
if(this.countDiamonds() < 3) {
|
||||||
throw new LevelConstraintNotRespectedException("Add at least 3 diamonds!");
|
throw new LevelConstraintNotRespectedException("Add at least 3 diamonds!");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rockford in model?
|
// Rockford in model?
|
||||||
if (!this.isRockfordInModel()) {
|
if(!this.isRockfordInModel()) {
|
||||||
throw new LevelConstraintNotRespectedException("Add Rockford on the map!");
|
throw new LevelConstraintNotRespectedException("Add Rockford on the map!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -449,6 +449,38 @@ public class LevelModel extends Observable implements Runnable {
|
|||||||
return groundGrid;
|
return groundGrid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Task 3c - move methods to LevelModel
|
||||||
|
*
|
||||||
|
* @return position according to specific
|
||||||
|
*/
|
||||||
|
public DisplayableElementModel getElement(int x, int y) {
|
||||||
|
return getGroundLevelModel()[x][y];
|
||||||
|
}
|
||||||
|
|
||||||
|
public DisplayableElementModel getElementTwoBelow(int x, int y) {
|
||||||
|
return getElement(x, y + 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DisplayableElementModel getElementBelowRight(int x, int y) {
|
||||||
|
return getElement(x + 1, y + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DisplayableElementModel getElementBelowLeft(int x, int y) {
|
||||||
|
return getElement(x - 1, y + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DisplayableElementModel getElementRight(int x, int y) {
|
||||||
|
return getElement(x + 1, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DisplayableElementModel getElementLeft(int x, int y) {
|
||||||
|
return getElement(x - 1, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DisplayableElementModel getElementBelow(int x, int y) {
|
||||||
|
return getElement(x, y + 1);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Notify observers about a model change
|
* Notify observers about a model change
|
||||||
*/
|
*/
|
||||||
@ -464,7 +496,7 @@ public class LevelModel extends Observable implements Runnable {
|
|||||||
* @param y Sprite block vertical position
|
* @param y Sprite block vertical position
|
||||||
*/
|
*/
|
||||||
public void updateSprites(int x, int y) {
|
public void updateSprites(int x, int y) {
|
||||||
if (groundGrid[x][y] == null) {
|
if(groundGrid[x][y] == null) {
|
||||||
groundGrid[x][y] = new DirtModel();
|
groundGrid[x][y] = new DirtModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user