[Priority 1] - Create simple grid

This commit is contained in:
Katchan 2021-10-18 18:20:17 +02:00
parent e81fb4af2e
commit 6c61be3a90
3 changed files with 76 additions and 22 deletions

View File

@ -1,12 +1,23 @@
package fr.lnl.game.server; 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.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 class ServerMain {
public static void main(String[] args) { 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.initGrid();
grid.printGrid(); grid.placePlayersBRUT();
grid.placeEnergyBallBRUT();
grid.placeInternWallBRUT();
Game game = new Game(grid,playerOne,playerTwo);
game.getGrid().printGrid();
} }
} }

View File

@ -15,10 +15,10 @@ public class Game {
this.player_One = player_One; this.player_One = player_One;
this.player_Two = player_Two; this.player_Two = player_Two;
this.current_player = player_One; this.current_player = player_One;
this.grid = grid;
players = new Player[]{player_One, player_Two}; players = new Player[]{player_One, player_Two};
} }
public void play(){ public void play(){
} }
@ -37,4 +37,20 @@ public class Game {
public Player getCurrent_player() { public Player getCurrent_player() {
return current_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;
}
} }

View File

@ -1,20 +1,23 @@
package fr.lnl.game.server.games.grid; 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.Cardinal;
import fr.lnl.game.server.utils.Pair;
import fr.lnl.game.server.utils.Point; import fr.lnl.game.server.utils.Point;
import fr.lnl.game.server.utils.Triplet;
import java.util.HashMap; import java.util.HashMap;
public class Grid { public class Grid {
private HashMap<Point, Triplet<Box, Box, Box>> board; private HashMap<Point, Pair<Player, Box>> board;
private int x; private int x;
private int y; private int y;
private Player[] players;
public Grid(int x, int y){ public Grid(int x, int y, Player[] players){
this.x = x; this.x = x;
this.y = y; this.y = y;
this.players = players;
board = new HashMap<>(); board = new HashMap<>();
} }
@ -41,44 +44,68 @@ public class Grid {
} else { } else {
box = null; box = null;
} }
board.put(new Point(i,j), new Triplet<>(box, null, null)); board.put(new Point(i,j), new Pair<>(null,box));
} }
} }
} }
public void placePlayersBRUT(){
// TODO: 18/10/2021 board.get(new Point(1,1)).setA(players[0]);
public void placePlayers() { 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() { public void printGrid() {
for (int i = 0; i < x; i++) { for (int i = 0; i < x; i++) {
System.out.print("\n"); System.out.print("\n");
for (int j = 0; j < y; j++) { for (int j = 0; j < y; j++) {
Triplet<Box, Box, Box> value = board.get(new Point(i, j)); Pair<Player, Box> value = board.get(new Point(i, j));
if (value.getA() instanceof Wall) { if(value.getA() instanceof Player){
if (((Wall) value.getA()).getCardinal() == Cardinal.NORTH) { 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"); 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"); 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"); 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"); 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"); 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"); 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"); 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"); System.out.print(" \033[0;33mS\033[0m");
} }
} }
else { else if(value.getB() instanceof EnergyBall){
System.out.print(" \033[0;31mO\033[0m"); 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");
}
} }
} }
} }