Deletion of the notion of cardinal for a wall

This commit is contained in:
Katchan 2021-12-03 15:45:09 +01:00
parent 0a4e706e07
commit daa07887f7
6 changed files with 21 additions and 83 deletions

View File

@ -5,7 +5,6 @@ import fr.lnl.game.server.games.grid.EnergyBall;
import fr.lnl.game.server.games.grid.Mine; import fr.lnl.game.server.games.grid.Mine;
import fr.lnl.game.server.games.grid.Wall; import fr.lnl.game.server.games.grid.Wall;
import fr.lnl.game.server.games.player.Player; import fr.lnl.game.server.games.player.Player;
import fr.lnl.game.server.utils.Cardinal;
import javafx.scene.image.Image; import javafx.scene.image.Image;
import javafx.scene.image.ImageView; import javafx.scene.image.ImageView;
import javafx.scene.layout.StackPane; import javafx.scene.layout.StackPane;
@ -48,24 +47,7 @@ public class Cell extends Rectangle {
image = new Image("/images/mine.webp"); image = new Image("/images/mine.webp");
} }
else{ else{
//test image = new Image("/images/wall.jpg");
if(((Wall)object).getCardinal()== Cardinal.NORTH){
image = new Image("/images/topWall.png");
}else if(((Wall)object).getCardinal()== Cardinal.SOUTH) {
image = new Image("/images/bottomWall.png");
}else if(((Wall)object).getCardinal()== Cardinal.EAST) {
image = new Image("/images/rightWall.png");
}else if(((Wall)object).getCardinal()== Cardinal.WEST) {
image = new Image("/images/rightWall.png"); // TODO: 03/12/2021 a replace par leftWall
}else if(((Wall)object).getCardinal()== Cardinal.NORTH_EAST) {
image = new Image("/images/topRightWall.png");
}else if(((Wall)object).getCardinal()== Cardinal.NORTH_WEST) {
image = new Image("/images/topLeftWall.png");
}else if(((Wall)object).getCardinal()== Cardinal.SOUTH_EAST) {
image = new Image("/images/bottomRightWall.png");
}else{
image = new Image("/images/bottomLeftWall.png");
}
} }
ImageView iv = new ImageView(image); ImageView iv = new ImageView(image);

View File

@ -1,7 +1,6 @@
package fr.lnl.game.server.games.grid; package fr.lnl.game.server.games.grid;
import fr.lnl.game.server.games.player.Player; import fr.lnl.game.server.games.player.Player;
import fr.lnl.game.server.utils.Cardinal;
import fr.lnl.game.server.utils.Pair; import fr.lnl.game.server.utils.Pair;
import fr.lnl.game.server.utils.Point; import fr.lnl.game.server.utils.Point;
@ -35,21 +34,21 @@ public class Grid {
for (int j = 0; j < column; j++) { for (int j = 0; j < column; j++) {
Box box; Box box;
if (i == 0 && j == 0) { if (i == 0 && j == 0) {
box = new Wall(Cardinal.NORTH_WEST, i, j); box = new Wall(i, j);
} else if (i == 0 && j == column-1) { } else if (i == 0 && j == column-1) {
box = new Wall(Cardinal.NORTH_EAST, i, j); box = new Wall(i, j);
} else if (i == row-1 && j == 0) { } else if (i == row-1 && j == 0) {
box = new Wall(Cardinal.SOUTH_WEST, i, j); box = new Wall(i, j);
} else if (i == row-1 && j == column-1) { } else if (i == row-1 && j == column-1) {
box = new Wall(Cardinal.SOUTH_EAST, i, j); box = new Wall(i, j);
} else if (i == 0) { } else if (i == 0) {
box = new Wall(Cardinal.NORTH, i, j); box = new Wall(i, j);
} else if (i == row-1) { } else if (i == row-1) {
box = new Wall(Cardinal.SOUTH, i, j); box = new Wall(i, j);
} else if (j == 0) { } else if (j == 0) {
box = new Wall(Cardinal.WEST, i, j); box = new Wall(i, j);
} else if (j == column-1) { } else if (j == column-1) {
box = new Wall(Cardinal.EAST, i, j); box = new Wall(i, j);
} else { } else {
box = null; box = null;
} }
@ -97,7 +96,7 @@ public class Grid {
if(Math.random() >= probability){ if(Math.random() >= probability){
Point point = new Point(i,j); Point point = new Point(i,j);
if(getIllusionNumberWallNeighbour(point) <= 3){ if(getIllusionNumberWallNeighbour(point) <= 3){
getBoard().get(point).setB(new Wall(Cardinal.getRandom(),i,j)); getBoard().get(point).setB(new Wall(i,j));
} }
else{ else{
getBoard().get(point).setB(new AbstractBox()); getBoard().get(point).setB(new AbstractBox());
@ -170,23 +169,7 @@ public class Grid {
str.append(" \033[0;34mP\033[0m"); str.append(" \033[0;34mP\033[0m");
} }
else if (value.getB() instanceof Wall) { else if (value.getB() instanceof Wall) {
if (((Wall) value.getB()).getCardinal() == Cardinal.NORTH) { str.append(" \033[0;32m□\033[0m");
str.append(" \033[0;34m—\033[0m");
} else if (((Wall) value.getB()).getCardinal() == Cardinal.SOUTH) {
str.append(" \033[0;31m—\033[0m");
} else if (((Wall) value.getB()).getCardinal() == Cardinal.WEST) {
str.append(" \033[0;33m|\033[0m");
} else if (((Wall) value.getB()).getCardinal() == Cardinal.EAST) {
str.append(" \033[0;32m|\033[0m");
} else if (((Wall) value.getB()).getCardinal() == Cardinal.NORTH_EAST) {
str.append(" \033[0;32mN\033[0m");
} else if (((Wall) value.getB()).getCardinal() == Cardinal.NORTH_WEST) {
str.append(" \033[0;33mN\033[0m");
} else if (((Wall) value.getB()).getCardinal() == Cardinal.SOUTH_EAST) {
str.append(" \033[0;32mS\033[0m");
} else if (((Wall) value.getB()).getCardinal() == Cardinal.SOUTH_WEST) {
str.append(" \033[0;33mS\033[0m");
}
} }
else if(value.getB() instanceof EnergyBall){ else if(value.getB() instanceof EnergyBall){
str.append(" \033[0;31mE\033[0m"); str.append(" \033[0;31mE\033[0m");

View File

@ -1,24 +1,17 @@
package fr.lnl.game.server.games.grid; package fr.lnl.game.server.games.grid;
import fr.lnl.game.server.utils.Cardinal;
import java.util.Objects; import java.util.Objects;
public class Wall extends AbstractBox { public class Wall extends AbstractBox {
private final Cardinal cardinal;
private final int x; private final int x;
private final int y; private final int y;
public Wall(Cardinal cardinal, int x, int y){ public Wall(int x, int y){
this.cardinal = cardinal;
this.x = x; this.x = x;
this.y = y; this.y = y;
} }
public Cardinal getCardinal() {
return cardinal;
}
public int getX() { public int getX() {
return x; return x;
@ -33,6 +26,6 @@ public class Wall extends AbstractBox {
if (this == o) return true; if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false; if (o == null || getClass() != o.getClass()) return false;
Wall other = (Wall) o; Wall other = (Wall) o;
return Objects.equals(cardinal, other.cardinal) && x == other.x && y == other.y; return x == other.x && y == other.y;
} }
} }

View File

@ -1,18 +0,0 @@
package fr.lnl.game.server.utils;
public enum Cardinal {
NORTH,
SOUTH,
EAST,
WEST,
NORTH_EAST,
NORTH_WEST,
SOUTH_EAST,
SOUTH_WEST;
public static Cardinal getRandom() {
return values()[(int) (Math.random() * values().length)];
}
}

View File

@ -6,7 +6,6 @@ import fr.lnl.game.server.games.grid.EnergyBall;
import fr.lnl.game.server.games.grid.Grid; import fr.lnl.game.server.games.grid.Grid;
import fr.lnl.game.server.games.grid.Wall; import fr.lnl.game.server.games.grid.Wall;
import fr.lnl.game.server.games.player.Player; import fr.lnl.game.server.games.player.Player;
import fr.lnl.game.server.utils.Cardinal;
import fr.lnl.game.server.utils.Pair; import fr.lnl.game.server.utils.Pair;
import fr.lnl.game.server.utils.Point; import fr.lnl.game.server.utils.Point;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
@ -29,10 +28,10 @@ public class GridTest {
@Test @Test
public void testGrid() { public void testGrid() {
// test Grid#initGrid() // test Grid#initGrid()
assertEquals(new Wall(Cardinal.NORTH_WEST, 0, 0), grid.getBoard().get(new Point(0,0)).getB()); assertEquals(new Wall(0, 0), grid.getBoard().get(new Point(0,0)).getB());
assertEquals(new Wall(Cardinal.NORTH_EAST, 0, grid.getColumn() - 1), grid.getBoard().get(new Point(0, grid.getColumn() - 1)).getB()); assertEquals(new Wall(0, grid.getColumn() - 1), grid.getBoard().get(new Point(0, grid.getColumn() - 1)).getB());
assertEquals(new Wall(Cardinal.SOUTH_WEST, grid.getRow() - 1, 0), grid.getBoard().get(new Point(grid.getRow() - 1, 0)).getB()); assertEquals(new Wall(grid.getRow() - 1, 0), grid.getBoard().get(new Point(grid.getRow() - 1, 0)).getB());
assertEquals(new Wall(Cardinal.SOUTH_EAST, grid.getRow() - 1, grid.getColumn() - 1), grid.getBoard().get(new Point(grid.getRow() - 1, grid.getColumn() - 1)).getB()); assertEquals(new Wall(grid.getRow() - 1, grid.getColumn() - 1), grid.getBoard().get(new Point(grid.getRow() - 1, grid.getColumn() - 1)).getB());
// test placePlayersBRUT (mocked) // test placePlayersBRUT (mocked)
assertEquals(grid.getPlayers().get(0), grid.getBoard().get(new Point(7, 7)).getA()); assertEquals(grid.getPlayers().get(0), grid.getBoard().get(new Point(7, 7)).getA());
assertEquals(grid.getPlayers().get(1), grid.getBoard().get(new Point(7, 8)).getA()); assertEquals(grid.getPlayers().get(1), grid.getBoard().get(new Point(7, 8)).getA());

View File

@ -8,7 +8,6 @@ import fr.lnl.game.server.games.player.ClassPlayer;
import fr.lnl.game.server.games.player.Player; import fr.lnl.game.server.games.player.Player;
import fr.lnl.game.server.games.player.RandomComputerPlayer; import fr.lnl.game.server.games.player.RandomComputerPlayer;
import fr.lnl.game.server.listener.GameFinishEvent; import fr.lnl.game.server.listener.GameFinishEvent;
import fr.lnl.game.server.utils.Cardinal;
import fr.lnl.game.server.utils.Point; import fr.lnl.game.server.utils.Point;
import java.util.Arrays; import java.util.Arrays;
@ -39,10 +38,10 @@ public class Mock {
} }
public void placeInternWallBRUT(){ public void placeInternWallBRUT(){
grid.getBoard().get(new Point(3,6)).setB(new Wall(Cardinal.NORTH,3,6)); grid.getBoard().get(new Point(3,6)).setB(new Wall(3,6));
grid.getBoard().get(new Point(7,14)).setB(new Wall(Cardinal.SOUTH,7,14)); grid.getBoard().get(new Point(7,14)).setB(new Wall(7,14));
grid.getBoard().get(new Point(10,7)).setB(new Wall(Cardinal.EAST,10,7)); grid.getBoard().get(new Point(10,7)).setB(new Wall(10,7));
grid.getBoard().get(new Point(14,2)).setB(new Wall(Cardinal.WEST,14,2)); grid.getBoard().get(new Point(14,2)).setB(new Wall(14,2));
} }
} }