Fix explosives bugs

This commit is contained in:
Katchan 2021-12-07 15:55:51 +01:00
parent 0e8a46421f
commit ca756c6e01
2 changed files with 6 additions and 3 deletions

View File

@ -27,16 +27,17 @@ public class Bomb extends Explosive implements CountdownBox {
@Override @Override
public void update() { public void update() {
Grid grid = game.getGrid();
counter--; counter--;
if(counter == 0) { if(counter == 0) {
for(int i = -EXPLOSION_SIZE; i < EXPLOSION_SIZE; i++) { for(int i = -EXPLOSION_SIZE; i < EXPLOSION_SIZE; i++) {
for(int j = -EXPLOSION_SIZE; j < EXPLOSION_SIZE; j++) { for(int j = -EXPLOSION_SIZE; j < EXPLOSION_SIZE; j++) {
if(pythagoras(i, j) <= EXPLOSION_SIZE) { // recherche en cercle, pas en carré if(pythagoras(i, j) <= EXPLOSION_SIZE) { // recherche en cercle, pas en carré
Grid grid = game.getGrid();
Point position = new Point(point.getA() + i, point.getB() + j); Point position = new Point(point.getA() + i, point.getB() + j);
if(position.getA() >= 0 && position.getA() < grid.getRow() if(position.getA() >= 0 && position.getA() < grid.getRow()
&& position.getB() >= 0 && position.getB() < grid.getColumn()) { && position.getB() >= 0 && position.getB() < grid.getColumn()) {
interact(grid, null, position); Player player = grid.getBoard().get(position).getA();
interact(grid, player, position);
} }
} }
} }

View File

@ -8,6 +8,8 @@ public abstract class Explosive extends AbstractBox implements InteractiveBox {
@Override @Override
public void interact(Grid grid, Player player, Point position) { public void interact(Grid grid, Player player, Point position) {
if(grid.getBoard().get(position).getB() == this){
grid.getBoard().get(position).setB(null); grid.getBoard().get(position).setB(null);
} }
}
} }