From 4c52bedc9f59b47911cc8dbbed2d294236d59777 Mon Sep 17 00:00:00 2001 From: Katchan <35238981+KatchanNve@users.noreply.github.com> Date: Wed, 8 Dec 2021 18:54:52 +0100 Subject: [PATCH] Improve display of classes in the view, add player shield icon --- .../java/fr/lnl/game/client/view/Cell.java | 8 ++++++- .../fr/lnl/game/client/view/Terminal.java | 4 ++-- .../fr/lnl/game/client/view/ViewManager.java | 2 +- .../java/fr/lnl/game/client/view/Window.java | 13 ++++++----- client/src/main/resources/player_shield.png | Bin 0 -> 7833 bytes .../games/action/ReunionSameAction.java | 1 - .../fr/lnl/game/server/games/grid/Grid.java | 12 ++++++++-- .../games/player/RandomComputerPlayer.java | 21 +++++++++--------- 8 files changed, 38 insertions(+), 23 deletions(-) create mode 100644 client/src/main/resources/player_shield.png diff --git a/client/src/main/java/fr/lnl/game/client/view/Cell.java b/client/src/main/java/fr/lnl/game/client/view/Cell.java index d5d8e7f..23ccd9f 100644 --- a/client/src/main/java/fr/lnl/game/client/view/Cell.java +++ b/client/src/main/java/fr/lnl/game/client/view/Cell.java @@ -17,6 +17,7 @@ import javafx.scene.shape.Rectangle; 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 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"); @@ -36,7 +37,12 @@ public class Cell extends Rectangle { StackPane sp = new StackPane(); Image in; if(object instanceof Player){ - in = PLAYER_IMAGE; + if(((Player) object).isShieldDeploy()){ + in = PLAYER_SHIELD_IMAGE; + } + else{ + in = PLAYER_IMAGE; + } } else if(object instanceof EnergyBall){ in = ENERGY_BALL_IMAGE; } else if(object instanceof Bomb){ diff --git a/client/src/main/java/fr/lnl/game/client/view/Terminal.java b/client/src/main/java/fr/lnl/game/client/view/Terminal.java index 1138bd9..0162831 100644 --- a/client/src/main/java/fr/lnl/game/client/view/Terminal.java +++ b/client/src/main/java/fr/lnl/game/client/view/Terminal.java @@ -24,12 +24,12 @@ public class Terminal extends AbstractView { @Override 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 public Action choseAction() { - List actions = generateAvailableActions(); + List actions = player.generateAvailableActions(); List listActions = choseReunionSameAction(actions).getActions(); Action action = null; String error = "Veuillez renseigner une valeur numérique comprise entre 1 et " + listActions.size(); diff --git a/client/src/main/java/fr/lnl/game/client/view/ViewManager.java b/client/src/main/java/fr/lnl/game/client/view/ViewManager.java index 0280a77..6e89f8c 100644 --- a/client/src/main/java/fr/lnl/game/client/view/ViewManager.java +++ b/client/src/main/java/fr/lnl/game/client/view/ViewManager.java @@ -27,7 +27,7 @@ public record ViewManager( } 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()); + System.out.println("Il a joué l'action: " + game.getSelectedAction().getClass().getSimpleName()); if (isOver) { displayWinnerEvent.updateModel(game.getWinner()); System.exit(0); diff --git a/client/src/main/java/fr/lnl/game/client/view/Window.java b/client/src/main/java/fr/lnl/game/client/view/Window.java index 0815b0f..059433a 100644 --- a/client/src/main/java/fr/lnl/game/client/view/Window.java +++ b/client/src/main/java/fr/lnl/game/client/view/Window.java @@ -62,7 +62,7 @@ public class Window extends AbstractView { @Override public Action choseAction() { - List actions = generateAvailableActions(); + List actions = player.generateAvailableActions(); List listActions = choseReunionSameAction(actions).getActions(); Action action = null; do { @@ -125,7 +125,7 @@ public class Window extends AbstractView { public void putStatePlayerPane(Pane principalPane){ int Y = 0; for(int i=0;i1jyE_yFcXti$?hv$a3JvbiNRZ$J_u%dh!2%WBoeqM!k$f6+=BLe^cG1X_tp~15&%G5 zoZq8*(whymkke2G03y%;5P^WI57fX5aIv;;XMF=Xd+=lZXEzXb+na~ zRFjvK1gg0@S=l;(006!IDq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+FQQnoi%V`we3ZIrP;9HtVIQYpUt}M?9VQBCm&ZWOaU^Ww60_|Ss$NU{x zP)^o(@aPlOAU>bFeFSu71SWZK6LU|D=U(n6daAfa)GPQ;IyUymf_~&^yy-}%mzkpZ zL0;(>u2*Q%dWvooE>HMJ{!=0zom{Pyl;+q4(Zzss?iuVI?${qO+|%4H-2)LJoX{M! zll!I{$MG;hMV3|B9RFwk?sBXepY1I>pH->kkrj{k^DZk=f`|c5U$;LFRh^_;)|5lg zU}jLuraZnwySMwO$G-~1C$vbc%(XKhrSsx&JzD*hVRd4^tqS#6q0i3NM*=mZa?9#) z{}66QbgnFoVH=EtshWw^RrJ+|D&a5|VhN~SO2o-RxnI?WNP60BU**!Tm09CWn7uqS zwP#@K%^gVAiN?C!_;kCzi=EgrP)gEw_73qE40R#|mHEI_hq!cSb--yYZ~vt93x%nN zTCX7$Fd1<7 zijx?HL?6z`SOnKKD^bTa6qrgX<|v$CqnAz3_!_hq`pyu#N7n+mPy9Tcwe%r^&TIUx z=xla?*{K>+Jlm7s=NqMKAC=urwyhgkxuuO#^BIn(IQL_Bqt<8)EK153Ai z;XAgI374FYxY}wXq!~vYG9MrtdrRd^T7uU7zT)6{ getPlayers() { return players; } diff --git a/server/src/main/java/fr/lnl/game/server/games/player/RandomComputerPlayer.java b/server/src/main/java/fr/lnl/game/server/games/player/RandomComputerPlayer.java index f735b49..35ee9fa 100644 --- a/server/src/main/java/fr/lnl/game/server/games/player/RandomComputerPlayer.java +++ b/server/src/main/java/fr/lnl/game/server/games/player/RandomComputerPlayer.java @@ -1,7 +1,9 @@ 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.Nothing; +import fr.lnl.game.server.games.grid.Grid; import fr.lnl.game.server.utils.Point; import java.util.Random; @@ -13,18 +15,17 @@ public class RandomComputerPlayer extends ComputerPlayer { } @Override - public Action choseAction() { + public Action strategy(Game game) { Action action = null; - switch (getActions().size()){ - case 0 -> action = new Nothing(); - case 1 -> action = getActions().get(0); - default -> { - Random random = new Random(); - while (action == null || !action.isPossible()) { - action = getActions().get(random.nextInt(0,getActions().size())); - } - } + Random random = new Random(); + while (action == null || !action.isPossible()) { + action = getActions().get(random.nextInt(0, getActions().size())); } return action; } + + @Override + public String toString() { + return "Random"; + } }