Merge branch 'testplay'
# Conflicts: # server/src/main/java/fr/lnl/game/server/games/Game.java # server/src/main/java/fr/lnl/game/server/games/action/DeployShield.java # server/src/main/java/fr/lnl/game/server/games/action/DropMine.java
This commit is contained in:
commit
3a31f8485d
@ -47,6 +47,10 @@ public class Game {
|
|||||||
} while(!currentPlayer.isAlive()); // On arrête la boucle dès qu'on trouve un joueur en vie
|
} while(!currentPlayer.isAlive()); // On arrête la boucle dès qu'on trouve un joueur en vie
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setCurrent_player(Player current_player) {
|
||||||
|
this.currentPlayer = current_player;
|
||||||
|
}
|
||||||
|
|
||||||
public Grid getGrid() {
|
public Grid getGrid() {
|
||||||
return grid;
|
return grid;
|
||||||
}
|
}
|
||||||
|
@ -17,9 +17,9 @@ public class DropMine extends DropObject {
|
|||||||
List<Point> points = getValidPoint();
|
List<Point> points = getValidPoint();
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
Point point = points.get(random.nextInt(0,points.size()-1));
|
Point point = points.get(random.nextInt(0,points.size()-1));
|
||||||
getGame().getGrid().getBoard().get(point).setB(new Mine());
|
Mine mine = new Mine();
|
||||||
Player player = getGame().getCurrentPlayer();
|
getGame().getGrid().getBoard().get(point).setB(mine);
|
||||||
player.decrementEnergy(player.getClassPlayer().getMineCost());
|
getGame().getCurrentPlayer().decrementEnergy(getGame().getCurrentPlayer().getClassPlayer().getMineCost());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -31,7 +31,7 @@ public class Move extends AbstractAction {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isPossible() {
|
public boolean isPossible() {
|
||||||
return getValidPoint().isEmpty();
|
return !getValidPoint().isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Point> getValidPoint() {
|
public List<Point> getValidPoint() {
|
||||||
@ -40,7 +40,7 @@ public class Move extends AbstractAction {
|
|||||||
Point position = getGame().getCurrentPlayer().getPoint();
|
Point position = getGame().getCurrentPlayer().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(row == position.getA() + row || column == position.getB() + column){
|
||||||
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);
|
||||||
|
@ -9,7 +9,6 @@ public class Nothing extends AbstractAction {
|
|||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void doAction(){
|
public void doAction(){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -69,7 +69,7 @@ public class Grid {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean caseisValid(int row, int column, int deltaRow, int deltaColumn){
|
public static boolean caseisValid(int row, int column, int deltaRow, int deltaColumn){
|
||||||
return row + deltaRow >= 0 && row + deltaRow <= row && column + deltaColumn >= 0 && column + deltaColumn <= column;
|
return row + deltaRow >= 0 && row + deltaRow < row && column + deltaColumn >= 0 && column + deltaColumn < column;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashMap<Point, Pair<Player, Box>> getBoard() {
|
public HashMap<Point, Pair<Player, Box>> getBoard() {
|
||||||
|
@ -59,6 +59,10 @@ public abstract class AbstractPlayer implements Player {
|
|||||||
return actions;
|
return actions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setActions(Action[] actions){
|
||||||
|
this.actions = actions;
|
||||||
|
}
|
||||||
|
|
||||||
public ClassPlayer getClassPlayer() {
|
public ClassPlayer getClassPlayer() {
|
||||||
return classPlayer;
|
return classPlayer;
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ public interface Player {
|
|||||||
void setShieldDeploy(boolean shieldDeploy);
|
void setShieldDeploy(boolean shieldDeploy);
|
||||||
void setWeapon(Weapon weapon);
|
void setWeapon(Weapon weapon);
|
||||||
Action[] getActions();
|
Action[] getActions();
|
||||||
|
void setActions(Action[] actions);
|
||||||
ClassPlayer getClassPlayer();
|
ClassPlayer getClassPlayer();
|
||||||
void setPoint(Point point);
|
void setPoint(Point point);
|
||||||
void decrementEnergy(int energy);
|
void decrementEnergy(int energy);
|
||||||
|
@ -1,23 +1,30 @@
|
|||||||
package fr.lnl.game.server;
|
package fr.lnl.game.server;
|
||||||
|
|
||||||
|
import fr.lnl.game.server.games.Game;
|
||||||
|
import fr.lnl.game.server.games.action.*;
|
||||||
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.utils.Cardinal;
|
import fr.lnl.game.server.utils.Cardinal;
|
||||||
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.Random;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
public class GridTest {
|
public class GridTest {
|
||||||
|
|
||||||
private Grid grid;
|
private Grid grid;
|
||||||
|
private Game game;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void mock() {
|
public void mock() {
|
||||||
Mock mock = new Mock();
|
Mock mock = new Mock();
|
||||||
grid = mock.grid;
|
grid = mock.grid;
|
||||||
|
game = mock.game;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -35,4 +42,33 @@ public class GridTest {
|
|||||||
assertEquals(new EnergyBall(), grid.getBoard().get(new Point(7, 10)).getB());
|
assertEquals(new EnergyBall(), grid.getBoard().get(new Point(7, 10)).getB());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPlay(){
|
||||||
|
for (Player player: game.getPlayers()) {
|
||||||
|
player.setActions(new Action[]{new Move(game)});
|
||||||
|
}
|
||||||
|
System.out.println(game.getGrid().toString());
|
||||||
|
while (!game.isOver()){
|
||||||
|
Random random = new Random();
|
||||||
|
Action action = null;
|
||||||
|
do {
|
||||||
|
action = game.getCurrentPlayer().getActions()[random.nextInt(0,game.getCurrentPlayer().getActions().length -1)];
|
||||||
|
}while (!action.isPossible());
|
||||||
|
action.doAction();
|
||||||
|
System.out.println(game.getGrid().toString());
|
||||||
|
if(game.getCurrentPlayer().getEnergy() <= 0){
|
||||||
|
game.decrementPlayers(game.getCurrentPlayer());
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
if(game.getCurrentPlayer() == game.getPlayers().get(0)){
|
||||||
|
game.setCurrent_player(game.getPlayers().get(1));
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
game.setCurrent_player(game.getPlayers().get(0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
System.out.println("Le joueur gagnant : " + game.getWinner().getId());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user