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.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,6 +40,7 @@ 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(row == getGame().getGrid().getRow() || column == getGame().getGrid().getColumn()){
|
||||||
if(Grid.caseisValid(position.getA(),row,position.getB(),column)){
|
if(Grid.caseisValid(position.getA(),row,position.getB(),column)){
|
||||||
Point neighbour = new Point(position.getA() + row, position.getB() + column);
|
Point neighbour = new Point(position.getA() + row, position.getB() + column);
|
||||||
Pair<Player, Box> state = board.get(neighbour);
|
Pair<Player, Box> state = board.get(neighbour);
|
||||||
@ -42,6 +50,7 @@ public class Move extends AbstractAction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return listMoves;
|
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(){
|
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));
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user