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 190225a..cc05ccf 100644 --- a/server/src/main/java/fr/lnl/game/server/ServerMain.java +++ b/server/src/main/java/fr/lnl/game/server/ServerMain.java @@ -1,12 +1,23 @@ 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.Player; +import fr.lnl.game.server.games.weapon.Firearm; public class ServerMain { public static void main(String[] args) { - Grid grid = new Grid(10,10); + Player playerOne = new ComputerPlayer(1,1000,new Firearm()); + Player playerTwo = new ComputerPlayer(2,1000,new Firearm()); + + Grid grid = new Grid(16,16,new Player[]{playerOne,playerTwo}); grid.initGrid(); - grid.printGrid(); + grid.placePlayersBRUT(); + grid.placeEnergyBallBRUT(); + grid.placeInternWallBRUT(); + Game game = new Game(grid,playerOne,playerTwo); + game.getGrid().printGrid(); } } diff --git a/server/src/main/java/fr/lnl/game/server/games/Game.java b/server/src/main/java/fr/lnl/game/server/games/Game.java index 8800e63..9858edd 100644 --- a/server/src/main/java/fr/lnl/game/server/games/Game.java +++ b/server/src/main/java/fr/lnl/game/server/games/Game.java @@ -15,10 +15,10 @@ public class Game { this.player_One = player_One; this.player_Two = player_Two; this.current_player = player_One; + this.grid = grid; players = new Player[]{player_One, player_Two}; } - public void play(){ } @@ -37,4 +37,20 @@ public class Game { public Player getCurrent_player() { return current_player; } + + public Grid getGrid() { + return grid; + } + + public Player getPlayer_One() { + return player_One; + } + + public Player getPlayer_Two() { + return player_Two; + } + + public Player[] getPlayers() { + return players; + } } \ No newline at end of file diff --git a/server/src/main/java/fr/lnl/game/server/games/grid/Grid.java b/server/src/main/java/fr/lnl/game/server/games/grid/Grid.java index 49ac0f6..09de6c7 100644 --- a/server/src/main/java/fr/lnl/game/server/games/grid/Grid.java +++ b/server/src/main/java/fr/lnl/game/server/games/grid/Grid.java @@ -1,20 +1,23 @@ package fr.lnl.game.server.games.grid; +import fr.lnl.game.server.games.player.Player; import fr.lnl.game.server.utils.Cardinal; +import fr.lnl.game.server.utils.Pair; import fr.lnl.game.server.utils.Point; -import fr.lnl.game.server.utils.Triplet; import java.util.HashMap; public class Grid { - private HashMap> board; + private HashMap> board; private int x; private int y; + private Player[] players; - public Grid(int x, int y){ + public Grid(int x, int y, Player[] players){ this.x = x; this.y = y; + this.players = players; board = new HashMap<>(); } @@ -41,44 +44,68 @@ public class Grid { } else { box = null; } - board.put(new Point(i,j), new Triplet<>(box, null, null)); + board.put(new Point(i,j), new Pair<>(null,box)); } } } - - // TODO: 18/10/2021 - public void placePlayers() { - + public void placePlayersBRUT(){ + board.get(new Point(1,1)).setA(players[0]); + board.get(new Point(14,14)).setA(players[1]); } + public void placeEnergyBallBRUT(){ + board.get(new Point(2,3)).setB(new EnergyBall()); + board.get(new Point(7,10)).setB(new EnergyBall()); + } + + public void placeInternWallBRUT(){ + board.get(new Point(3,6)).setB(new Wall(Cardinal.NORTH,3,6)); + board.get(new Point(7,14)).setB(new Wall(Cardinal.SOUTH,7,14)); + board.get(new Point(10,7)).setB(new Wall(Cardinal.EAST,10,7)); + board.get(new Point(14,2)).setB(new Wall(Cardinal.WEST,14,2)); + } + + public void printGrid() { for (int i = 0; i < x; i++) { System.out.print("\n"); for (int j = 0; j < y; j++) { - Triplet value = board.get(new Point(i, j)); - if (value.getA() instanceof Wall) { - if (((Wall) value.getA()).getCardinal() == Cardinal.NORTH) { + Pair value = board.get(new Point(i, j)); + if(value.getA() instanceof Player){ + System.out.print(" \033[0;34mP\033[0m"); + } + else if (value.getB() instanceof Wall) { + if (((Wall) value.getB()).getCardinal() == Cardinal.NORTH) { System.out.print(" \033[0;34m—\033[0m"); - } else if (((Wall) value.getA()).getCardinal() == Cardinal.SOUTH) { + } else if (((Wall) value.getB()).getCardinal() == Cardinal.SOUTH) { System.out.print(" \033[0;31m—\033[0m"); - } else if (((Wall) value.getA()).getCardinal() == Cardinal.WEST) { + } else if (((Wall) value.getB()).getCardinal() == Cardinal.WEST) { System.out.print(" \033[0;33m|\033[0m"); - } else if (((Wall) value.getA()).getCardinal() == Cardinal.EAST) { + } else if (((Wall) value.getB()).getCardinal() == Cardinal.EAST) { System.out.print(" \033[0;32m|\033[0m"); - } else if (((Wall) value.getA()).getCardinal() == Cardinal.NORTH_EAST) { + } else if (((Wall) value.getB()).getCardinal() == Cardinal.NORTH_EAST) { System.out.print(" \033[0;32mN\033[0m"); - } else if (((Wall) value.getA()).getCardinal() == Cardinal.NORTH_WEST) { + } else if (((Wall) value.getB()).getCardinal() == Cardinal.NORTH_WEST) { System.out.print(" \033[0;33mN\033[0m"); - } else if (((Wall) value.getA()).getCardinal() == Cardinal.SOUTH_EAST) { + } else if (((Wall) value.getB()).getCardinal() == Cardinal.SOUTH_EAST) { System.out.print(" \033[0;32mS\033[0m"); - } else if (((Wall) value.getA()).getCardinal() == Cardinal.SOUTH_WEST) { + } else if (((Wall) value.getB()).getCardinal() == Cardinal.SOUTH_WEST) { System.out.print(" \033[0;33mS\033[0m"); } } - else { + else if(value.getB() instanceof EnergyBall){ System.out.print(" \033[0;31mO\033[0m"); } + else if(value.getB() instanceof Mine){ + System.out.print(" \033[0;31mX\033[0m"); + } + else if(value.getB() instanceof Bomb){ + System.out.print(" \033[0;31mI\033[0m"); + } + else { + System.out.print(" \033[0;31m.\033[0m"); + } } } }