Improve display in terminal view and add Shot icon in Window view

This commit is contained in:
Katchan 2021-12-08 21:47:34 +01:00
parent 417d311435
commit dab710597b
6 changed files with 23 additions and 6 deletions

View File

@ -1,5 +1,7 @@
package fr.lnl.game.client.view;
import fr.lnl.game.server.games.Game;
import fr.lnl.game.server.games.action.Shot;
import fr.lnl.game.server.games.grid.elements.Bomb;
import fr.lnl.game.server.games.grid.elements.EnergyBall;
import fr.lnl.game.server.games.grid.elements.Mine;
@ -18,6 +20,7 @@ public class Cell extends Rectangle {
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 PLAYER_SHOT_IMAGE = new Image("player_shot.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");
@ -33,11 +36,14 @@ public class Cell extends Rectangle {
public static StackPane setImageObject(Object object){
public static StackPane setImageObject(Object object, Game game){
StackPane sp = new StackPane();
Image in;
if(object instanceof Player){
if(((Player) object).isShieldDeploy()){
if(object.equals(game.getCurrentPlayer()) && game.getSelectedAction() instanceof Shot){
in = PLAYER_SHOT_IMAGE;
}
else if(((Player) object).isShieldDeploy()){
in = PLAYER_SHIELD_IMAGE;
}
else{

View File

@ -24,7 +24,9 @@ public class Terminal extends AbstractView {
@Override
public void displayWinner(Player winner) {
System.out.println(winner + " " + winner.getId() + " a gagné la partie");
System.out.println("\n\033[0;31m====== FIN DU JEU ======\033[0m");
System.out.println(game.getGrid().toString());
System.out.println("\n\033[0;33mVictoire de " + winner + " " + winner.getId() + "\033[0m");
}
@Override

View File

@ -21,13 +21,15 @@ public record ViewManager(
DisplayWinnerEvent displayWinnerEvent = new DisplayWinnerEvent();
while (true) {
Player player = game.getCurrentPlayer();
System.out.println("\n\033[0;34m====== Tour n°" + game.getNbrTurn() + " =======\033[0m");
System.out.println("\nA \033[0;31m" + player + " " + player.getId() + "\033[0m de jouer");
players.get(game.getCurrentPlayer()).getView().show();
if(game.getCurrentPlayer() instanceof HumanPlayer human) {
game.setSelectedAction(players.get(human).getView().choseAction());
}
boolean isOver = game.play();
System.out.println("Le joueur ordinateur numéro " + player.getId() + " a joué");
System.out.println("Il a joué l'action: " + game.getSelectedAction().getClass().getSimpleName());
System.out.println("\n\033[0;31m" + player + " " + player.getId() + "\033[0m utilise l'action \033[0;36m"+
game.getSelectedAction().getClass().getSimpleName() + "\033[0m");
if (isOver) {
displayWinnerEvent.updateModel(game.getWinner());
System.exit(0);

View File

@ -113,7 +113,7 @@ public class Window extends AbstractView {
}
public void addToPrincipalPanel(Object object, Pane principalPane, int i, int j) {
StackPane sp = Cell.setImageObject(object);
StackPane sp = Cell.setImageObject(object, game);
sp.setLayoutY(i * cellSize);
sp.setLayoutX(j * cellSize);
principalPane.getChildren().add(sp);

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

View File

@ -21,6 +21,7 @@ public class Game {
private final List<Player> players;
private Player currentPlayer;
private Action selectedAction = null;
private int nbrTurn;
public Game(GridFactoryBuilder buildStrategy, List<Player> players) throws IllegalArgumentException {
this.grid = buildStrategy.build();
@ -32,6 +33,7 @@ public class Game {
this.buildStrategy = buildStrategy;
this.players = players;
this.currentPlayer = players.get(0);
this.nbrTurn = 1;
initGame();
}
@ -53,6 +55,7 @@ public class Game {
gridPlayersUpdate();
nextCurrentPlayer();
currentPlayer.setActions(generateAndGetPlayerActions(currentPlayer));
nbrTurn++;
return isOver();
}
@ -140,4 +143,8 @@ public class Game {
public void setSelectedAction(Action selectedAction) {
this.selectedAction = selectedAction;
}
public int getNbrTurn() {
return nbrTurn;
}
}