fix DropBomb, DropMine and Shot not using the correct Direction implementation, delete debug messages
This commit is contained in:
parent
af5cbf80c1
commit
80b737ad5f
@ -143,7 +143,6 @@ public class App extends Application {
|
|||||||
default -> throw new IllegalArgumentException("Unknown argument: " + str);
|
default -> throw new IllegalArgumentException("Unknown argument: " + str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
System.out.println("oui");
|
|
||||||
if(playerClass != null)
|
if(playerClass != null)
|
||||||
playerList.add(createNewPlayer(playerClass,
|
playerList.add(createNewPlayer(playerClass,
|
||||||
classPlayer != null ? classPlayer : ClassPlayer.DEFAULT, playerList.size())
|
classPlayer != null ? classPlayer : ClassPlayer.DEFAULT, playerList.size())
|
||||||
|
@ -98,6 +98,12 @@ public class Game {
|
|||||||
try {
|
try {
|
||||||
actions.add(new Move(this, player, direction));
|
actions.add(new Move(this, player, direction));
|
||||||
} catch (NotValidDirectionException ignored){}
|
} catch (NotValidDirectionException ignored){}
|
||||||
|
try {
|
||||||
|
actions.add(new Shot(this, player, direction));
|
||||||
|
} catch (NotValidDirectionException | NoMoreBulletInWeaponException ignored) {}
|
||||||
|
|
||||||
|
}
|
||||||
|
for(Direction8Axis direction : Direction8Axis.values()) {
|
||||||
try {
|
try {
|
||||||
actions.add(new DropBomb(this, player, direction));
|
actions.add(new DropBomb(this, player, direction));
|
||||||
} catch (NotValidDirectionException ignored) {}
|
} catch (NotValidDirectionException ignored) {}
|
||||||
@ -105,11 +111,6 @@ public class Game {
|
|||||||
actions.add(new DropMine(this, player, direction));
|
actions.add(new DropMine(this, player, direction));
|
||||||
} catch (NotValidDirectionException ignored) {}
|
} catch (NotValidDirectionException ignored) {}
|
||||||
}
|
}
|
||||||
for(Direction8Axis direction : Direction8Axis.values()) {
|
|
||||||
try {
|
|
||||||
actions.add(new Shot(this, player, direction));
|
|
||||||
} catch (NotValidDirectionException | NoMoreBulletInWeaponException ignored) {}
|
|
||||||
}
|
|
||||||
actions.addAll(Arrays.asList(new Nothing(), new DeployShield(player)));
|
actions.addAll(Arrays.asList(new Nothing(), new DeployShield(player)));
|
||||||
return actions;
|
return actions;
|
||||||
}
|
}
|
||||||
|
@ -5,17 +5,19 @@ package fr.lnl.game.server.games.action;
|
|||||||
*/
|
*/
|
||||||
public enum Direction4Axis implements Direction {
|
public enum Direction4Axis implements Direction {
|
||||||
|
|
||||||
UP(-1, 0),
|
UP(-1, 0, true),
|
||||||
DOWN(1, 0),
|
DOWN(1, 0, true),
|
||||||
LEFT(0, -1),
|
LEFT(0, -1, false),
|
||||||
RIGHT(0, 1);
|
RIGHT(0, 1, false);
|
||||||
|
|
||||||
private final int deltaX;
|
private final int deltaX;
|
||||||
private final int deltaY;
|
private final int deltaY;
|
||||||
|
private final boolean isVertical;
|
||||||
|
|
||||||
Direction4Axis(int i, int i1) {
|
Direction4Axis(int i, int i1, boolean isVertical) {
|
||||||
this.deltaX = i;
|
this.deltaX = i;
|
||||||
this.deltaY = i1;
|
this.deltaY = i1;
|
||||||
|
this.isVertical = isVertical;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -27,4 +29,13 @@ public enum Direction4Axis implements Direction {
|
|||||||
public int getDeltaY() {
|
public int getDeltaY() {
|
||||||
return deltaY;
|
return deltaY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used by {@link Shot} to know if the direction is in vertical direction cause shot action can have a different
|
||||||
|
* distance depending on the direction
|
||||||
|
* @return true if the direction is vertical
|
||||||
|
*/
|
||||||
|
public boolean isVertical() {
|
||||||
|
return isVertical;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,23 +2,21 @@ package fr.lnl.game.server.games.action;
|
|||||||
|
|
||||||
public enum Direction8Axis implements Direction {
|
public enum Direction8Axis implements Direction {
|
||||||
|
|
||||||
UP(-1, 0, true),
|
UP(-1, 0),
|
||||||
DOWN(1, 0, true),
|
DOWN(1, 0),
|
||||||
LEFT(0, -1, false),
|
LEFT(0, -1),
|
||||||
RIGHT(0, 1, false),
|
RIGHT(0, 1),
|
||||||
UP_LEFT(-1, -1, true),
|
UP_LEFT(-1, -1),
|
||||||
UP_RIGHT(-1, 1, true),
|
UP_RIGHT(-1, 1),
|
||||||
DOWN_RIGHT(1, 1, true),
|
DOWN_RIGHT(1, 1),
|
||||||
DOWN_LEFT(1, -1, true);
|
DOWN_LEFT(1, -1);
|
||||||
|
|
||||||
private final int deltaX;
|
private final int deltaX;
|
||||||
private final int deltaY;
|
private final int deltaY;
|
||||||
private final boolean isVertical;
|
|
||||||
|
|
||||||
Direction8Axis(int i, int i1, boolean isVertical) {
|
Direction8Axis(int i, int i1) {
|
||||||
this.deltaX = i;
|
this.deltaX = i;
|
||||||
this.deltaY = i1;
|
this.deltaY = i1;
|
||||||
this.isVertical = isVertical;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -31,14 +29,5 @@ public enum Direction8Axis implements Direction {
|
|||||||
return deltaY;
|
return deltaY;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Used by {@link Shot} to know if the direction is in vertical direction cause shot action can have a different
|
|
||||||
* distance depending of the direction
|
|
||||||
* @return true if the direction is vertical
|
|
||||||
*/
|
|
||||||
public boolean isVertical() {
|
|
||||||
return isVertical;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ import fr.lnl.game.server.games.player.Player;
|
|||||||
*/
|
*/
|
||||||
public class DropBomb extends DropObject {
|
public class DropBomb extends DropObject {
|
||||||
|
|
||||||
public DropBomb(Game game, Player player, Direction4Axis direction) throws NotValidDirectionException {
|
public DropBomb(Game game, Player player, Direction8Axis direction) throws NotValidDirectionException {
|
||||||
super(game, player, direction);
|
super(game, player, direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ import fr.lnl.game.server.games.player.Player;
|
|||||||
*/
|
*/
|
||||||
public class DropMine extends DropObject {
|
public class DropMine extends DropObject {
|
||||||
|
|
||||||
public DropMine(Game game, Player player, Direction4Axis direction) throws NotValidDirectionException {
|
public DropMine(Game game, Player player, Direction8Axis direction) throws NotValidDirectionException {
|
||||||
super(game, player, direction);
|
super(game, player, direction);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,14 +16,14 @@ import java.util.List;
|
|||||||
public abstract class DropObject extends AbstractAction {
|
public abstract class DropObject extends AbstractAction {
|
||||||
|
|
||||||
protected final Point point;
|
protected final Point point;
|
||||||
private final Direction4Axis direction;
|
private final Direction8Axis direction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param player basically current player
|
* @param player basically current player
|
||||||
* @param direction chosen direction
|
* @param direction chosen direction
|
||||||
* @throws NotValidDirectionException throw when the chosen direction is invalid
|
* @throws NotValidDirectionException throw when the chosen direction is invalid
|
||||||
*/
|
*/
|
||||||
public DropObject(Game game, Player player, Direction4Axis direction) throws NotValidDirectionException {
|
public DropObject(Game game, Player player, Direction8Axis direction) throws NotValidDirectionException {
|
||||||
super(game, player);
|
super(game, player);
|
||||||
List<Point> points = getValidPoint();
|
List<Point> points = getValidPoint();
|
||||||
Point playerPosition = player.getPosition();
|
Point playerPosition = player.getPosition();
|
||||||
@ -67,7 +67,7 @@ public abstract class DropObject extends AbstractAction {
|
|||||||
return listMoves;
|
return listMoves;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Direction4Axis getDirection() {
|
public Direction8Axis getDirection() {
|
||||||
return direction;
|
return direction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,9 +12,9 @@ import java.util.List;
|
|||||||
public class Shot extends AbstractAction {
|
public class Shot extends AbstractAction {
|
||||||
|
|
||||||
private final Point point;
|
private final Point point;
|
||||||
private final Direction8Axis direction;
|
private final Direction4Axis direction;
|
||||||
|
|
||||||
public Shot(Game game, Player player, Direction8Axis direction) throws NoMoreBulletInWeaponException, NotValidDirectionException {
|
public Shot(Game game, Player player, Direction4Axis direction) throws NoMoreBulletInWeaponException, NotValidDirectionException {
|
||||||
super(game, player);
|
super(game, player);
|
||||||
if(player.getWeapon().getBullet() == 0) {
|
if(player.getWeapon().getBullet() == 0) {
|
||||||
throw new NoMoreBulletInWeaponException();
|
throw new NoMoreBulletInWeaponException();
|
||||||
@ -75,7 +75,7 @@ public class Shot extends AbstractAction {
|
|||||||
List<Point> listMoves = new ArrayList<>();
|
List<Point> listMoves = new ArrayList<>();
|
||||||
Point position = game.getCurrentPlayer().getPosition();
|
Point position = game.getCurrentPlayer().getPosition();
|
||||||
Weapon weapon = game.getCurrentPlayer().getWeapon();
|
Weapon weapon = game.getCurrentPlayer().getWeapon();
|
||||||
for(Direction8Axis direction : Direction8Axis.values()) {
|
for(Direction4Axis direction : Direction4Axis.values()) {
|
||||||
Point neighbour = seeNeighbour(position, direction.getDeltaX(), direction.getDeltaY(),
|
Point neighbour = seeNeighbour(position, direction.getDeltaX(), direction.getDeltaY(),
|
||||||
direction.isVertical() ? weapon.getVerticalDistance() : weapon.getHorizontalDistance());
|
direction.isVertical() ? weapon.getVerticalDistance() : weapon.getHorizontalDistance());
|
||||||
if(neighbour != null)
|
if(neighbour != null)
|
||||||
@ -102,7 +102,6 @@ public class Shot extends AbstractAction {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if(game.getGrid().getBoard().get(neighbour).getA() instanceof Player) {
|
if(game.getGrid().getBoard().get(neighbour).getA() instanceof Player) {
|
||||||
System.out.println(game.getGrid().getBoard().get(neighbour).getA().getPosition());
|
|
||||||
return neighbour;
|
return neighbour;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ public class ActionPlayerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void shotActionTest(){
|
public void shotActionTest(){
|
||||||
Action shot = null;
|
Action shot = null;
|
||||||
for(Direction8Axis direction : Direction8Axis.values()) {
|
for(Direction4Axis direction : Direction4Axis.values()) {
|
||||||
try {
|
try {
|
||||||
shot = new Shot(game, game.getCurrentPlayer(), direction);
|
shot = new Shot(game, game.getCurrentPlayer(), direction);
|
||||||
break;
|
break;
|
||||||
@ -84,8 +84,8 @@ public class ActionPlayerTest {
|
|||||||
public void dropBombActionTest() {
|
public void dropBombActionTest() {
|
||||||
Player player = game.getCurrentPlayer();
|
Player player = game.getCurrentPlayer();
|
||||||
Action action = null;
|
Action action = null;
|
||||||
Direction4Axis savedDirection = null;
|
Direction8Axis savedDirection = null;
|
||||||
for(Direction4Axis direction : Direction4Axis.values()) {
|
for(Direction8Axis direction : Direction8Axis.values()) {
|
||||||
try {
|
try {
|
||||||
action = new DropBomb(game, game.getCurrentPlayer(), direction);
|
action = new DropBomb(game, game.getCurrentPlayer(), direction);
|
||||||
savedDirection = direction;
|
savedDirection = direction;
|
||||||
|
Loading…
Reference in New Issue
Block a user