add javadoc to grid's elements, deleted useless x and y parameters in Wall, adjustments to bombs timer and explosion size
This commit is contained in:
parent
ea07ca0c6a
commit
8415739d18
@ -38,21 +38,21 @@ public class LockGridFactoryBuilder extends AbstractGridFactoryBuilder {
|
||||
for (int j = 0; j < getGrid().getColumn(); j++) {
|
||||
Box box;
|
||||
if (i == 0 && j == 0) {
|
||||
box = new Wall(i, j);
|
||||
box = new Wall();
|
||||
} else if (i == 0 && j == getGrid().getColumn()-1) {
|
||||
box = new Wall(i, j);
|
||||
box = new Wall();
|
||||
} else if (i == getGrid().getRow()-1 && j == 0) {
|
||||
box = new Wall(i, j);
|
||||
box = new Wall();
|
||||
} else if (i == getGrid().getRow()-1 && j == getGrid().getColumn()-1) {
|
||||
box = new Wall(i, j);
|
||||
box = new Wall();
|
||||
} else if (i == 0) {
|
||||
box = new Wall(i, j);
|
||||
box = new Wall();
|
||||
} else if (i == getGrid().getRow()-1) {
|
||||
box = new Wall(i, j);
|
||||
box = new Wall();
|
||||
} else if (j == 0) {
|
||||
box = new Wall(i, j);
|
||||
box = new Wall();
|
||||
} else if (j == getGrid().getColumn()-1) {
|
||||
box = new Wall(i, j);
|
||||
box = new Wall();
|
||||
} else {
|
||||
box = null;
|
||||
}
|
||||
@ -92,7 +92,7 @@ public class LockGridFactoryBuilder extends AbstractGridFactoryBuilder {
|
||||
if(Math.random() >= wallProbability){
|
||||
Point point = new Point(i,j);
|
||||
if(getIllusionNumberWallNeighbour(point) <= 3){
|
||||
getGrid().getBoard().get(point).setB(new Wall(i,j));
|
||||
getGrid().getBoard().get(point).setB(new Wall());
|
||||
}
|
||||
else{
|
||||
getGrid().getBoard().get(point).setB(new AbstractBox());
|
||||
@ -132,7 +132,7 @@ public class LockGridFactoryBuilder extends AbstractGridFactoryBuilder {
|
||||
* @param point the position where we want to place a new wall
|
||||
* @return number of walls and locked place around {@code position}
|
||||
*/
|
||||
public int getIllusionNumberWallNeighbour(Point point){
|
||||
private int getIllusionNumberWallNeighbour(Point point){
|
||||
int countWall = 0;
|
||||
for (int deltaRow = -1; deltaRow <= 1; deltaRow++){
|
||||
for (int deltaColomn = -1; deltaColomn <= 1; deltaColomn++) {
|
||||
|
@ -1,6 +1,10 @@
|
||||
package fr.lnl.game.server.games.grid.elements;
|
||||
|
||||
public class AbstractBox implements Box{
|
||||
/**
|
||||
* AbstractBox is instantiable (not an abstract class), but when it's the case, instance doesn't represent anything,
|
||||
* it's only to see if there is a lock on this position or not
|
||||
*/
|
||||
public class AbstractBox implements Box {
|
||||
|
||||
boolean lock;
|
||||
|
||||
|
@ -5,12 +5,24 @@ import fr.lnl.game.server.games.grid.Grid;
|
||||
import fr.lnl.game.server.games.player.Player;
|
||||
import fr.lnl.game.server.utils.Point;
|
||||
|
||||
/**
|
||||
* Bomb are elements which explode when someone walks on it or after a countdown, the explosion area is on multiple cases
|
||||
*/
|
||||
public class Bomb extends Explosive implements CountdownBox {
|
||||
|
||||
/**
|
||||
* Position of the bomb
|
||||
*/
|
||||
private final Point point;
|
||||
private final Game game;
|
||||
private int counter = 3;
|
||||
private static int EXPLOSION_SIZE = 4;
|
||||
/**
|
||||
* Timer before explosion
|
||||
*/
|
||||
private int counter = 5;
|
||||
/**
|
||||
* Explosion size, size is circle, not square
|
||||
*/
|
||||
private static final int EXPLOSION_SIZE = 2;
|
||||
|
||||
public Bomb(Point point, Game game) {
|
||||
super(game.getCurrentPlayer());
|
||||
@ -19,6 +31,14 @@ public class Bomb extends Explosive implements CountdownBox {
|
||||
counter = counter * game.getPlayers().size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrement players energy around this element
|
||||
* @param grid Game's grid
|
||||
* @param player the player who walks on this element
|
||||
* @param position position of this element on the grid
|
||||
* @see InteractiveBox#interact(Grid, Player, Point)
|
||||
* @see Explosive#interact(Grid, Player, Point)
|
||||
*/
|
||||
@Override
|
||||
public void interact(Grid grid, /* Nullable */ Player player, Point position) {
|
||||
if(player != null)
|
||||
@ -26,6 +46,10 @@ public class Bomb extends Explosive implements CountdownBox {
|
||||
super.interact(grid, player, position);
|
||||
}
|
||||
|
||||
/**
|
||||
* When the timer (counter) goes down to 0, the bomb explode
|
||||
* @see CountdownBox#update()
|
||||
*/
|
||||
@Override
|
||||
public void update() {
|
||||
Grid grid = game.getGrid();
|
||||
@ -46,6 +70,11 @@ public class Bomb extends Explosive implements CountdownBox {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param a adjacent side of a triangle
|
||||
* @param b opposite side of a triangle
|
||||
* @return Pythagoras' theorem value
|
||||
*/
|
||||
public double pythagoras(double a, double b) {
|
||||
return Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2));
|
||||
}
|
||||
|
@ -2,6 +2,11 @@ package fr.lnl.game.server.games.grid.elements;
|
||||
|
||||
public interface Box {
|
||||
|
||||
/**
|
||||
* @return true if this box is locked (can't place wall on this position)
|
||||
* @see fr.lnl.game.server.games.grid.build.LockGridFactoryBuilder
|
||||
*/
|
||||
boolean isLock();
|
||||
|
||||
void setLock(boolean lock);
|
||||
}
|
||||
|
@ -1,7 +1,13 @@
|
||||
package fr.lnl.game.server.games.grid.elements;
|
||||
|
||||
/**
|
||||
* A box implemented by CountdownBox is a box which do an action a certain time after being placed
|
||||
*/
|
||||
public interface CountdownBox {
|
||||
|
||||
/**
|
||||
* Call at each game tick (After a player do an action)
|
||||
*/
|
||||
void update();
|
||||
|
||||
}
|
||||
|
@ -4,17 +4,31 @@ import fr.lnl.game.server.games.grid.Grid;
|
||||
import fr.lnl.game.server.games.player.Player;
|
||||
import fr.lnl.game.server.utils.Point;
|
||||
|
||||
/**
|
||||
* An EnergyBall is a box which give back a bit of player energy after it walks on the ball
|
||||
*/
|
||||
public class EnergyBall extends AbstractBox implements InteractiveBox{
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
return o != null && getClass() == o.getClass();// no var to test
|
||||
}
|
||||
|
||||
/**
|
||||
* Increment energy of player who walks on this element
|
||||
* @param grid Game's grid
|
||||
* @param player the player who walks on this element
|
||||
* @param position position of this element on the grid
|
||||
* @see InteractiveBox#interact(Grid, Player, Point)
|
||||
*/
|
||||
@Override
|
||||
public void interact(Grid grid, Player player, Point position) {
|
||||
player.incrementEnergy(player.getClassPlayer().getGainEnergy());
|
||||
grid.getBoard().get(position).setB(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used by tests
|
||||
* @param obj the object to compare
|
||||
* @return true if obj is an instance of EnergyBall, false otherwise
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return obj instanceof EnergyBall;
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,9 @@ import fr.lnl.game.server.games.grid.Grid;
|
||||
import fr.lnl.game.server.games.player.Player;
|
||||
import fr.lnl.game.server.utils.Point;
|
||||
|
||||
/**
|
||||
* Super class of {@link Bomb} and {@link Mine}
|
||||
*/
|
||||
public abstract class Explosive extends AbstractBox implements InteractiveBox {
|
||||
|
||||
Player player;
|
||||
@ -12,6 +15,13 @@ public abstract class Explosive extends AbstractBox implements InteractiveBox {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy this element on explosion
|
||||
* @param grid Game's grid
|
||||
* @param player the player who walks on this element
|
||||
* @param position position of this element on the grid
|
||||
* @see InteractiveBox#interact(Grid, Player, Point)
|
||||
*/
|
||||
@Override
|
||||
public void interact(Grid grid, Player player, Point position) {
|
||||
if(grid.getBoard().get(position).getB() == this){
|
||||
|
@ -4,9 +4,17 @@ import fr.lnl.game.server.games.grid.Grid;
|
||||
import fr.lnl.game.server.games.player.Player;
|
||||
import fr.lnl.game.server.utils.Point;
|
||||
|
||||
/**
|
||||
* A box implemented by InteractiveBox is a box which do an action when someone walks on it
|
||||
*/
|
||||
public interface InteractiveBox {
|
||||
|
||||
|
||||
/**
|
||||
* Call when a player walk on it
|
||||
* @param grid Game's grid
|
||||
* @param player the player who walks on this element
|
||||
* @param position position of this element on the grid
|
||||
*/
|
||||
void interact(Grid grid, Player player, Point position);
|
||||
|
||||
}
|
||||
|
@ -4,12 +4,23 @@ import fr.lnl.game.server.games.grid.Grid;
|
||||
import fr.lnl.game.server.games.player.Player;
|
||||
import fr.lnl.game.server.utils.Point;
|
||||
|
||||
/**
|
||||
* A mine is an element which explose when someone walks on it, the explosion area is on 1 case only
|
||||
*/
|
||||
public class Mine extends Explosive{
|
||||
|
||||
public Mine(Player player) {
|
||||
super(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrement energy of the player who walks on this element
|
||||
* @param grid Game's grid
|
||||
* @param player the player who walks on this element
|
||||
* @param position position of this element on the grid
|
||||
* @see InteractiveBox#interact(Grid, Player, Point)
|
||||
* @see Explosive#interact(Grid, Player, Point)
|
||||
*/
|
||||
@Override
|
||||
public void interact(Grid grid, Player player, Point position) {
|
||||
player.decrementEnergy(player.getClassPlayer().getPenaltyMine());
|
||||
|
@ -1,29 +1,17 @@
|
||||
package fr.lnl.game.server.games.grid.elements;
|
||||
|
||||
/**
|
||||
* A wall is an intraversable object
|
||||
*/
|
||||
public class Wall extends AbstractBox {
|
||||
|
||||
private final int x;
|
||||
private final int y;
|
||||
|
||||
public Wall(int x, int y){
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used by tests
|
||||
* @param obj the object to compare
|
||||
* @return true if obj is an instance of wall, false otherwise
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Wall other = (Wall) o;
|
||||
return x == other.x && y == other.y;
|
||||
public boolean equals(Object obj) {
|
||||
return obj instanceof Wall;
|
||||
}
|
||||
}
|
||||
|
@ -36,10 +36,10 @@ public class GridTest {
|
||||
@Test
|
||||
public void testGrid() {
|
||||
// test Grid#initGrid()
|
||||
assertEquals(new Wall(0, 0), grid.getBoard().get(new Point(0,0)).getB());
|
||||
assertEquals(new Wall(0, grid.getColumn() - 1), grid.getBoard().get(new Point(0, grid.getColumn() - 1)).getB());
|
||||
assertEquals(new Wall(grid.getRow() - 1, 0), grid.getBoard().get(new Point(grid.getRow() - 1, 0)).getB());
|
||||
assertEquals(new Wall(grid.getRow() - 1, grid.getColumn() - 1), grid.getBoard().get(new Point(grid.getRow() - 1, grid.getColumn() - 1)).getB());
|
||||
assertEquals(new Wall(), grid.getBoard().get(new Point(0,0)).getB());
|
||||
assertEquals(new Wall(), grid.getBoard().get(new Point(0, grid.getColumn() - 1)).getB());
|
||||
assertEquals(new Wall(), grid.getBoard().get(new Point(grid.getRow() - 1, 0)).getB());
|
||||
assertEquals(new Wall(), grid.getBoard().get(new Point(grid.getRow() - 1, grid.getColumn() - 1)).getB());
|
||||
// test placePlayersBRUT (mocked)
|
||||
grid.getPlayers().forEach(p -> System.out.println(p.getId() + ": " + p.getPosition()));
|
||||
assertEquals(grid.getPlayers().get(0), grid.getBoard().get(new Point(7, 7)).getA());
|
||||
|
@ -15,7 +15,7 @@ public class Mock {
|
||||
|
||||
public Mock(List<Player> players) {
|
||||
this.buildStrategy = MockGridFactoryBuilder.create().gridDimensions(16, 16).playersList(players).wallProbability(0.80F).energyProbability(0.95F);
|
||||
game = new Game(buildStrategy, players, new MockDisplayWinner());
|
||||
game = new Game(buildStrategy, players);
|
||||
this.grid = game.getGrid();
|
||||
}
|
||||
|
||||
|
@ -25,10 +25,10 @@ public class MockGridFactoryBuilder extends LockGridFactoryBuilder {
|
||||
|
||||
@Override
|
||||
protected void initPlaceInternWall() {
|
||||
grid.getBoard().get(new Point(3,6)).setB(new Wall(3,6));
|
||||
grid.getBoard().get(new Point(7,14)).setB(new Wall(7,14));
|
||||
grid.getBoard().get(new Point(10,7)).setB(new Wall(10,7));
|
||||
grid.getBoard().get(new Point(14,2)).setB(new Wall(14,2));
|
||||
grid.getBoard().get(new Point(3,6)).setB(new Wall());
|
||||
grid.getBoard().get(new Point(7,14)).setB(new Wall());
|
||||
grid.getBoard().get(new Point(10,7)).setB(new Wall());
|
||||
grid.getBoard().get(new Point(14,2)).setB(new Wall());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user