Add basis Play test and Shot test
This commit is contained in:
parent
2322462ab3
commit
8a35d22b58
@ -38,13 +38,16 @@ public class Game {
|
|||||||
/**
|
/**
|
||||||
* Change player to the next available in the list
|
* Change player to the next available in the list
|
||||||
*/
|
*/
|
||||||
public void nextCurrentPlayer() {
|
public boolean nextCurrentPlayer() {
|
||||||
|
if(isOver())
|
||||||
|
return false;
|
||||||
do {
|
do {
|
||||||
int index = players.indexOf(currentPlayer) + 1;
|
int index = players.indexOf(currentPlayer) + 1;
|
||||||
if(index == players.size())
|
if(index == players.size())
|
||||||
index = 0;
|
index = 0;
|
||||||
currentPlayer = players.get(index);
|
currentPlayer = players.get(index);
|
||||||
} 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
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCurrent_player(Player current_player) {
|
public void setCurrent_player(Player current_player) {
|
||||||
|
@ -68,8 +68,16 @@ public class Grid {
|
|||||||
board.get(new Point(14,2)).setB(new Wall(Cardinal.WEST,14,2));
|
board.get(new Point(14,2)).setB(new Wall(Cardinal.WEST,14,2));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean caseisValid(int row, int column, int deltaRow, int deltaColumn){
|
public boolean boardPositionIsValid(int row, int deltaRow, int column, int deltaColumn){
|
||||||
return row + deltaRow >= 0 && row + deltaRow < row && column + deltaColumn >= 0 && column + deltaColumn < column;
|
return row + deltaRow >= 0 && row + deltaRow < this.row && column + deltaColumn >= 0 && column + deltaColumn < this.column;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean boardHorizontalIsValid(int column, int deltaColumn){
|
||||||
|
return column + deltaColumn >= 0 && column + deltaColumn < this.column;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean boardVerticalIsValid(int row, int deltaRow){
|
||||||
|
return row + deltaRow >= 0 && row + deltaRow < this.row;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashMap<Point, Pair<Player, Box>> getBoard() {
|
public HashMap<Point, Pair<Player, Box>> getBoard() {
|
||||||
@ -106,16 +114,16 @@ public class Grid {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(value.getB() instanceof EnergyBall){
|
else if(value.getB() instanceof EnergyBall){
|
||||||
str.append(" \033[0;31mO\033[0m");
|
str.append(" \033[0;31mE\033[0m");
|
||||||
}
|
}
|
||||||
else if(value.getB() instanceof Mine){
|
else if(value.getB() instanceof Mine){
|
||||||
str.append(" \033[0;31mX\033[0m");
|
str.append(" \033[0;35mM\033[0m");
|
||||||
}
|
}
|
||||||
else if(value.getB() instanceof Bomb){
|
else if(value.getB() instanceof Bomb){
|
||||||
str.append(" \033[0;31mI\033[0m");
|
str.append(" \033[0;36mB\033[0m");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
str.append(" \033[0;31m.\033[0m");
|
str.append(" \033[0;37m.\033[0m");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,15 @@
|
|||||||
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.Shot;
|
||||||
import fr.lnl.game.server.games.grid.Grid;
|
import fr.lnl.game.server.games.grid.Grid;
|
||||||
|
import fr.lnl.game.server.utils.Point;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
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.List;
|
||||||
|
|
||||||
public class ActionPlayerTest {
|
public class ActionPlayerTest {
|
||||||
|
|
||||||
private Grid grid;
|
private Grid grid;
|
||||||
@ -25,4 +29,17 @@ public class ActionPlayerTest {
|
|||||||
Assertions.assertEquals(game.getPlayers().get(0), game.getCurrentPlayer());
|
Assertions.assertEquals(game.getPlayers().get(0), game.getCurrentPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// TODO: 10/28/2021 pas un vrai test et marche qu'avec le mock actuel
|
||||||
|
@Test
|
||||||
|
public void shotActionTest(){
|
||||||
|
System.out.println(grid.toString());
|
||||||
|
Shot shot = new Shot(game);
|
||||||
|
List<Point> points = shot.getValidPoint();
|
||||||
|
System.out.println(points);
|
||||||
|
System.out.println("Before shot " + game.getPlayers().get(1).getEnergy());
|
||||||
|
shot.doAction();
|
||||||
|
System.out.println("After shot " + game.getPlayers().get(1).getEnergy());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ import org.junit.jupiter.api.Test;
|
|||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
public class GridTest {
|
public class GridTest {
|
||||||
|
|
||||||
@ -42,28 +42,35 @@ 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
|
@Test
|
||||||
public void testPlay(){
|
public void testPlay(){
|
||||||
for (Player player: game.getPlayers()) {
|
for (Player player: game.getPlayers()) {
|
||||||
player.setActions(new Action[]{new Move(game)});
|
player.setActions(new Action[]{new Nothing(game), new Shot(game), new Move(game),
|
||||||
|
new DeployShield(game), new DropBomb(game), new DropMine(game)});
|
||||||
}
|
}
|
||||||
System.out.println(game.getGrid().toString());
|
|
||||||
while (!game.isOver()){
|
while (!game.isOver()){
|
||||||
Random random = new Random();
|
System.out.println(" Tour du joueur " + game.getCurrentPlayer().getId() + " : " +
|
||||||
|
game.getCurrentPlayer().getEnergy() + " points de vies restants");
|
||||||
|
System.out.println(game.getGrid().toString());
|
||||||
Action action = null;
|
Action action = null;
|
||||||
while ((action == null || !action.isPossible()) && game.getCurrentPlayer().getActions().length != 0) {
|
switch (game.getCurrentPlayer().getActions().length){
|
||||||
if(game.getCurrentPlayer().getActions().length == 1) {
|
case 0 -> action = new Nothing(game);
|
||||||
action = game.getCurrentPlayer().getActions()[0];
|
case 1 -> action = game.getCurrentPlayer().getActions()[0];
|
||||||
} else {
|
default -> {
|
||||||
action = game.getCurrentPlayer().getActions()[random.nextInt(0,game.getCurrentPlayer().getActions().length -1)];
|
Random random = new Random();
|
||||||
|
while (action == null || !action.isPossible()) {
|
||||||
|
action = game.getCurrentPlayer().getActions()
|
||||||
|
[random.nextInt(0,game.getCurrentPlayer().getActions().length)];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
action.doAction();
|
action.doAction();
|
||||||
System.out.println(game.getGrid().toString());
|
System.out.println("Action " + action + " : " + game.getCurrentPlayer().getEnergy() +
|
||||||
|
" points de vies restants");
|
||||||
game.nextCurrentPlayer();
|
game.nextCurrentPlayer();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
System.out.println(game.getGrid().toString());
|
||||||
System.out.println("Le joueur gagnant : " + game.getWinner().getId());
|
System.out.println("Le joueur gagnant : " + game.getWinner().getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,13 +29,15 @@ public class Mock {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void placePlayersBRUT(){
|
public void placePlayersBRUT(){
|
||||||
grid.getBoard().get(new Point(1,1)).setA(grid.getPlayers().get(0));
|
grid.getBoard().get(new Point(7,7)).setA(grid.getPlayers().get(0));
|
||||||
grid.getBoard().get(new Point(14,14)).setA(grid.getPlayers().get(1));
|
grid.getPlayers().get(0).setPoint(new Point(7, 7));
|
||||||
|
grid.getBoard().get(new Point(7,8)).setA(grid.getPlayers().get(1));
|
||||||
|
grid.getPlayers().get(1).setPoint(new Point(7, 8));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void placeEnergyBallBRUT(){
|
public void placeEnergyBallBRUT(){
|
||||||
grid.getBoard().get(new Point(2,3)).setB(new EnergyBall());
|
grid.getBoard().get(new Point(2,3)).setB(new EnergyBall());
|
||||||
grid.getBoard().get(new Point(7,10)).setB(new EnergyBall());
|
grid.getBoard().get(new Point(8,10)).setB(new EnergyBall());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void placeInternWallBRUT(){
|
public void placeInternWallBRUT(){
|
||||||
|
Loading…
Reference in New Issue
Block a user