Added view files + refactored Tests

This commit is contained in:
Quentin Legot 2021-10-21 20:43:16 +02:00
parent cd166fa809
commit ce39edaead
11 changed files with 102 additions and 45 deletions

View File

@ -0,0 +1,4 @@
package fr.lnl.game.client;
public abstract class AbstractView implements View {
}

View File

@ -0,0 +1,4 @@
package fr.lnl.game.client;
public interface View {
}

View File

@ -0,0 +1,4 @@
package fr.lnl.game.client;
public class Window extends AbstractView {
}

View File

@ -0,0 +1,6 @@
package fr.lnl.game.client.graphics;
import fr.lnl.game.client.AbstractView;
public class Terminal extends AbstractView {
}

View File

@ -28,13 +28,15 @@ public class Game {
}
public Player getWinner(){
// Quentin: simple avis: appel de isOver pas forcément nécessaire, puisqu'on appelera surement getWinner après
// un appel a isOver retournant true
if(isOver()){
return players[0];
}
return null;
}
public Player getCurrent_player() {
public Player getCurrentPlayer() {
return current_player;
}
@ -42,14 +44,6 @@ public class Game {
return grid;
}
public Player getPlayer_One() {
return player_One;
}
public Player getPlayer_Two() {
return player_Two;
}
public Player[] getPlayers() {
return players;
}

View File

@ -9,7 +9,7 @@ public class DeployShield extends AbstractAction {
@Override
public void doAction(){
getGame().getCurrent_player().setShieldDeploy(true);
getGame().getCurrentPlayer().setShieldDeploy(true);
//TO-DO retirer les point du player
}

View File

@ -11,7 +11,6 @@ import fr.lnl.game.server.utils.Point;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
public abstract class DropObject extends AbstractAction {
@ -31,7 +30,7 @@ public abstract class DropObject extends AbstractAction {
public List<Point> getValidPoint() {
List<Point> listMoves = new LinkedList<>();
HashMap<Point, Pair<Player, Box>> board = getGame().getGrid().getBoard();
Point position = getGame().getCurrent_player().getPoint();
Point position = getGame().getCurrentPlayer().getPoint();
for (int row = -1; row <= 1; row++) {
for (int column = -1; column <= 1; column++) {
if(Grid.caseisValid(position.getA(),row,position.getB(),column)){

View File

@ -23,7 +23,7 @@ public class Move extends AbstractAction {
List<Point> points = getValidPoint();
Random random = new Random();
Point nextPositon = points.get(random.nextInt(0,points.size() - 1));
Player player = getGame().getCurrent_player();
Player player = getGame().getCurrentPlayer();
getGame().getGrid().getBoard().get(player.getPoint()).setA(null);
getGame().getGrid().getBoard().get(nextPositon).setA(player);
player.decrementEnergy(player.getClassPlayer().getMoveCost());
@ -37,7 +37,7 @@ public class Move extends AbstractAction {
public List<Point> getValidPoint() {
List<Point> listMoves = new LinkedList<>();
HashMap<Point, Pair<Player, Box>> board = getGame().getGrid().getBoard();
Point position = getGame().getCurrent_player().getPoint();
Point position = getGame().getCurrentPlayer().getPoint();
for (int row = -1; row <= 1; row++) {
for (int column = -1; column <= 1; column++) {
if(row == getGame().getGrid().getRow() || column == getGame().getGrid().getColumn()){

View File

@ -0,0 +1,28 @@
package fr.lnl.game.server;
import fr.lnl.game.server.games.Game;
import fr.lnl.game.server.games.grid.Grid;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
public class ActionPlayerTest {
private Grid grid;
private Game game;
@BeforeEach
public void mock() {
Mock mock = new Mock();
this.grid = mock.grid;
this.game = mock.game;
}
// TODO: 21/10/2021 Vérifier sur Move effectue la bonne action en pensant a appeller isPossible() avant et
// en checkant son résultat
@Test
public void moveActionTest() {
Assertions.assertEquals(game.getPlayers()[0], game.getCurrentPlayer());
}
}

View File

@ -1,12 +1,8 @@
package fr.lnl.game.server;
import fr.lnl.game.server.games.Game;
import fr.lnl.game.server.games.grid.EnergyBall;
import fr.lnl.game.server.games.grid.Grid;
import fr.lnl.game.server.games.grid.Wall;
import fr.lnl.game.server.games.player.ComputerPlayer;
import fr.lnl.game.server.games.player.ClassPlayer;
import fr.lnl.game.server.games.player.Player;
import fr.lnl.game.server.utils.Cardinal;
import fr.lnl.game.server.utils.Point;
import org.junit.jupiter.api.BeforeEach;
@ -18,17 +14,10 @@ public class GridTest {
private Grid grid;
@BeforeEach
public void mockGrid() {
Player playerOne = new ComputerPlayer(1,null, ClassPlayer.DEFAULT);
Player playerTwo = new ComputerPlayer(2,null, ClassPlayer.DEFAULT);
this.grid = new Grid(16,16,new Player[]{playerOne,playerTwo});
grid.initGrid();
placePlayersBRUT();
placeEnergyBallBRUT();
placeInternWallBRUT();
Game game = new Game(grid,playerOne,playerTwo);
public void mock() {
Mock mock = new Mock();
grid = mock.grid;
}
@Test
@ -46,21 +35,4 @@ public class GridTest {
assertEquals(new EnergyBall(), grid.getBoard().get(new Point(7, 10)).getB());
}
public void placePlayersBRUT(){
grid.getBoard().get(new Point(1,1)).setA(grid.getPlayers()[0]);
grid.getBoard().get(new Point(14,14)).setA(grid.getPlayers()[1]);
}
public void placeEnergyBallBRUT(){
grid.getBoard().get(new Point(2,3)).setB(new EnergyBall());
grid.getBoard().get(new Point(7,10)).setB(new EnergyBall());
}
public void placeInternWallBRUT(){
grid.getBoard().get(new Point(3,6)).setB(new Wall(Cardinal.NORTH,3,6));
grid.getBoard().get(new Point(7,14)).setB(new Wall(Cardinal.SOUTH,7,14));
grid.getBoard().get(new Point(10,7)).setB(new Wall(Cardinal.EAST,10,7));
grid.getBoard().get(new Point(14,2)).setB(new Wall(Cardinal.WEST,14,2));
}
}

View File

@ -0,0 +1,46 @@
package fr.lnl.game.server;
import fr.lnl.game.server.games.Game;
import fr.lnl.game.server.games.grid.EnergyBall;
import fr.lnl.game.server.games.grid.Grid;
import fr.lnl.game.server.games.grid.Wall;
import fr.lnl.game.server.games.player.ClassPlayer;
import fr.lnl.game.server.games.player.ComputerPlayer;
import fr.lnl.game.server.games.player.Player;
import fr.lnl.game.server.utils.Cardinal;
import fr.lnl.game.server.utils.Point;
public class Mock {
Grid grid;
Game game;
public Mock() {
Player playerOne = new ComputerPlayer(1,null, ClassPlayer.DEFAULT);
Player playerTwo = new ComputerPlayer(2,null, ClassPlayer.DEFAULT);
this.grid = new Grid(16,16,new Player[]{playerOne,playerTwo});
grid.initGrid();
placePlayersBRUT();
placeEnergyBallBRUT();
placeInternWallBRUT();
game = new Game(grid,playerOne,playerTwo);
}
public void placePlayersBRUT(){
grid.getBoard().get(new Point(1,1)).setA(grid.getPlayers()[0]);
grid.getBoard().get(new Point(14,14)).setA(grid.getPlayers()[1]);
}
public void placeEnergyBallBRUT(){
grid.getBoard().get(new Point(2,3)).setB(new EnergyBall());
grid.getBoard().get(new Point(7,10)).setB(new EnergyBall());
}
public void placeInternWallBRUT(){
grid.getBoard().get(new Point(3,6)).setB(new Wall(Cardinal.NORTH,3,6));
grid.getBoard().get(new Point(7,14)).setB(new Wall(Cardinal.SOUTH,7,14));
grid.getBoard().get(new Point(10,7)).setB(new Wall(Cardinal.EAST,10,7));
grid.getBoard().get(new Point(14,2)).setB(new Wall(Cardinal.WEST,14,2));
}
}