Improved interaction with box

This commit is contained in:
Quentin Legot 2021-11-07 15:15:27 +01:00
parent 01d855435e
commit 4b5f9b719d
6 changed files with 52 additions and 14 deletions

View File

@ -34,17 +34,8 @@ public class Move extends AbstractAction {
player.setPoint(this.point);
player.decrementEnergy(player.getClassPlayer().getMoveCost());
Box box = getGame().getGrid().getBoard().get(this.point).getB();
if (box instanceof Mine){
player.decrementEnergy(player.getClassPlayer().getPenaltyMine());
getGame().getGrid().getBoard().get(this.point).setB(null);
}
if(box instanceof Bomb){
player.decrementEnergy(player.getClassPlayer().getPenaltyBomb());
getGame().getGrid().getBoard().get(this.point).setB(null);
}
if(box instanceof EnergyBall){
player.incrementEnergy(player.getClassPlayer().getGainEnergy());
getGame().getGrid().getBoard().get(this.point).setB(null);
if(box instanceof InteractiveBox interactiveBox) {
interactiveBox.interact(getGame().getGrid(), player, this.point);
}
}

View File

@ -1,4 +1,14 @@
package fr.lnl.game.server.games.grid;
public class Bomb extends Explosive{
import fr.lnl.game.server.games.player.Player;
import fr.lnl.game.server.utils.Point;
public class Bomb extends Explosive {
@Override
public void interact(Grid grid, Player player, Point position) {
player.decrementEnergy(player.getClassPlayer().getPenaltyBomb());
super.interact(grid, player, position);
}
}

View File

@ -1,10 +1,19 @@
package fr.lnl.game.server.games.grid;
public class EnergyBall implements Box{
import fr.lnl.game.server.games.player.Player;
import fr.lnl.game.server.utils.Point;
public class EnergyBall implements Box, InteractiveBox {
@Override
public boolean equals(Object o) {
if (this == o) return true;
return o != null && getClass() == o.getClass();// no var to test
}
@Override
public void interact(Grid grid, Player player, Point position) {
player.incrementEnergy(player.getClassPlayer().getGainEnergy());
grid.getBoard().get(position).setB(null);
}
}

View File

@ -1,4 +1,12 @@
package fr.lnl.game.server.games.grid;
public abstract class Explosive implements Box{
import fr.lnl.game.server.games.player.Player;
import fr.lnl.game.server.utils.Point;
public abstract class Explosive implements Box, InteractiveBox {
@Override
public void interact(Grid grid, Player player, Point position) {
grid.getBoard().get(position).setB(null);
}
}

View File

@ -0,0 +1,11 @@
package fr.lnl.game.server.games.grid;
import fr.lnl.game.server.games.player.Player;
import fr.lnl.game.server.utils.Point;
public interface InteractiveBox {
void interact(Grid grid, Player player, Point position);
}

View File

@ -1,4 +1,13 @@
package fr.lnl.game.server.games.grid;
import fr.lnl.game.server.games.player.Player;
import fr.lnl.game.server.utils.Point;
public class Mine extends Explosive{
@Override
public void interact(Grid grid, Player player, Point position) {
player.decrementEnergy(player.getClassPlayer().getPenaltyMine());
super.interact(grid, player, position);
}
}