Add move doAction
This commit is contained in:
parent
f5ba25843c
commit
cd166fa809
@ -11,6 +11,7 @@ import fr.lnl.game.server.utils.Point;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class Move extends AbstractAction {
|
||||
public Move(Game game) {
|
||||
@ -19,7 +20,13 @@ public class Move extends AbstractAction {
|
||||
|
||||
@Override
|
||||
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
|
||||
@ -33,6 +40,7 @@ public class Move extends AbstractAction {
|
||||
Point position = getGame().getCurrent_player().getPoint();
|
||||
for (int row = -1; row <= 1; row++) {
|
||||
for (int column = -1; column <= 1; column++) {
|
||||
if(row == getGame().getGrid().getRow() || column == getGame().getGrid().getColumn()){
|
||||
if(Grid.caseisValid(position.getA(),row,position.getB(),column)){
|
||||
Point neighbour = new Point(position.getA() + row, position.getB() + column);
|
||||
Pair<Player, Box> state = board.get(neighbour);
|
||||
@ -42,6 +50,7 @@ public class Move extends AbstractAction {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return listMoves;
|
||||
}
|
||||
|
||||
|
@ -49,28 +49,16 @@ public class Grid {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated A utiliser seulement pour les tests, voir GridTest dans le dossier test
|
||||
*/
|
||||
@Deprecated
|
||||
public void placePlayersBRUT(){
|
||||
board.get(new Point(1,1)).setA(players[0]);
|
||||
board.get(new Point(14,14)).setA(players[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated idem que {@link Grid#placePlayersBRUT()}
|
||||
*/
|
||||
@Deprecated
|
||||
public void placeEnergyBallBRUT(){
|
||||
board.get(new Point(2,3)).setB(new EnergyBall());
|
||||
board.get(new Point(7,10)).setB(new EnergyBall());
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated idem que {@link Grid#placePlayersBRUT()}
|
||||
*/
|
||||
@Deprecated
|
||||
public void placeInternWallBRUT(){
|
||||
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));
|
||||
|
@ -70,4 +70,8 @@ public abstract class AbstractPlayer implements Player {
|
||||
public void setPoint(Point point){
|
||||
this.point = point;
|
||||
}
|
||||
|
||||
public void decrementEnergy(int energy){
|
||||
this.energy -= energy;
|
||||
}
|
||||
}
|
||||
|
@ -17,4 +17,5 @@ public interface Player {
|
||||
Action[] getActions();
|
||||
ClassPlayer getClassPlayer();
|
||||
void setPoint(Point point);
|
||||
void decrementEnergy(int energy);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user