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
.idea
src/fr/enssat/BoulderDash
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@ -3,7 +3,7 @@
|
||||
<component name="PDMPlugin">
|
||||
<option name="skipTestSources" value="false" />
|
||||
</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" />
|
||||
</component>
|
||||
</project>
|
@ -57,7 +57,7 @@ public class BoulderAndDiamondController extends AbstractLevelController impleme
|
||||
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];
|
||||
DisplayableElementModel elementModel = this.levelModel.getElement(x, y);
|
||||
|
||||
if(elementModel == null) {
|
||||
elementModel = new DirtModel();
|
||||
@ -67,7 +67,7 @@ public class BoulderAndDiamondController extends AbstractLevelController impleme
|
||||
|
||||
// If it is a boulder or a diamond...
|
||||
if (spriteName == "boulder" || spriteName == "diamond") {
|
||||
this.manageFall(x, y);
|
||||
this.manageFallingObjectBehavior(x, y);
|
||||
} else if(spriteName == "expandingwall"){
|
||||
if(this.expandWall(x,y).equals("left")){
|
||||
x -= 1;
|
||||
@ -84,8 +84,9 @@ public class BoulderAndDiamondController extends AbstractLevelController impleme
|
||||
* @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];
|
||||
DisplayableElementModel elementLeft = this.levelModel.getElementLeft(x, y);
|
||||
DisplayableElementModel elementRight = this.levelModel.getElementRight(x, y);
|
||||
|
||||
String spriteNameLeft = elementLeft.getSpriteName();
|
||||
String spriteNameRight = elementRight.getSpriteName();
|
||||
|
||||
@ -107,11 +108,16 @@ public class BoulderAndDiamondController extends AbstractLevelController impleme
|
||||
* @param x Horizontal 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
|
||||
DisplayableElementModel elementBelow = this.levelModel.getGroundLevelModel()[x][y + 1];
|
||||
DisplayableElementModel elementLeft = this.levelModel.getGroundLevelModel()[x - 1][y];
|
||||
DisplayableElementModel elementRight = this.levelModel.getGroundLevelModel()[x + 1][y];
|
||||
DisplayableElementModel elementBelow = this.levelModel.getElementBelow(x, y);
|
||||
DisplayableElementModel elementLeft = this.levelModel.getElementLeft(x, y);
|
||||
DisplayableElementModel elementRight = this.levelModel.getElementRight(x, y);
|
||||
|
||||
String spriteNameBelow = elementBelow.getSpriteName();
|
||||
String spriteNameLeft = elementLeft.getSpriteName();
|
||||
@ -122,12 +128,13 @@ public class BoulderAndDiamondController extends AbstractLevelController impleme
|
||||
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") {
|
||||
if (this.levelModel.getElementBelowLeft(x, y).getSpriteName() == "black") {
|
||||
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);
|
||||
}
|
||||
} else if (spriteNameBelow == "rockford" && this.levelModel.getGroundLevelModel()[x][y].isFalling()) {
|
||||
} else {
|
||||
if (spriteNameBelow == "rockford" && element.isFalling()) {
|
||||
this.levelModel.exploseGround(x, y + 1);
|
||||
|
||||
AUDIO_LOAD_HELPER.playSound("die");
|
||||
@ -140,23 +147,26 @@ public class BoulderAndDiamondController extends AbstractLevelController impleme
|
||||
|
||||
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()) {
|
||||
if (element.getSpriteName() == "boulder"
|
||||
&& (elementTwoBelow.getSpriteName() == "dirt" ||
|
||||
elementTwoBelow.getSpriteName() == "black")) {
|
||||
if(element.isConvertible()) {
|
||||
this.levelModel.transformThisBoulderIntoADiamond(x, y);
|
||||
} else {
|
||||
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);
|
||||
} 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);
|
||||
} 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);
|
||||
} 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
|
||||
* <p>
|
||||
*
|
||||
* 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
|
||||
* the view when there are changes on it.
|
||||
@ -449,6 +449,38 @@ public class LevelModel extends Observable implements Runnable {
|
||||
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
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user