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; + } + + }