Skip to content

Commit

Permalink
Bug Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
luigi-borriello00 committed Jun 25, 2021
2 parents 0d98fbd + 83ee451 commit 8ffa728
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package bomberone.model.bombergameboard;

import bomberone.model.common.P2d;

import bomberone.model.common.Maps;
import bomberone.model.pathfinding.gameboard.BoardPoint;
import bomberone.model.pathfinding.gameboard.BoardPointImpl;
Expand All @@ -21,6 +22,14 @@ public final class BomberOneBoard extends GameBoard {

private BomberOneBoard() {
super(Maps.MAP1.getList());

for (int i = 0; i < this.getRowsQuantity(); i++) {
for (int j = 0; j < this.getColumnsQuantity(); j++) {
if (Maps.MAP1.getList().get(i).get(j).equals("H")) {
this.setItem(new BoardPointImpl(i, j, Markers.NOTACCESSIBLE));
}
}
}
}

/**
Expand Down
18 changes: 12 additions & 6 deletions src/main/java/bomberone/model/enemy/EnemyImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,14 @@ public final class EnemyImpl extends MoveableObjectImpl implements Enemy {
* This constant is the enemy speed in the hard mode.
*/
private static final int HIGH_SPEED = 200;

private Difficulty mode;
private Actions behavior;
private int frameCounter;
private int animationCounter;
private int nextMoveFrameCounter;
private boolean isHittable = false;
private boolean playerFound = false;

/* Constructors. */
public EnemyImpl(final P2d position, final int lifes, final Difficulty gameMode) {
Expand All @@ -69,8 +71,12 @@ public EnemyImpl(final P2d position, final int lifes, final Difficulty gameMode)
// move.
this.nextMoveFrameCounter = NEXT_MOVE_FRAME_QUANTITY;

if (gameMode.equals(Difficulty.EASY)) {
this.setSpeed(LOW_SPEED);
} else {
this.setSpeed(HIGH_SPEED);
}
this.mode = gameMode;
this.setSpeed(LOW_SPEED);
this.animationCounter = 0;
this.behavior = new BasicBehavior(this);
}
Expand All @@ -86,20 +92,20 @@ public void update(final int elapsed) {
if (this.frameCounter > 0) {
this.frameCounter--;
} else {

if (!this.isHittable) {
this.isHittable = true;
}

// The enemy has to wait some frames before the next move.
if (++this.nextMoveFrameCounter >= NEXT_MOVE_FRAME_QUANTITY) {

if (this.mode.equals(Difficulty.HARD)) {
BoardPoint enemyPosition = BomberOneBoard.getInstance().convertPosition(this.getPosition());
boolean playerFound = BomberOneBoard.getInstance().isSpotVisible(enemyPosition.getX(),
enemyPosition.getY());
if (playerFound && this.behavior.getClass() == BasicBehavior.class) {
this.behavior = new HardBehavior(this, new BFSSearch(BomberOneBoard.getInstance()));
this.setSpeed(HIGH_SPEED);
} else {
BoardPoint enemyPosition = BomberOneBoard.getInstance().convertPosition(this.getPosition());
playerFound = BomberOneBoard.getInstance().isSpotVisible(enemyPosition.getX(),
enemyPosition.getY());
}
}
this.nextMoveFrameCounter = 0;
Expand Down

0 comments on commit 8ffa728

Please sign in to comment.