refactored ClassPlayer from a class to an enum

This commit is contained in:
Quentin Legot 2021-10-21 17:14:04 +02:00
parent f2e42c68bf
commit fb1c82ed58
4 changed files with 91 additions and 100 deletions

View File

@ -3,14 +3,14 @@ package fr.lnl.game.server;
import fr.lnl.game.server.games.Game;
import fr.lnl.game.server.games.grid.Grid;
import fr.lnl.game.server.games.player.ComputerPlayer;
import fr.lnl.game.server.games.player.DefaultClassPlayer;
import fr.lnl.game.server.games.player.ClassPlayer;
import fr.lnl.game.server.games.player.Player;
public class ServerMain {
public static void main(String[] args) {
Player playerOne = new ComputerPlayer(1,null,new DefaultClassPlayer());
Player playerTwo = new ComputerPlayer(2,null,new DefaultClassPlayer());
Player playerOne = new ComputerPlayer(1,null, ClassPlayer.DEFAULT);
Player playerTwo = new ComputerPlayer(2,null, ClassPlayer.DEFAULT);
Grid grid = new Grid(16,16,new Player[]{playerOne,playerTwo});
grid.initGrid();

View File

@ -1,18 +1,81 @@
package fr.lnl.game.server.games.player;
import fr.lnl.game.server.games.weapon.Firearm;
import fr.lnl.game.server.games.weapon.Weapon;
public interface ClassPlayer {
public enum ClassPlayer {
int getEnergy();
int getShieldCost();
int getShootdCost();
int getMineCost();
int getBombCost();
int getDeplaceCost();
int getGainEnergyBall();
int getPenaltyShoot();
int getPenaltyMine();
int getPenaltyBomb();
Weapon getWeapon();
DEFAULT(800, 25, 40, 30, 40, 10, 800, 20, 20, 15, new Firearm());
private final int energy;
private final int shieldCost;
private final int shootCost;
private final int mineCost;
private final int bombCost;
private final int moveCost;
private final int gainEnergyCost;
private final int penaltyShoot;
private final int penaltyBomb;
private final int penaltyMine;
private final Weapon weapon;
ClassPlayer(int energy, int shieldCost, int shootCost, int mineCost, int bombCost, int moveCost,
int gainEnergyCost, int penaltyShoot, int penaltyBomb, int penaltyMine, Weapon weapon){
this.energy = energy;
this.shieldCost = shieldCost;
this.shootCost = shootCost;
this.mineCost = mineCost;
this.bombCost = bombCost;
this.moveCost = moveCost;
this.gainEnergyCost = gainEnergyCost;
this.penaltyShoot = penaltyShoot;
this.penaltyBomb = penaltyBomb;
this.penaltyMine = penaltyMine;
this.weapon = weapon;
}
public int getEnergy() {
return energy;
}
public int getShieldCost() {
return shieldCost;
}
public int getShootCost() {
return shootCost;
}
public int getMineCost() {
return mineCost;
}
public int getBombCost() {
return bombCost;
}
public int getMoveCost() {
return moveCost;
}
public int getGainEnergyCost() {
return gainEnergyCost;
}
public int getPenaltyShoot() {
return penaltyShoot;
}
public int getPenaltyBomb() {
return penaltyBomb;
}
public int getPenaltyMine() {
return penaltyMine;
}
public Weapon getWeapon() {
return weapon;
}
}

View File

@ -1,80 +0,0 @@
package fr.lnl.game.server.games.player;
import fr.lnl.game.server.games.weapon.Firearm;
import fr.lnl.game.server.games.weapon.Weapon;
@SuppressWarnings("all")
public class DefaultClassPlayer implements ClassPlayer{
private final int ENERGY = 800;
private final int SHIELDCOST = 25;
private final int SHOOTDCOST = 40;
private final int MINECOST = 30;
private final int BOMBCOST = 40;
private final int DEPLACECOST = 10;
private final int GAINENERGYBALL = 800;
private final int PENALTYSHOOT = 20;
private final int PENALTYBOMB = 20;
private final int PENALTYMINE = 15;
private final Weapon WEAPON = new Firearm();
public DefaultClassPlayer(){
}
@Override
public int getEnergy() {
return this.ENERGY;
}
@Override
public int getShieldCost() {
return this.SHIELDCOST;
}
@Override
public int getShootdCost() {
return this.SHOOTDCOST;
}
@Override
public int getMineCost() {
return this.MINECOST;
}
@Override
public int getBombCost() {
return this.BOMBCOST;
}
@Override
public int getDeplaceCost() {
return this.DEPLACECOST;
}
@Override
public int getGainEnergyBall() {
return this.GAINENERGYBALL;
}
@Override
public int getPenaltyShoot() {
return this.PENALTYSHOOT;
}
@Override
public int getPenaltyMine() {
return this.PENALTYMINE;
}
@Override
public int getPenaltyBomb() {
return this.PENALTYBOMB;
}
@Override
public Weapon getWeapon() {
return this.WEAPON;
}
}

View File

@ -1,13 +1,15 @@
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.DefaultClassPlayer;
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;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
@ -16,15 +18,21 @@ public class GridTest {
private Grid grid;
@Test
public void testGrid() {
Player playerOne = new ComputerPlayer(1,null, new DefaultClassPlayer());
Player playerTwo = new ComputerPlayer(2,null, new DefaultClassPlayer());
@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);
}
@Test
public void testGrid() {
// test Grid#initGrid()
assertEquals(new Wall(Cardinal.NORTH_WEST, 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());