Add move doAction

This commit is contained in:
Katchan 2021-10-21 17:19:05 +02:00
parent f5ba25843c
commit cd166fa809
4 changed files with 20 additions and 18 deletions

View File

@ -11,6 +11,7 @@ import fr.lnl.game.server.utils.Point;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Random;
public class Move extends AbstractAction { public class Move extends AbstractAction {
public Move(Game game) { public Move(Game game) {
@ -19,7 +20,13 @@ public class Move extends AbstractAction {
@Override @Override
public void doAction() { public void doAction() {
List<Point> points = getValidPoint();
Random random = new Random();
Point nextPositon = points.get(random.nextInt(0,points.size() - 1));
Player player = getGame().getCurrent_player();
getGame().getGrid().getBoard().get(player.getPoint()).setA(null);
getGame().getGrid().getBoard().get(nextPositon).setA(player);
player.decrementEnergy(player.getClassPlayer().getMoveCost());
} }
@Override @Override
@ -33,11 +40,13 @@ public class Move extends AbstractAction {
Point position = getGame().getCurrent_player().getPoint(); Point position = getGame().getCurrent_player().getPoint();
for (int row = -1; row <= 1; row++) { for (int row = -1; row <= 1; row++) {
for (int column = -1; column <= 1; column++) { for (int column = -1; column <= 1; column++) {
if(Grid.caseisValid(position.getA(),row,position.getB(),column)){ if(row == getGame().getGrid().getRow() || column == getGame().getGrid().getColumn()){
Point neighbour = new Point(position.getA() + row, position.getB() + column); if(Grid.caseisValid(position.getA(),row,position.getB(),column)){
Pair<Player, Box> state = board.get(neighbour); Point neighbour = new Point(position.getA() + row, position.getB() + column);
if(state.getA() == null || state.getB() instanceof Wall){ Pair<Player, Box> state = board.get(neighbour);
listMoves.add(neighbour); if(state.getA() == null || state.getB() instanceof Wall){
listMoves.add(neighbour);
}
} }
} }
} }

View File

@ -49,28 +49,16 @@ public class Grid {
} }
} }
/**
* @deprecated A utiliser seulement pour les tests, voir GridTest dans le dossier test
*/
@Deprecated
public void placePlayersBRUT(){ public void placePlayersBRUT(){
board.get(new Point(1,1)).setA(players[0]); board.get(new Point(1,1)).setA(players[0]);
board.get(new Point(14,14)).setA(players[1]); board.get(new Point(14,14)).setA(players[1]);
} }
/**
* @deprecated idem que {@link Grid#placePlayersBRUT()}
*/
@Deprecated
public void placeEnergyBallBRUT(){ public void placeEnergyBallBRUT(){
board.get(new Point(2,3)).setB(new EnergyBall()); board.get(new Point(2,3)).setB(new EnergyBall());
board.get(new Point(7,10)).setB(new EnergyBall()); board.get(new Point(7,10)).setB(new EnergyBall());
} }
/**
* @deprecated idem que {@link Grid#placePlayersBRUT()}
*/
@Deprecated
public void placeInternWallBRUT(){ public void placeInternWallBRUT(){
board.get(new Point(3,6)).setB(new Wall(Cardinal.NORTH,3,6)); board.get(new Point(3,6)).setB(new Wall(Cardinal.NORTH,3,6));
board.get(new Point(7,14)).setB(new Wall(Cardinal.SOUTH,7,14)); board.get(new Point(7,14)).setB(new Wall(Cardinal.SOUTH,7,14));

View File

@ -70,4 +70,8 @@ public abstract class AbstractPlayer implements Player {
public void setPoint(Point point){ public void setPoint(Point point){
this.point = point; this.point = point;
} }
public void decrementEnergy(int energy){
this.energy -= energy;
}
} }

View File

@ -17,4 +17,5 @@ public interface Player {
Action[] getActions(); Action[] getActions();
ClassPlayer getClassPlayer(); ClassPlayer getClassPlayer();
void setPoint(Point point); void setPoint(Point point);
void decrementEnergy(int energy);
} }