Improved interaction with box
This commit is contained in:
parent
01d855435e
commit
4b5f9b719d
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,14 @@
|
||||
package fr.lnl.game.server.games.grid;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user