From 4305f8963b5c78f18aa853c301dbe72ef3bf01f4 Mon Sep 17 00:00:00 2001 From: Katchan <35238981+KatchanNve@users.noreply.github.com> Date: Wed, 8 Dec 2021 12:52:25 +0100 Subject: [PATCH] Add private view --- .../java/fr/lnl/game/client/view/Cell.java | 10 ++--- .../fr/lnl/game/client/view/Terminal.java | 2 +- .../java/fr/lnl/game/client/view/View.java | 1 - .../java/fr/lnl/game/client/view/Window.java | 7 +++- .../game/server/games/action/DropMine.java | 2 +- .../fr/lnl/game/server/games/grid/Grid.java | 38 ++++++++++++++++++- .../game/server/games/grid/elements/Bomb.java | 1 + .../server/games/grid/elements/Explosive.java | 10 +++++ .../game/server/games/grid/elements/Mine.java | 4 ++ 9 files changed, 65 insertions(+), 10 deletions(-) diff --git a/client/src/main/java/fr/lnl/game/client/view/Cell.java b/client/src/main/java/fr/lnl/game/client/view/Cell.java index f0d0fd8..d5d8e7f 100644 --- a/client/src/main/java/fr/lnl/game/client/view/Cell.java +++ b/client/src/main/java/fr/lnl/game/client/view/Cell.java @@ -16,11 +16,11 @@ import javafx.scene.shape.Rectangle; */ public class Cell extends Rectangle { - private static Image PLAYER_IMAGE = new Image("player.png"); - private static Image ENERGY_BALL_IMAGE = new Image("energyBall.png"); - private static Image BOMB_IMAGE = new Image("bomb.png"); - private static Image MINE_IMAGE = new Image("mine.png"); - private static Image WALL_IMAGE = new Image("wall.jpg"); + private static final Image PLAYER_IMAGE = new Image("player.png"); + private static final Image ENERGY_BALL_IMAGE = new Image("energyBall.png"); + private static final Image BOMB_IMAGE = new Image("bomb.png"); + private static final Image MINE_IMAGE = new Image("mine.png"); + private static final Image WALL_IMAGE = new Image("wall.jpg"); public Cell(int x, int y){ setWidth(Window.cellSize); diff --git a/client/src/main/java/fr/lnl/game/client/view/Terminal.java b/client/src/main/java/fr/lnl/game/client/view/Terminal.java index 5ad8f95..1138bd9 100644 --- a/client/src/main/java/fr/lnl/game/client/view/Terminal.java +++ b/client/src/main/java/fr/lnl/game/client/view/Terminal.java @@ -19,7 +19,7 @@ public class Terminal extends AbstractView { } public void show() { - System.out.println(game.getGrid().toString()); + System.out.println(game.getGrid().privateView(player)); } @Override diff --git a/client/src/main/java/fr/lnl/game/client/view/View.java b/client/src/main/java/fr/lnl/game/client/view/View.java index f2b8df9..8bcfa2e 100644 --- a/client/src/main/java/fr/lnl/game/client/view/View.java +++ b/client/src/main/java/fr/lnl/game/client/view/View.java @@ -1,7 +1,6 @@ package fr.lnl.game.client.view; import fr.lnl.game.server.games.action.Action; -import fr.lnl.game.server.games.player.HumanPlayer; import fr.lnl.game.server.games.player.Player; public interface View { diff --git a/client/src/main/java/fr/lnl/game/client/view/Window.java b/client/src/main/java/fr/lnl/game/client/view/Window.java index 6c93e99..0815b0f 100644 --- a/client/src/main/java/fr/lnl/game/client/view/Window.java +++ b/client/src/main/java/fr/lnl/game/client/view/Window.java @@ -87,9 +87,14 @@ public class Window extends AbstractView { for (int i = 0; i < grid.getRow(); i++) { for (int j = 0; j < grid.getColumn(); j++) { Pair value = grid.getBoard().get(new Point(i, j)); - if (value.getB() instanceof Wall || value.getB() instanceof EnergyBall || value.getB() instanceof Explosive) { + if (value.getB() instanceof Wall || value.getB() instanceof EnergyBall) { addToPrincipalPanel(value.getB(), principalPane, i, j); } + if(value.getB() instanceof Explosive){ + if(((Explosive) value.getB()).getPlayer().equals(player)){ + addToPrincipalPanel(value.getB(), principalPane, i, j); + } + } if (value.getA() != null) { addToPrincipalPanel(value.getA(), principalPane, i, j); } diff --git a/server/src/main/java/fr/lnl/game/server/games/action/DropMine.java b/server/src/main/java/fr/lnl/game/server/games/action/DropMine.java index 016035b..ef27572 100644 --- a/server/src/main/java/fr/lnl/game/server/games/action/DropMine.java +++ b/server/src/main/java/fr/lnl/game/server/games/action/DropMine.java @@ -13,7 +13,7 @@ public class DropMine extends DropObject { @Override public void doAction() { - game.getGrid().getBoard().get(point).setB(new Mine()); + game.getGrid().getBoard().get(point).setB(new Mine(player)); game.getCurrentPlayer().decrementEnergy(player.getClassPlayer().getMineCost()); } 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 0d89b51..8472b9a 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 @@ -59,7 +59,7 @@ public class Grid { for (int j = 0; j < column; j++) { Pair value = board.get(new Point(i, j)); if(value.getA() != null){ - str.append(" \033[0;34mP\033[0m"); + str.append(" \033[0;34m").append(value.getA().getId()).append("\033[0m"); } else if (value.getB() instanceof Wall) { str.append(" \033[0;32m□\033[0m"); @@ -81,6 +81,42 @@ public class Grid { return str.toString(); } + public String privateView(Player player) { + StringBuilder str = new StringBuilder(); + for (int i = 0; i < row; i++) { + str.append("\n"); + for (int j = 0; j < column; j++) { + Pair value = board.get(new Point(i, j)); + if(value.getA() != null){ + str.append(" \033[0;34m").append(value.getA().getId()).append("\033[0m"); + } + else if (value.getB() instanceof Wall) { + str.append(" \033[0;32m□\033[0m"); + } + else if(value.getB() instanceof EnergyBall){ + str.append(" \033[0;31mE\033[0m"); + } + else if(value.getB() instanceof Explosive){ + if(((Explosive) value.getB()).getPlayer().equals(player)){ + if(value.getB() instanceof Mine){ + str.append(" \033[0;35mM\033[0m"); + } + else if(value.getB() instanceof Bomb){ + str.append(" \033[0;36mB\033[0m"); + } + } + else{ + str.append(" \033[0;37m.\033[0m"); + } + } + else { + str.append(" \033[0;37m.\033[0m"); + } + } + } + return str.toString(); + } + public HashMap> getBoard() { return board; } diff --git a/server/src/main/java/fr/lnl/game/server/games/grid/elements/Bomb.java b/server/src/main/java/fr/lnl/game/server/games/grid/elements/Bomb.java index a5cff21..f801a79 100644 --- a/server/src/main/java/fr/lnl/game/server/games/grid/elements/Bomb.java +++ b/server/src/main/java/fr/lnl/game/server/games/grid/elements/Bomb.java @@ -13,6 +13,7 @@ public class Bomb extends Explosive implements CountdownBox { private static int EXPLOSION_SIZE = 4; public Bomb(Point point, Game game) { + super(game.getCurrentPlayer()); this.point = point; this.game = game; counter = counter * game.getPlayers().size(); diff --git a/server/src/main/java/fr/lnl/game/server/games/grid/elements/Explosive.java b/server/src/main/java/fr/lnl/game/server/games/grid/elements/Explosive.java index dca0d3f..136a9ce 100644 --- a/server/src/main/java/fr/lnl/game/server/games/grid/elements/Explosive.java +++ b/server/src/main/java/fr/lnl/game/server/games/grid/elements/Explosive.java @@ -6,10 +6,20 @@ import fr.lnl.game.server.utils.Point; public abstract class Explosive extends AbstractBox implements InteractiveBox { + Player player; + + public Explosive(Player player){ + this.player = player; + } + @Override public void interact(Grid grid, Player player, Point position) { if(grid.getBoard().get(position).getB() == this){ grid.getBoard().get(position).setB(null); } } + + public Player getPlayer() { + return player; + } } diff --git a/server/src/main/java/fr/lnl/game/server/games/grid/elements/Mine.java b/server/src/main/java/fr/lnl/game/server/games/grid/elements/Mine.java index c0f8c3e..2818e38 100644 --- a/server/src/main/java/fr/lnl/game/server/games/grid/elements/Mine.java +++ b/server/src/main/java/fr/lnl/game/server/games/grid/elements/Mine.java @@ -6,6 +6,10 @@ import fr.lnl.game.server.utils.Point; public class Mine extends Explosive{ + public Mine(Player player) { + super(player); + } + @Override public void interact(Grid grid, Player player, Point position) { player.decrementEnergy(player.getClassPlayer().getPenaltyMine());