Add private view

This commit is contained in:
Katchan 2021-12-08 12:52:25 +01:00
parent 609966d9af
commit 4305f8963b
9 changed files with 65 additions and 10 deletions

View File

@ -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);

View File

@ -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

View File

@ -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 {

View File

@ -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<Player, Box> 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);
}

View File

@ -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());
}

View File

@ -59,7 +59,7 @@ public class Grid {
for (int j = 0; j < column; j++) {
Pair<Player, Box> 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<Player, Box> 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<Point, Pair<Player, Box>> getBoard() {
return board;
}

View File

@ -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();

View File

@ -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;
}
}

View File

@ -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());