Modification de Cell et GUI, Affichage réussie de la grille mais image pas encore affichée
This commit is contained in:
parent
2ebd51f011
commit
572a20bcf7
@ -19,21 +19,20 @@ import javafx.scene.shape.Rectangle;
|
|||||||
|
|
||||||
public class Cell extends Rectangle {
|
public class Cell extends Rectangle {
|
||||||
|
|
||||||
//NON-ETABLIE
|
|
||||||
public Cell(int x, int y){
|
public Cell(int x, int y){
|
||||||
setWidth(GUI.cellSize);
|
setWidth(GUI.cellSize);
|
||||||
setHeight(GUI.cellSize);
|
setHeight(GUI.cellSize);
|
||||||
relocate(x,y);
|
relocate(x*GUI.cellSize,y*GUI.cellSize);
|
||||||
setFill(Color.valueOf("#ffffff"));
|
setFill(Color.valueOf("#ffffff"));
|
||||||
setStroke(Color.DARKGRAY);
|
setStroke(Color.DARKGRAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//NON-TEST
|
|
||||||
public static StackPane setImageObject(Object object){
|
public static StackPane setImageObject(Object object){
|
||||||
Image image = null;
|
Image image;
|
||||||
StackPane sp = new StackPane();
|
StackPane sp = new StackPane();
|
||||||
//remplacer après par le switch dès que on aura implémenter les interfaces
|
|
||||||
|
|
||||||
if(object instanceof Player){
|
if(object instanceof Player){
|
||||||
image = new Image("file:resources/images/player.png");
|
image = new Image("file:resources/images/player.png");
|
||||||
@ -47,16 +46,14 @@ public class Cell extends Rectangle {
|
|||||||
if(object instanceof Mine){
|
if(object instanceof Mine){
|
||||||
image = new Image("file:resources/images/mine.webp");
|
image = new Image("file:resources/images/mine.webp");
|
||||||
}
|
}
|
||||||
if(object instanceof Wall){
|
else{
|
||||||
image = new Image("file:resources/images/wall.jpg");
|
image = new Image("file:resources/images/wall.jpg");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ImageView iv = new ImageView(image);
|
ImageView iv = new ImageView(image);
|
||||||
iv.setFitHeight(40);
|
iv.setFitHeight(40);
|
||||||
iv.setFitWidth(40);
|
iv.setFitWidth(40);
|
||||||
sp.getChildren().add(iv);
|
sp.getChildren().add(iv);
|
||||||
|
|
||||||
return sp;
|
return sp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,18 +1,26 @@
|
|||||||
package fr.lnl.game.client.view;
|
package fr.lnl.game.client.view;
|
||||||
|
|
||||||
|
|
||||||
import fr.lnl.game.server.games.grid.Box;
|
import fr.lnl.game.server.games.Game;
|
||||||
import fr.lnl.game.server.games.grid.Grid;
|
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.Player;
|
||||||
|
import fr.lnl.game.server.games.player.RandomComputerPlayer;
|
||||||
import fr.lnl.game.server.utils.Pair;
|
import fr.lnl.game.server.utils.Pair;
|
||||||
import fr.lnl.game.server.utils.Point;
|
import fr.lnl.game.server.utils.Point;
|
||||||
import javafx.scene.Parent;
|
import javafx.scene.Parent;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
|
import javafx.scene.control.Button;
|
||||||
import javafx.scene.layout.Pane;
|
import javafx.scene.layout.Pane;
|
||||||
|
import javafx.scene.layout.StackPane;
|
||||||
|
import javafx.scene.shape.Rectangle;
|
||||||
import javafx.stage.Modality;
|
import javafx.stage.Modality;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class GUI {
|
public class GUI {
|
||||||
|
|
||||||
@ -21,20 +29,20 @@ public class GUI {
|
|||||||
Stage stage;
|
Stage stage;
|
||||||
Scene scene;
|
Scene scene;
|
||||||
Grid grid;
|
Grid grid;
|
||||||
String text ="";
|
|
||||||
|
|
||||||
|
|
||||||
//temporaire
|
|
||||||
public static final int cellSize = 40;
|
public static final int cellSize = 40;
|
||||||
public static final int width = 24;
|
public static final int width = 24;
|
||||||
public static final int height = 16;
|
public static final int height = 16;
|
||||||
|
|
||||||
public GUI(){
|
public GUI() {
|
||||||
stage = new Stage();
|
stage = new Stage();
|
||||||
stage.initModality(Modality.APPLICATION_MODAL);
|
stage.initModality(Modality.APPLICATION_MODAL);
|
||||||
//ce n'est pas à la vue de gérer ça donc à voir
|
//à enlever avec sa méthode car ne respecte pas mvc
|
||||||
//grid = getGrid();
|
grid = getGrid();
|
||||||
|
|
||||||
scene = new Scene(createContent());
|
scene = new Scene(createContent());
|
||||||
|
|
||||||
stage.setScene(scene);
|
stage.setScene(scene);
|
||||||
stage.setTitle("Game");
|
stage.setTitle("Game");
|
||||||
stage.setResizable(false);
|
stage.setResizable(false);
|
||||||
@ -43,10 +51,61 @@ public class GUI {
|
|||||||
|
|
||||||
private Parent createContent() {
|
private Parent createContent() {
|
||||||
Pane principalPane = new Pane();
|
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<Player, Box> 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;
|
return principalPane;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//méthode à supprimer existe juste pour test
|
||||||
|
private Grid getGrid() {
|
||||||
|
List<Player> 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user