Improve display in terminal view and add Shot icon in Window view
This commit is contained in:
parent
417d311435
commit
dab710597b
@ -1,5 +1,7 @@
|
|||||||
package fr.lnl.game.client.view;
|
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.Bomb;
|
||||||
import fr.lnl.game.server.games.grid.elements.EnergyBall;
|
import fr.lnl.game.server.games.grid.elements.EnergyBall;
|
||||||
import fr.lnl.game.server.games.grid.elements.Mine;
|
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_IMAGE = new Image("player.png");
|
||||||
private static final Image PLAYER_SHIELD_IMAGE = new Image("player_shield.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 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");
|
||||||
@ -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();
|
StackPane sp = new StackPane();
|
||||||
Image in;
|
Image in;
|
||||||
if(object instanceof Player){
|
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;
|
in = PLAYER_SHIELD_IMAGE;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
@ -24,7 +24,9 @@ public class Terminal extends AbstractView {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void displayWinner(Player winner) {
|
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
|
@Override
|
||||||
|
@ -21,13 +21,15 @@ public record ViewManager(
|
|||||||
DisplayWinnerEvent displayWinnerEvent = new DisplayWinnerEvent();
|
DisplayWinnerEvent displayWinnerEvent = new DisplayWinnerEvent();
|
||||||
while (true) {
|
while (true) {
|
||||||
Player player = game.getCurrentPlayer();
|
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();
|
players.get(game.getCurrentPlayer()).getView().show();
|
||||||
if(game.getCurrentPlayer() instanceof HumanPlayer human) {
|
if(game.getCurrentPlayer() instanceof HumanPlayer human) {
|
||||||
game.setSelectedAction(players.get(human).getView().choseAction());
|
game.setSelectedAction(players.get(human).getView().choseAction());
|
||||||
}
|
}
|
||||||
boolean isOver = game.play();
|
boolean isOver = game.play();
|
||||||
System.out.println("Le joueur ordinateur numéro " + player.getId() + " a joué");
|
System.out.println("\n\033[0;31m" + player + " " + player.getId() + "\033[0m utilise l'action \033[0;36m"+
|
||||||
System.out.println("Il a joué l'action: " + game.getSelectedAction().getClass().getSimpleName());
|
game.getSelectedAction().getClass().getSimpleName() + "\033[0m");
|
||||||
if (isOver) {
|
if (isOver) {
|
||||||
displayWinnerEvent.updateModel(game.getWinner());
|
displayWinnerEvent.updateModel(game.getWinner());
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
|
@ -113,7 +113,7 @@ public class Window extends AbstractView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void addToPrincipalPanel(Object object, Pane principalPane, int i, int j) {
|
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.setLayoutY(i * cellSize);
|
||||||
sp.setLayoutX(j * cellSize);
|
sp.setLayoutX(j * cellSize);
|
||||||
principalPane.getChildren().add(sp);
|
principalPane.getChildren().add(sp);
|
||||||
|
BIN
client/src/main/resources/player_shot.png
Normal file
BIN
client/src/main/resources/player_shot.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.9 KiB |
@ -21,6 +21,7 @@ public class Game {
|
|||||||
private final List<Player> players;
|
private final List<Player> players;
|
||||||
private Player currentPlayer;
|
private Player currentPlayer;
|
||||||
private Action selectedAction = null;
|
private Action selectedAction = null;
|
||||||
|
private int nbrTurn;
|
||||||
|
|
||||||
public Game(GridFactoryBuilder buildStrategy, List<Player> players) throws IllegalArgumentException {
|
public Game(GridFactoryBuilder buildStrategy, List<Player> players) throws IllegalArgumentException {
|
||||||
this.grid = buildStrategy.build();
|
this.grid = buildStrategy.build();
|
||||||
@ -32,6 +33,7 @@ public class Game {
|
|||||||
this.buildStrategy = buildStrategy;
|
this.buildStrategy = buildStrategy;
|
||||||
this.players = players;
|
this.players = players;
|
||||||
this.currentPlayer = players.get(0);
|
this.currentPlayer = players.get(0);
|
||||||
|
this.nbrTurn = 1;
|
||||||
initGame();
|
initGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,6 +55,7 @@ public class Game {
|
|||||||
gridPlayersUpdate();
|
gridPlayersUpdate();
|
||||||
nextCurrentPlayer();
|
nextCurrentPlayer();
|
||||||
currentPlayer.setActions(generateAndGetPlayerActions(currentPlayer));
|
currentPlayer.setActions(generateAndGetPlayerActions(currentPlayer));
|
||||||
|
nbrTurn++;
|
||||||
return isOver();
|
return isOver();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,4 +143,8 @@ public class Game {
|
|||||||
public void setSelectedAction(Action selectedAction) {
|
public void setSelectedAction(Action selectedAction) {
|
||||||
this.selectedAction = selectedAction;
|
this.selectedAction = selectedAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getNbrTurn() {
|
||||||
|
return nbrTurn;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user