Improve display of classes in the view, add player shield icon

This commit is contained in:
Katchan 2021-12-08 18:54:52 +01:00
parent 2e99366e56
commit 4c52bedc9f
8 changed files with 38 additions and 23 deletions

View File

@ -17,6 +17,7 @@ import javafx.scene.shape.Rectangle;
public class Cell extends Rectangle { public class Cell extends Rectangle {
private static final Image PLAYER_IMAGE = new Image("player.png"); private static final Image PLAYER_IMAGE = new Image("player.png");
private static final Image PLAYER_SHIELD_IMAGE = new Image("player_shield.png");
private static final Image ENERGY_BALL_IMAGE = new Image("energyBall.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 BOMB_IMAGE = new Image("bomb.png");
private static final Image MINE_IMAGE = new Image("mine.png"); private static final Image MINE_IMAGE = new Image("mine.png");
@ -36,7 +37,12 @@ public class Cell extends Rectangle {
StackPane sp = new StackPane(); StackPane sp = new StackPane();
Image in; Image in;
if(object instanceof Player){ if(object instanceof Player){
in = PLAYER_IMAGE; if(((Player) object).isShieldDeploy()){
in = PLAYER_SHIELD_IMAGE;
}
else{
in = PLAYER_IMAGE;
}
} else if(object instanceof EnergyBall){ } else if(object instanceof EnergyBall){
in = ENERGY_BALL_IMAGE; in = ENERGY_BALL_IMAGE;
} else if(object instanceof Bomb){ } else if(object instanceof Bomb){

View File

@ -24,12 +24,12 @@ public class Terminal extends AbstractView {
@Override @Override
public void displayWinner(Player winner) { public void displayWinner(Player winner) {
System.out.println("Le joueur " + winner + " a gagné la partie"); System.out.println(winner + " " + winner.getId() + " a gagné la partie");
} }
@Override @Override
public Action choseAction() { public Action choseAction() {
List<ReunionSameAction> actions = generateAvailableActions(); List<ReunionSameAction> actions = player.generateAvailableActions();
List<Action> listActions = choseReunionSameAction(actions).getActions(); List<Action> listActions = choseReunionSameAction(actions).getActions();
Action action = null; Action action = null;
String error = "Veuillez renseigner une valeur numérique comprise entre 1 et " + listActions.size(); String error = "Veuillez renseigner une valeur numérique comprise entre 1 et " + listActions.size();

View File

@ -27,7 +27,7 @@ public record ViewManager(
} }
boolean isOver = game.play(); boolean isOver = game.play();
System.out.println("Le joueur ordinateur numéro " + player.getId() + " a joué"); System.out.println("Le joueur ordinateur numéro " + player.getId() + " a joué");
System.out.println("Il a joué l'action: " + game.getSelectedAction()); System.out.println("Il a joué l'action: " + game.getSelectedAction().getClass().getSimpleName());
if (isOver) { if (isOver) {
displayWinnerEvent.updateModel(game.getWinner()); displayWinnerEvent.updateModel(game.getWinner());
System.exit(0); System.exit(0);

View File

@ -62,7 +62,7 @@ public class Window extends AbstractView {
@Override @Override
public Action choseAction() { public Action choseAction() {
List<ReunionSameAction> actions = generateAvailableActions(); List<ReunionSameAction> actions = player.generateAvailableActions();
List<Action> listActions = choseReunionSameAction(actions).getActions(); List<Action> listActions = choseReunionSameAction(actions).getActions();
Action action = null; Action action = null;
do { do {
@ -125,7 +125,7 @@ public class Window extends AbstractView {
public void putStatePlayerPane(Pane principalPane){ public void putStatePlayerPane(Pane principalPane){
int Y = 0; int Y = 0;
for(int i=0;i<game.getPlayers().size();i++){ for(int i=0;i<game.getPlayers().size();i++){
StackPane sp = showStatePlayer(i); StackPane sp = showStatePlayer(game.getPlayers().get(i).toString(),i);
sp.setLayoutX(480); sp.setLayoutX(480);
sp.setLayoutY(Y); sp.setLayoutY(Y);
Y+=90; Y+=90;
@ -133,9 +133,9 @@ public class Window extends AbstractView {
} }
} }
public StackPane showStatePlayer(int playerNumber){ public StackPane showStatePlayer(String type, int playerNumber){
StackPane subSp = new StackPane(); StackPane subSp = new StackPane();
String s = "Joueur " + (playerNumber+1) + "\n" + String s = type + " " + (playerNumber+1) + "\n" +
"Energie : " + game.getPlayers().get(playerNumber).getEnergy() + "\n" + "Energie : " + game.getPlayers().get(playerNumber).getEnergy() + "\n" +
"Arme : " + game.getPlayers().get(playerNumber).getWeapon().getClass().getSimpleName() + "\n"; "Arme : " + game.getPlayers().get(playerNumber).getWeapon().getClass().getSimpleName() + "\n";
Text t = new Text(s); Text t = new Text(s);
@ -161,8 +161,9 @@ public class Window extends AbstractView {
public StackPane showMoveText(){ public StackPane showMoveText(){
StackPane subSp = new StackPane(); StackPane subSp = new StackPane();
String s = "Joueur : " + (player.getId()+1) + "\n" + String action = game.getSelectedAction() == null ? "null" : game.getSelectedAction().getClass().getSimpleName();
"Vient de jouer : " + game.getSelectedAction() + "\n"; String s = player + " : " + (player.getId()+1) + "\n" +
"Vient de jouer : " + action + "\n";
Text t = new Text(s); Text t = new Text(s);
Rectangle r = new Rectangle(); Rectangle r = new Rectangle();
r.setWidth(478); r.setWidth(478);

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

View File

@ -1,7 +1,6 @@
package fr.lnl.game.server.games.action; package fr.lnl.game.server.games.action;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
/** /**

View File

@ -90,7 +90,7 @@ public class Grid {
str.append(" \033[0;34m").append(value.getA().getId()).append("\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");
} }
else if(value.getB() instanceof EnergyBall){ else if(value.getB() instanceof EnergyBall){
str.append(" \033[0;31mE\033[0m"); str.append(" \033[0;31mE\033[0m");
@ -119,7 +119,7 @@ public class Grid {
str.append(" \033[0;34m").append(value.getA().getId()).append("\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");
} }
else if(value.getB() instanceof EnergyBall){ else if(value.getB() instanceof EnergyBall){
str.append(" \033[0;31mE\033[0m"); str.append(" \033[0;31mE\033[0m");
@ -149,6 +149,14 @@ public class Grid {
return board; return board;
} }
public Player getGridPlayer(Point point){
return getBoard().get(point).getA();
}
public Box getGridBox(Point point){
return getBoard().get(point).getB();
}
public List<Player> getPlayers() { public List<Player> getPlayers() {
return players; return players;
} }

View File

@ -1,7 +1,9 @@
package fr.lnl.game.server.games.player; package fr.lnl.game.server.games.player;
import fr.lnl.game.server.games.Game;
import fr.lnl.game.server.games.action.Action; import fr.lnl.game.server.games.action.Action;
import fr.lnl.game.server.games.action.Nothing; import fr.lnl.game.server.games.action.Nothing;
import fr.lnl.game.server.games.grid.Grid;
import fr.lnl.game.server.utils.Point; import fr.lnl.game.server.utils.Point;
import java.util.Random; import java.util.Random;
@ -13,18 +15,17 @@ public class RandomComputerPlayer extends ComputerPlayer {
} }
@Override @Override
public Action choseAction() { public Action strategy(Game game) {
Action action = null; Action action = null;
switch (getActions().size()){ Random random = new Random();
case 0 -> action = new Nothing(); while (action == null || !action.isPossible()) {
case 1 -> action = getActions().get(0); action = getActions().get(random.nextInt(0, getActions().size()));
default -> {
Random random = new Random();
while (action == null || !action.isPossible()) {
action = getActions().get(random.nextInt(0,getActions().size()));
}
}
} }
return action; return action;
} }
@Override
public String toString() {
return "Random";
}
} }