Merge remote-tracking branch 'origin/master'
@ -38,7 +38,7 @@ public class App extends Application {
|
|||||||
public static void startGame(ViewLambda lambda) throws IllegalArgumentException, InvocationTargetException, NoSuchMethodException,
|
public static void startGame(ViewLambda lambda) throws IllegalArgumentException, InvocationTargetException, NoSuchMethodException,
|
||||||
InstantiationException, IllegalAccessException {
|
InstantiationException, IllegalAccessException {
|
||||||
List<Player> players = parsePlayers();
|
List<Player> players = parsePlayers();
|
||||||
game = new Game(new Grid(12, 12, players), players, new GameFinishEvent());
|
game = new Game(new Grid(12, 12, players, 0.80F,0.95F), players, new GameFinishEvent());
|
||||||
for (Player player : game.getPlayers()) {
|
for (Player player : game.getPlayers()) {
|
||||||
playerList.put(player, new ClientPlayer(player, lambda.createViewLambda(player)));
|
playerList.put(player, new ClientPlayer(player, lambda.createViewLambda(player)));
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,8 @@ package fr.lnl.game.client.view;
|
|||||||
import fr.lnl.game.server.games.grid.Bomb;
|
import fr.lnl.game.server.games.grid.Bomb;
|
||||||
import fr.lnl.game.server.games.grid.EnergyBall;
|
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.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;
|
||||||
@ -37,17 +37,34 @@ public class Cell extends Rectangle {
|
|||||||
if(object instanceof Player){
|
if(object instanceof Player){
|
||||||
image = new Image("file:resources/images/player.png");
|
image = new Image("file:resources/images/player.png");
|
||||||
}
|
}
|
||||||
if(object instanceof EnergyBall){
|
else if(object instanceof EnergyBall){
|
||||||
image = new Image("file:resources/images/energyBall.png");
|
image = new Image("file:resources/images/energyBall.png");
|
||||||
}
|
}
|
||||||
if(object instanceof Bomb){
|
else if(object instanceof Bomb){
|
||||||
image = new Image("file:resources/images/bomb.jpg");
|
image = new Image("file:resources/images/bomb.jpg");
|
||||||
}
|
}
|
||||||
if(object instanceof Mine){
|
else if(object instanceof Mine){
|
||||||
image = new Image("file:resources/images/mine.webp");
|
image = new Image("file:resources/images/mine.webp");
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
image = new Image("file:resources/images/wall.jpg");
|
//test
|
||||||
|
if(((Wall)object).getCardinal()== Cardinal.NORTH){
|
||||||
|
image = new Image("file:resources/topWall.png");
|
||||||
|
}else if(((Wall)object).getCardinal()== Cardinal.SOUTH) {
|
||||||
|
image = new Image("file:resources/bottomWall.png");
|
||||||
|
}else if(((Wall)object).getCardinal()== Cardinal.EAST) {
|
||||||
|
image = new Image("file:resources/rightWall.png");
|
||||||
|
}else if(((Wall)object).getCardinal()== Cardinal.WEST) {
|
||||||
|
image = new Image("file:resources/leftWall.png");
|
||||||
|
}else if(((Wall)object).getCardinal()== Cardinal.NORTH_EAST) {
|
||||||
|
image = new Image("file:resources/topRightWall.png");
|
||||||
|
}else if(((Wall)object).getCardinal()== Cardinal.NORTH_WEST) {
|
||||||
|
image = new Image("file:resources/topLeftWall.png");
|
||||||
|
}else if(((Wall)object).getCardinal()== Cardinal.SOUTH_EAST) {
|
||||||
|
image = new Image("file:resources/bottomRightWall.png");
|
||||||
|
}else{
|
||||||
|
image = new Image("file:resources/bottomLeftWall.png");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageView iv = new ImageView(image);
|
ImageView iv = new ImageView(image);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package fr.lnl.game.client.view;
|
package fr.lnl.game.client.view;
|
||||||
|
|
||||||
import fr.lnl.game.server.listener.ModelListener;
|
|
||||||
import fr.lnl.game.client.listener.ButtonListener;
|
import fr.lnl.game.client.listener.ButtonListener;
|
||||||
|
import fr.lnl.game.server.listener.ModelListener;
|
||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
import javafx.event.EventHandler;
|
import javafx.event.EventHandler;
|
||||||
|
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
package fr.lnl.game.client.view;
|
package fr.lnl.game.client.view;
|
||||||
|
|
||||||
|
|
||||||
import fr.lnl.game.server.games.Game;
|
|
||||||
import fr.lnl.game.server.games.grid.*;
|
import fr.lnl.game.server.games.grid.*;
|
||||||
import fr.lnl.game.server.games.player.AbstractPlayer;
|
|
||||||
import fr.lnl.game.server.games.player.ClassPlayer;
|
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;
|
||||||
@ -52,9 +50,8 @@ public class GUI {
|
|||||||
private Parent createContent() {
|
private Parent createContent() {
|
||||||
Pane principalPane = new Pane();
|
Pane principalPane = new Pane();
|
||||||
principalPane.setPrefSize(width * cellSize, height * cellSize);
|
principalPane.setPrefSize(width * cellSize, height * cellSize);
|
||||||
//PARTIE1
|
|
||||||
//à définir avec n pour moduler la taille du plateau
|
|
||||||
|
|
||||||
|
//à définir avec n pour moduler la taille du plateau
|
||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
for (int j = 0; j < 16; j++) {
|
for (int j = 0; j < 16; j++) {
|
||||||
Cell cell = new Cell(i, j);
|
Cell cell = new Cell(i, j);
|
||||||
@ -62,7 +59,6 @@ public class GUI {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//PARTIE2
|
|
||||||
board = grid.getBoard();
|
board = grid.getBoard();
|
||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
for (int j = 0; j < 16; j++) {
|
for (int j = 0; j < 16; j++) {
|
||||||
@ -71,11 +67,20 @@ public class GUI {
|
|||||||
addToPrincipalPanel(value.getA(), principalPane, i, j);
|
addToPrincipalPanel(value.getA(), principalPane, i, j);
|
||||||
}
|
}
|
||||||
if (value.getB() instanceof Wall || value.getB() instanceof EnergyBall || value.getB() instanceof Mine || value.getB() instanceof Bomb) {
|
if (value.getB() instanceof Wall || value.getB() instanceof EnergyBall || value.getB() instanceof Mine || value.getB() instanceof Bomb) {
|
||||||
|
System.out.println(value.getB());
|
||||||
addToPrincipalPanel(value.getB(), principalPane, i, j);
|
addToPrincipalPanel(value.getB(), principalPane, i, j);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//PARTIE3
|
|
||||||
|
Rectangle shape = new Rectangle();
|
||||||
|
shape.setX(700);
|
||||||
|
shape.setY(20);
|
||||||
|
shape.setWidth(200);
|
||||||
|
shape.setHeight(600);
|
||||||
|
shape.setFill(javafx.scene.paint.Color.WHITE);
|
||||||
|
|
||||||
|
|
||||||
Button followingButton = new Button("SUIVANT");
|
Button followingButton = new Button("SUIVANT");
|
||||||
followingButton.setLayoutX(775);
|
followingButton.setLayoutX(775);
|
||||||
followingButton.setLayoutY(600);
|
followingButton.setLayoutY(600);
|
||||||
@ -84,6 +89,7 @@ public class GUI {
|
|||||||
//add un eventListener au button
|
//add un eventListener au button
|
||||||
|
|
||||||
principalPane.getChildren().add(followingButton);
|
principalPane.getChildren().add(followingButton);
|
||||||
|
//pas compris le principe
|
||||||
return principalPane;
|
return principalPane;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,10 +106,8 @@ public class GUI {
|
|||||||
private Grid getGrid() {
|
private Grid getGrid() {
|
||||||
List<Player> players = Arrays.asList(new RandomComputerPlayer(1, null, ClassPlayer.DEFAULT),
|
List<Player> players = Arrays.asList(new RandomComputerPlayer(1, null, ClassPlayer.DEFAULT),
|
||||||
new RandomComputerPlayer(2, null, ClassPlayer.DEFAULT));
|
new RandomComputerPlayer(2, null, ClassPlayer.DEFAULT));
|
||||||
Grid grid = new Grid(16, 16, players);
|
Grid grid = new Grid(16, 16, players, 0.80F, 0.95F);
|
||||||
grid.placePlayersBRUT();
|
//grid.placePlayersBRUT();
|
||||||
grid.placeEnergyBallBRUT();
|
|
||||||
grid.placeInternWallBRUT();
|
|
||||||
return grid;
|
return grid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,14 +3,11 @@ package fr.lnl.game.client.view;
|
|||||||
import fr.lnl.game.client.listener.ButtonListener;
|
import fr.lnl.game.client.listener.ButtonListener;
|
||||||
import fr.lnl.game.server.games.Game;
|
import fr.lnl.game.server.games.Game;
|
||||||
import fr.lnl.game.server.games.player.Player;
|
import fr.lnl.game.server.games.player.Player;
|
||||||
import javafx.concurrent.ScheduledService;
|
|
||||||
import javafx.concurrent.Task;
|
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.layout.GridPane;
|
import javafx.scene.layout.GridPane;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
import javafx.util.Duration;
|
|
||||||
|
|
||||||
public class Window extends AbstractView {
|
public class Window extends AbstractView {
|
||||||
|
|
||||||
|
BIN
client/src/main/resources/images/bottomLeftWall.PNG
Normal file
After Width: | Height: | Size: 5.9 KiB |
BIN
client/src/main/resources/images/bottomRightWall.PNG
Normal file
After Width: | Height: | Size: 6.0 KiB |
BIN
client/src/main/resources/images/bottomWall.PNG
Normal file
After Width: | Height: | Size: 4.7 KiB |
BIN
client/src/main/resources/images/rightWall.PNG
Normal file
After Width: | Height: | Size: 6.0 KiB |
BIN
client/src/main/resources/images/topLeftWall.PNG
Normal file
After Width: | Height: | Size: 5.5 KiB |
BIN
client/src/main/resources/images/topRightWall.PNG
Normal file
After Width: | Height: | Size: 6.2 KiB |
BIN
client/src/main/resources/images/topWall.PNG
Normal file
After Width: | Height: | Size: 4.6 KiB |
@ -25,25 +25,17 @@ public class Game {
|
|||||||
public Game(Grid grid, List<Player> players, ModelListener gameFinishEvent) throws IllegalArgumentException {
|
public Game(Grid grid, List<Player> players, ModelListener gameFinishEvent) throws IllegalArgumentException {
|
||||||
if(players.size() < 2)
|
if(players.size() < 2)
|
||||||
throw new IllegalArgumentException("The game need 2 or more player to start");
|
throw new IllegalArgumentException("The game need 2 or more player to start");
|
||||||
|
if(players.size() > grid.getNumberNeutralBox()){
|
||||||
|
throw new IllegalArgumentException("There are too many players for the number of box available");
|
||||||
|
}
|
||||||
this.players = players;
|
this.players = players;
|
||||||
this.currentPlayer = players.get(0);
|
this.currentPlayer = players.get(0);
|
||||||
this.grid = grid;
|
this.grid = grid;
|
||||||
this.gameFinishEvent = gameFinishEvent;
|
this.gameFinishEvent = gameFinishEvent;
|
||||||
placePlayersBRUT();
|
this.grid.initPlacePlayers();
|
||||||
currentPlayer.setActions(generateAndGetPlayerActions(currentPlayer));
|
currentPlayer.setActions(generateAndGetPlayerActions(currentPlayer));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated utiliser pour le moment, nécessite une meilleure implémentation pour savoir ou placé les joueurs
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public void placePlayersBRUT(){
|
|
||||||
grid.getBoard().get(new Point(7,7)).setA(grid.getPlayers().get(0));
|
|
||||||
grid.getPlayers().get(0).setPosition(new Point(7, 7));
|
|
||||||
grid.getBoard().get(new Point(7,8)).setA(grid.getPlayers().get(1));
|
|
||||||
grid.getPlayers().get(1).setPosition(new Point(7, 8));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void play() {
|
public void play() {
|
||||||
if (currentPlayer instanceof ComputerPlayer player) {
|
if (currentPlayer instanceof ComputerPlayer player) {
|
||||||
selectedAction = player.choseAction();
|
selectedAction = player.choseAction();
|
||||||
|
@ -3,9 +3,6 @@ package fr.lnl.game.server.games.action;
|
|||||||
import fr.lnl.game.server.games.Game;
|
import fr.lnl.game.server.games.Game;
|
||||||
import fr.lnl.game.server.games.grid.Mine;
|
import fr.lnl.game.server.games.grid.Mine;
|
||||||
import fr.lnl.game.server.games.player.Player;
|
import fr.lnl.game.server.games.player.Player;
|
||||||
import fr.lnl.game.server.utils.Point;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class DropMine extends DropObject {
|
public class DropMine extends DropObject {
|
||||||
|
|
||||||
|
@ -0,0 +1,21 @@
|
|||||||
|
package fr.lnl.game.server.games.grid;
|
||||||
|
|
||||||
|
public class AbstractBox implements Box{
|
||||||
|
|
||||||
|
boolean lock;
|
||||||
|
|
||||||
|
public AbstractBox(){
|
||||||
|
lock = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setLock(boolean lock) {
|
||||||
|
this.lock = lock;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLock() {
|
||||||
|
return lock;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,7 @@
|
|||||||
package fr.lnl.game.server.games.grid;
|
package fr.lnl.game.server.games.grid;
|
||||||
|
|
||||||
public interface Box {
|
public interface Box {
|
||||||
|
|
||||||
|
boolean isLock();
|
||||||
|
void setLock(boolean lock);
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ 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.Point;
|
import fr.lnl.game.server.utils.Point;
|
||||||
|
|
||||||
public class EnergyBall implements Box, InteractiveBox {
|
public class EnergyBall extends AbstractBox implements InteractiveBox{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
|
@ -3,7 +3,7 @@ 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.Point;
|
import fr.lnl.game.server.utils.Point;
|
||||||
|
|
||||||
public abstract class Explosive implements Box, InteractiveBox {
|
public abstract class Explosive extends AbstractBox implements InteractiveBox {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void interact(Grid grid, Player player, Point position) {
|
public void interact(Grid grid, Player player, Point position) {
|
||||||
|
@ -7,6 +7,7 @@ import fr.lnl.game.server.utils.Point;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
|
||||||
public class Grid {
|
public class Grid {
|
||||||
@ -15,12 +16,18 @@ public class Grid {
|
|||||||
private final int column;
|
private final int column;
|
||||||
private final List<Player> players;
|
private final List<Player> players;
|
||||||
|
|
||||||
public Grid(int row, int column, List<Player> players) {
|
public Grid(int row, int column, List<Player> players, float wallProbability, float energyProbability) {
|
||||||
this.row = row;
|
this.row = row;
|
||||||
this.column = column;
|
this.column = column;
|
||||||
this.players = players;
|
this.players = players;
|
||||||
board = new HashMap<>();
|
board = new HashMap<>();
|
||||||
|
initBoard(wallProbability, energyProbability);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initBoard(float wallProbability, float energyProbability){
|
||||||
initGrid();
|
initGrid();
|
||||||
|
initPlaceInternWall(wallProbability);
|
||||||
|
initPlaceEnergyBall(energyProbability);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initGrid(){
|
public void initGrid(){
|
||||||
@ -51,21 +58,54 @@ public class Grid {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void placePlayersBRUT(){
|
public void initPlacePlayers(){
|
||||||
board.get(new Point(1,1)).setA(players.get(0));
|
Random random = new Random();
|
||||||
board.get(new Point(14,14)).setA(players.get(1));
|
Box boxTargeted;
|
||||||
|
Player playerTargeted;
|
||||||
|
Point point;
|
||||||
|
for (Player player: players) {
|
||||||
|
do{
|
||||||
|
int i = random.nextInt(1,getRow() - 1);
|
||||||
|
int j = random.nextInt(1,getColumn() - 1);
|
||||||
|
point = new Point(i,j);
|
||||||
|
Pair<Player,Box> pairTargeted = getBoard().get(point);
|
||||||
|
boxTargeted = pairTargeted.getB();
|
||||||
|
playerTargeted = pairTargeted.getA();
|
||||||
|
}while(playerTargeted != null || !isNeutralBox(boxTargeted));
|
||||||
|
getBoard().get(point).setA(player);
|
||||||
|
player.setPosition(point);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void placeEnergyBallBRUT(){
|
|
||||||
board.get(new Point(2,3)).setB(new EnergyBall());
|
public void initPlaceEnergyBall(float probability){
|
||||||
board.get(new Point(7,10)).setB(new EnergyBall());
|
for (int i = 1; i < row - 1; i++) {
|
||||||
|
for (int j = 1; j < column - 1; j++) {
|
||||||
|
if(Math.random() >= probability){
|
||||||
|
Point point = new Point(i,j);
|
||||||
|
if(!(getBoard().get(point).getB() instanceof Wall)){
|
||||||
|
getBoard().get(point).setB(new EnergyBall());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void placeInternWallBRUT(){
|
public void initPlaceInternWall(float probability){
|
||||||
board.get(new Point(3,6)).setB(new Wall(Cardinal.NORTH,3,6));
|
for (int i = 1; i < row - 1; i++) {
|
||||||
board.get(new Point(7,14)).setB(new Wall(Cardinal.SOUTH,7,14));
|
for (int j = 1; j < column - 1; j++) {
|
||||||
board.get(new Point(10,7)).setB(new Wall(Cardinal.EAST,10,7));
|
if(Math.random() >= probability){
|
||||||
board.get(new Point(14,2)).setB(new Wall(Cardinal.WEST,14,2));
|
Point point = new Point(i,j);
|
||||||
|
if(getIllusionNumberWallNeighbour(point) <= 3){
|
||||||
|
getBoard().get(point).setB(new Wall(Cardinal.getRandom(),i,j));
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
getBoard().get(point).setB(new AbstractBox());
|
||||||
|
getBoard().get(point).getB().setLock(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean boardPositionIsValid(int row, int deltaRow, int column, int deltaColumn){
|
public boolean boardPositionIsValid(int row, int deltaRow, int column, int deltaColumn){
|
||||||
@ -80,12 +120,39 @@ public class Grid {
|
|||||||
return boardPositionIsValid(point.getA(), point.getB());
|
return boardPositionIsValid(point.getA(), point.getB());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean boardHorizontalIsValid(int column, int deltaColumn){
|
public int getIllusionNumberWallNeighbour(Point point){
|
||||||
return column + deltaColumn >= 0 && column + deltaColumn < this.column;
|
int countWall = 0;
|
||||||
|
for (int deltaRow = -1; deltaRow <= 1; deltaRow++){
|
||||||
|
for (int deltaColomn = -1; deltaColomn <= 1; deltaColomn++) {
|
||||||
|
Point neighbour = new Point(point.getA() + deltaRow, point.getB() + deltaColomn);
|
||||||
|
if (boardPositionIsValid(neighbour)) {
|
||||||
|
Box box = getBoard().get(neighbour).getB();
|
||||||
|
if (box != null) {
|
||||||
|
if (box instanceof Wall || box.isLock()) {
|
||||||
|
countWall++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return countWall;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean boardVerticalIsValid(int row, int deltaRow){
|
public int getNumberNeutralBox(){
|
||||||
return row + deltaRow >= 0 && row + deltaRow < this.row;
|
int countBox = 0;
|
||||||
|
for (int i = 1; i < row - 1; i++) {
|
||||||
|
for (int j = 1; j < column - 1; j++) {
|
||||||
|
Box box = getBoard().get(new Point(i,j)).getB();
|
||||||
|
if(isNeutralBox(box)){
|
||||||
|
countBox++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return countBox;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isNeutralBox(Box box){
|
||||||
|
return !(box instanceof Wall) && !(box instanceof EnergyBall);
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashMap<Point, Pair<Player, Box>> getBoard() {
|
public HashMap<Point, Pair<Player, Box>> getBoard() {
|
||||||
|
@ -4,7 +4,7 @@ import fr.lnl.game.server.utils.Cardinal;
|
|||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public class Wall implements Box {
|
public class Wall extends AbstractBox {
|
||||||
|
|
||||||
private final Cardinal cardinal;
|
private final Cardinal cardinal;
|
||||||
private final int x;
|
private final int x;
|
||||||
|
@ -87,6 +87,9 @@ public abstract class AbstractPlayer implements Player {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setPosition(Point position){
|
public void setPosition(Point position){
|
||||||
|
if(position == null){
|
||||||
|
throw new IllegalArgumentException("Position is null");
|
||||||
|
}
|
||||||
this.position = position;
|
this.position = position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package fr.lnl.game.server.games.player;
|
package fr.lnl.game.server.games.player;
|
||||||
|
|
||||||
import fr.lnl.game.server.games.action.Action;
|
|
||||||
import fr.lnl.game.server.utils.Point;
|
import fr.lnl.game.server.utils.Point;
|
||||||
|
|
||||||
public class HumanPlayer extends AbstractPlayer {
|
public class HumanPlayer extends AbstractPlayer {
|
||||||
|
@ -8,5 +8,11 @@ public enum Cardinal {
|
|||||||
NORTH_EAST,
|
NORTH_EAST,
|
||||||
NORTH_WEST,
|
NORTH_WEST,
|
||||||
SOUTH_EAST,
|
SOUTH_EAST,
|
||||||
SOUTH_WEST
|
SOUTH_WEST;
|
||||||
|
|
||||||
|
public static Cardinal getRandom() {
|
||||||
|
return values()[(int) (Math.random() * values().length)];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,20 +1,17 @@
|
|||||||
package fr.lnl.game.server;
|
package fr.lnl.game.server;
|
||||||
|
|
||||||
import fr.lnl.game.server.games.Game;
|
import fr.lnl.game.server.games.Game;
|
||||||
import fr.lnl.game.server.games.action.*;
|
import fr.lnl.game.server.games.grid.Box;
|
||||||
import fr.lnl.game.server.games.grid.EnergyBall;
|
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.Cardinal;
|
||||||
|
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;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
public class GridTest {
|
public class GridTest {
|
||||||
@ -44,4 +41,35 @@ public class GridTest {
|
|||||||
assertEquals(new EnergyBall(), grid.getBoard().get(new Point(8, 10)).getB());
|
assertEquals(new EnergyBall(), grid.getBoard().get(new Point(8, 10)).getB());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLock() {
|
||||||
|
System.out.println("=================== GRID COMPLETE ====================");
|
||||||
|
System.out.println(grid.toString());
|
||||||
|
System.out.println("=================== GRID AVEC LOCK ===================");
|
||||||
|
StringBuilder str = new StringBuilder();
|
||||||
|
for (int i = 0; i < grid.getRow(); i++) {
|
||||||
|
str.append("\n");
|
||||||
|
for (int j = 0; j < grid.getColumn(); j++) {
|
||||||
|
Pair<Player, Box> value = grid.getBoard().get(new Point(i, j));
|
||||||
|
if(value.getB() != null){
|
||||||
|
if(value.getB().isLock()){
|
||||||
|
str.append(" \033[0;35mL\033[0m");
|
||||||
|
}
|
||||||
|
if(value.getB() instanceof Wall){
|
||||||
|
str.append(" \033[0;32mW\033[0m");
|
||||||
|
}
|
||||||
|
if(value.getB() instanceof EnergyBall){
|
||||||
|
str.append(" \033[0;31mE\033[0m");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(value.getA() != null){
|
||||||
|
str.append(" \033[0;34mP\033[0m");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
str.append(" \033[0;37m.\033[0m");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
System.out.println(str);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,10 +22,7 @@ public class Mock {
|
|||||||
public Mock() {
|
public Mock() {
|
||||||
List<Player> players = Arrays.asList(new RandomComputerPlayer(1,null, ClassPlayer.DEFAULT),
|
List<Player> players = Arrays.asList(new RandomComputerPlayer(1,null, ClassPlayer.DEFAULT),
|
||||||
new RandomComputerPlayer(2,null, ClassPlayer.DEFAULT));
|
new RandomComputerPlayer(2,null, ClassPlayer.DEFAULT));
|
||||||
this.grid = new Grid(16,16, players);
|
this.grid = new Grid(16,16, players,0.80F, 0.95F);
|
||||||
placePlayersBRUT();
|
|
||||||
placeEnergyBallBRUT();
|
|
||||||
placeInternWallBRUT();
|
|
||||||
game = new Game(grid, players, new GameFinishEvent());
|
game = new Game(grid, players, new GameFinishEvent());
|
||||||
}
|
}
|
||||||
|
|
||||||
|