From 572a20bcf7d35a0a27ce56dcd3b2c87d17d15432 Mon Sep 17 00:00:00 2001 From: Valentin Lucas <21901740@etu.unicaen.fr> Date: Thu, 2 Dec 2021 16:12:30 +0100 Subject: [PATCH] =?UTF-8?q?Modification=20de=20Cell=20et=20GUI,=20Affichag?= =?UTF-8?q?e=20r=C3=A9ussie=20de=20la=20grille=20mais=20image=20pas=20enco?= =?UTF-8?q?re=20affich=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/fr/lnl/game/client/view/Cell.java | 13 ++-- .../java/fr/lnl/game/client/view/GUI.java | 73 +++++++++++++++++-- 2 files changed, 71 insertions(+), 15 deletions(-) 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 7d6eace..7028f9d 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 @@ -19,21 +19,20 @@ import javafx.scene.shape.Rectangle; public class Cell extends Rectangle { - //NON-ETABLIE + public Cell(int x, int y){ setWidth(GUI.cellSize); setHeight(GUI.cellSize); - relocate(x,y); + relocate(x*GUI.cellSize,y*GUI.cellSize); setFill(Color.valueOf("#ffffff")); setStroke(Color.DARKGRAY); } - //NON-TEST + public static StackPane setImageObject(Object object){ - Image image = null; + Image image; StackPane sp = new StackPane(); - //remplacer après par le switch dès que on aura implémenter les interfaces if(object instanceof Player){ image = new Image("file:resources/images/player.png"); @@ -47,16 +46,14 @@ public class Cell extends Rectangle { if(object instanceof Mine){ image = new Image("file:resources/images/mine.webp"); } - if(object instanceof Wall){ + else{ image = new Image("file:resources/images/wall.jpg"); } - ImageView iv = new ImageView(image); iv.setFitHeight(40); iv.setFitWidth(40); sp.getChildren().add(iv); - return sp; } diff --git a/client/src/main/java/fr/lnl/game/client/view/GUI.java b/client/src/main/java/fr/lnl/game/client/view/GUI.java index e72a922..175918f 100644 --- a/client/src/main/java/fr/lnl/game/client/view/GUI.java +++ b/client/src/main/java/fr/lnl/game/client/view/GUI.java @@ -1,18 +1,26 @@ package fr.lnl.game.client.view; -import fr.lnl.game.server.games.grid.Box; -import fr.lnl.game.server.games.grid.Grid; +import fr.lnl.game.server.games.Game; +import fr.lnl.game.server.games.grid.*; +import fr.lnl.game.server.games.player.AbstractPlayer; +import fr.lnl.game.server.games.player.ClassPlayer; import fr.lnl.game.server.games.player.Player; +import fr.lnl.game.server.games.player.RandomComputerPlayer; import fr.lnl.game.server.utils.Pair; import fr.lnl.game.server.utils.Point; import javafx.scene.Parent; import javafx.scene.Scene; +import javafx.scene.control.Button; import javafx.scene.layout.Pane; +import javafx.scene.layout.StackPane; +import javafx.scene.shape.Rectangle; import javafx.stage.Modality; import javafx.stage.Stage; +import java.util.Arrays; import java.util.HashMap; +import java.util.List; public class GUI { @@ -21,20 +29,20 @@ public class GUI { Stage stage; Scene scene; Grid grid; - String text =""; - //temporaire public static final int cellSize = 40; public static final int width = 24; public static final int height = 16; - public GUI(){ + public GUI() { stage = new Stage(); stage.initModality(Modality.APPLICATION_MODAL); - //ce n'est pas à la vue de gérer ça donc à voir - //grid = getGrid(); + //à enlever avec sa méthode car ne respecte pas mvc + grid = getGrid(); + scene = new Scene(createContent()); + stage.setScene(scene); stage.setTitle("Game"); stage.setResizable(false); @@ -43,10 +51,61 @@ public class GUI { private Parent createContent() { Pane principalPane = new Pane(); + principalPane.setPrefSize(width * cellSize, height * cellSize); + //PARTIE1 + //à définir avec n pour moduler la taille du plateau + for (int i = 0; i < 16; i++) { + for (int j = 0; j < 16; j++) { + Cell cell = new Cell(i, j); + principalPane.getChildren().add(cell); + } + } + //PARTIE2 + board = grid.getBoard(); + for (int i = 0; i < 16; i++) { + for (int j = 0; j < 16; j++) { + Pair value = board.get(new Point(i, j)); + if (value.getA() != null) { + addToPrincipalPanel(value.getA(), principalPane, i, j); + } + if (value.getB() instanceof Wall || value.getB() instanceof EnergyBall || value.getB() instanceof Mine || value.getB() instanceof Bomb) { + addToPrincipalPanel(value.getB(), principalPane, i, j); + } + } + } + //PARTIE3 + Button followingButton = new Button("SUIVANT"); + followingButton.setLayoutX(775); + followingButton.setLayoutY(600); + followingButton.setStyle("-fx-background-color: #a96806;"); + followingButton.setTextFill(javafx.scene.paint.Color.WHITE); + //add un eventListener au button + + principalPane.getChildren().add(followingButton); + return principalPane; + } + + public Pane addToPrincipalPanel(Object object, Pane principalPane, int i, int j) { + StackPane sp = Cell.setImageObject(object); + sp.setLayoutY(i * cellSize); + sp.setLayoutX(j * cellSize); + principalPane.getChildren().add(sp); return principalPane; } + //méthode à supprimer existe juste pour test + private Grid getGrid() { + List players = Arrays.asList(new RandomComputerPlayer(1, null, ClassPlayer.DEFAULT), + new RandomComputerPlayer(2, null, ClassPlayer.DEFAULT)); + Grid grid = new Grid(16, 16, players); + grid.placePlayersBRUT(); + grid.placeEnergyBallBRUT(); + grid.placeInternWallBRUT(); + return grid; + } + + }