Add private view
This commit is contained in:
parent
609966d9af
commit
4305f8963b
@ -16,11 +16,11 @@ import javafx.scene.shape.Rectangle;
|
|||||||
*/
|
*/
|
||||||
public class Cell extends Rectangle {
|
public class Cell extends Rectangle {
|
||||||
|
|
||||||
private static Image PLAYER_IMAGE = new Image("player.png");
|
private static final Image PLAYER_IMAGE = new Image("player.png");
|
||||||
private static Image ENERGY_BALL_IMAGE = new Image("energyBall.png");
|
private static final Image ENERGY_BALL_IMAGE = new Image("energyBall.png");
|
||||||
private static Image BOMB_IMAGE = new Image("bomb.png");
|
private static final Image BOMB_IMAGE = new Image("bomb.png");
|
||||||
private static Image MINE_IMAGE = new Image("mine.png");
|
private static final Image MINE_IMAGE = new Image("mine.png");
|
||||||
private static Image WALL_IMAGE = new Image("wall.jpg");
|
private static final Image WALL_IMAGE = new Image("wall.jpg");
|
||||||
|
|
||||||
public Cell(int x, int y){
|
public Cell(int x, int y){
|
||||||
setWidth(Window.cellSize);
|
setWidth(Window.cellSize);
|
||||||
|
@ -19,7 +19,7 @@ public class Terminal extends AbstractView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void show() {
|
public void show() {
|
||||||
System.out.println(game.getGrid().toString());
|
System.out.println(game.getGrid().privateView(player));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package fr.lnl.game.client.view;
|
package fr.lnl.game.client.view;
|
||||||
|
|
||||||
import fr.lnl.game.server.games.action.Action;
|
import fr.lnl.game.server.games.action.Action;
|
||||||
import fr.lnl.game.server.games.player.HumanPlayer;
|
|
||||||
import fr.lnl.game.server.games.player.Player;
|
import fr.lnl.game.server.games.player.Player;
|
||||||
|
|
||||||
public interface View {
|
public interface View {
|
||||||
|
@ -87,9 +87,14 @@ public class Window extends AbstractView {
|
|||||||
for (int i = 0; i < grid.getRow(); i++) {
|
for (int i = 0; i < grid.getRow(); i++) {
|
||||||
for (int j = 0; j < grid.getColumn(); j++) {
|
for (int j = 0; j < grid.getColumn(); j++) {
|
||||||
Pair<Player, Box> value = grid.getBoard().get(new Point(i, 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);
|
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) {
|
if (value.getA() != null) {
|
||||||
addToPrincipalPanel(value.getA(), principalPane, i, j);
|
addToPrincipalPanel(value.getA(), principalPane, i, j);
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ public class DropMine extends DropObject {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doAction() {
|
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());
|
game.getCurrentPlayer().decrementEnergy(player.getClassPlayer().getMineCost());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ public class Grid {
|
|||||||
for (int j = 0; j < column; j++) {
|
for (int j = 0; j < column; j++) {
|
||||||
Pair<Player, Box> value = board.get(new Point(i, j));
|
Pair<Player, Box> value = board.get(new Point(i, j));
|
||||||
if(value.getA() != null){
|
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) {
|
else if (value.getB() instanceof Wall) {
|
||||||
str.append(" \033[0;32m□\033[0m");
|
str.append(" \033[0;32m□\033[0m");
|
||||||
@ -81,6 +81,42 @@ public class Grid {
|
|||||||
return str.toString();
|
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() {
|
public HashMap<Point, Pair<Player, Box>> getBoard() {
|
||||||
return board;
|
return board;
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ public class Bomb extends Explosive implements CountdownBox {
|
|||||||
private static int EXPLOSION_SIZE = 4;
|
private static int EXPLOSION_SIZE = 4;
|
||||||
|
|
||||||
public Bomb(Point point, Game game) {
|
public Bomb(Point point, Game game) {
|
||||||
|
super(game.getCurrentPlayer());
|
||||||
this.point = point;
|
this.point = point;
|
||||||
this.game = game;
|
this.game = game;
|
||||||
counter = counter * game.getPlayers().size();
|
counter = counter * game.getPlayers().size();
|
||||||
|
@ -6,10 +6,20 @@ import fr.lnl.game.server.utils.Point;
|
|||||||
|
|
||||||
public abstract class Explosive extends AbstractBox implements InteractiveBox {
|
public abstract class Explosive extends AbstractBox implements InteractiveBox {
|
||||||
|
|
||||||
|
Player player;
|
||||||
|
|
||||||
|
public Explosive(Player player){
|
||||||
|
this.player = player;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void interact(Grid grid, Player player, Point position) {
|
public void interact(Grid grid, Player player, Point position) {
|
||||||
if(grid.getBoard().get(position).getB() == this){
|
if(grid.getBoard().get(position).getB() == this){
|
||||||
grid.getBoard().get(position).setB(null);
|
grid.getBoard().get(position).setB(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Player getPlayer() {
|
||||||
|
return player;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,10 @@ import fr.lnl.game.server.utils.Point;
|
|||||||
|
|
||||||
public class Mine extends Explosive{
|
public class Mine extends Explosive{
|
||||||
|
|
||||||
|
public Mine(Player player) {
|
||||||
|
super(player);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void interact(Grid grid, Player player, Point position) {
|
public void interact(Grid grid, Player player, Point position) {
|
||||||
player.decrementEnergy(player.getClassPlayer().getPenaltyMine());
|
player.decrementEnergy(player.getClassPlayer().getPenaltyMine());
|
||||||
|
Loading…
Reference in New Issue
Block a user