From fb1c82ed589000d14d676a042f3c20bfa381f401 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Thu, 21 Oct 2021 17:14:04 +0200 Subject: [PATCH] refactored ClassPlayer from a class to an enum --- .../java/fr/lnl/game/server/ServerMain.java | 6 +- .../game/server/games/player/ClassPlayer.java | 87 ++++++++++++++++--- .../games/player/DefaultClassPlayer.java | 80 ----------------- .../java/fr/lnl/game/server/GridTest.java | 18 ++-- 4 files changed, 91 insertions(+), 100 deletions(-) delete mode 100644 server/src/main/java/fr/lnl/game/server/games/player/DefaultClassPlayer.java diff --git a/server/src/main/java/fr/lnl/game/server/ServerMain.java b/server/src/main/java/fr/lnl/game/server/ServerMain.java index a4257da..0bf3337 100644 --- a/server/src/main/java/fr/lnl/game/server/ServerMain.java +++ b/server/src/main/java/fr/lnl/game/server/ServerMain.java @@ -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(); diff --git a/server/src/main/java/fr/lnl/game/server/games/player/ClassPlayer.java b/server/src/main/java/fr/lnl/game/server/games/player/ClassPlayer.java index 2125b2c..9c706ee 100644 --- a/server/src/main/java/fr/lnl/game/server/games/player/ClassPlayer.java +++ b/server/src/main/java/fr/lnl/game/server/games/player/ClassPlayer.java @@ -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; + } } diff --git a/server/src/main/java/fr/lnl/game/server/games/player/DefaultClassPlayer.java b/server/src/main/java/fr/lnl/game/server/games/player/DefaultClassPlayer.java deleted file mode 100644 index f05fca1..0000000 --- a/server/src/main/java/fr/lnl/game/server/games/player/DefaultClassPlayer.java +++ /dev/null @@ -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; - } -} diff --git a/server/src/test/java/fr/lnl/game/server/GridTest.java b/server/src/test/java/fr/lnl/game/server/GridTest.java index 06fbd22..0e9a056 100644 --- a/server/src/test/java/fr/lnl/game/server/GridTest.java +++ b/server/src/test/java/fr/lnl/game/server/GridTest.java @@ -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());