From de4460e92c48e46ce2fccbdd1b052b7a884d928a Mon Sep 17 00:00:00 2001 From: Mathis Date: Wed, 1 Jun 2022 20:27:51 +0200 Subject: [PATCH 1/2] bugfix LaticeApplicationWindow | ADD Constant --- .../application/LaticeApplicationWindow.java | 50 +++++++++++++++++-- src/main/java/latice/model/Constant.java | 19 +++++++ 2 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 src/main/java/latice/model/Constant.java diff --git a/src/main/java/latice/application/LaticeApplicationWindow.java b/src/main/java/latice/application/LaticeApplicationWindow.java index 6258652..6c7aee6 100644 --- a/src/main/java/latice/application/LaticeApplicationWindow.java +++ b/src/main/java/latice/application/LaticeApplicationWindow.java @@ -274,12 +274,33 @@ public class LaticeApplicationWindow extends Application { //------------------------------------------------------------------------ //###################### creating all rectangles and DragnDrop ######################// - RectangleFX rectFX = new RectangleFX(); - rectFX.createRectangle(root, pane); - rectFX.dragnDropOnAllRectangles(player1, indexTileClicked, validateBtnClickedCount); - rectFX.dragnDropOnAllRectangles(player2, indexTileClicked, validateBtnClickedCount); + //ectangleFX rectFX = new RectangleFX(); + //rectFX.createRectangle(root, pane); + //rectFX.dragnDropOnAllRectangles(player1, indexTileClicked, validateBtnClickedCount); + //rectFX.dragnDropOnAllRectangles(player2, indexTileClicked, validateBtnClickedCount); //------------------------------------------------------------------------ + //Setting drag & drop on rectangles + for(int i=0; i() { + + @Override + public void handle(DragEvent arg0) { + if (arg0.getDragboard().hasString()){ + Dragboard dragboard = arg0.getDragboard(); + + r[a][b].setFill(new ImagePattern(listTileImage.get(getIndexTileClicked()))); + } + arg0.consume(); + } + }); + + r[a][b].setOnDragExited(new EventHandler() { + @Override public void handle(DragEvent arg0) { if (arg0.isDropCompleted() == false) { @@ -332,6 +353,25 @@ public class LaticeApplicationWindow extends Application { }); + } + } + + + //rules / referee implementaion + + this.transition(namePlayer1, namePlayer2); + //root.setLeft(namePlayer1); + + //###################### display name, score and deck of each player ######################// + HBox players = new HBox(); + + ArrayList allPlayers = new ArrayList<>(); + allPlayers.add(player1); + allPlayers.add(player2); + + for (Player nameplayer : allPlayers ) { + VBox player = new VBox(); + Text name = new Text(); name.setFont(Font.font(nameplayer.getName(), FontWeight.BOLD, 20)); name.setText(nameplayer.getName()); @@ -349,7 +389,7 @@ public class LaticeApplicationWindow extends Application { players.setMargin(player, new Insets(50,0,0,55)); } System.out.println("largeur : " + root.getMaxWidth()); - players.setSpacing(850); + players.setSpacing(850); diff --git a/src/main/java/latice/model/Constant.java b/src/main/java/latice/model/Constant.java new file mode 100644 index 0000000..080c92f --- /dev/null +++ b/src/main/java/latice/model/Constant.java @@ -0,0 +1,19 @@ +package latice.model; + +public class Constant { + + //for creating rectangles + public static final int NUMBER_OF_BOX_ON_ONE_LINE = 9; + + public static final int RECTANGLE_HEIGHT = 50; + + public static final int RECTANGLE_WIDTH = 50; + + public static final int Y_CENTER = 37; + + public static final int X_CENTER = 355; + + public static final int BOX_WIDTH = 52; + + +} From 3bdcdeb237e0274525450c545258f48062cc6c7d Mon Sep 17 00:00:00 2001 From: Mathis Date: Thu, 2 Jun 2022 08:32:41 +0200 Subject: [PATCH 2/2] ADD PlayerFX | UPDATE LaticeApplicationWindow MainScreenController PlayerNameInputController --- .../application/LaticeApplicationWindow.java | 83 ++++++++----------- .../controller/MainScreenController.java | 13 ++- .../controller/PlayerNameInputController.java | 40 +++++++-- .../java/latice/model/window/PlayerFX.java | 49 +++++++++++ 4 files changed, 125 insertions(+), 60 deletions(-) create mode 100644 src/main/java/latice/model/window/PlayerFX.java diff --git a/src/main/java/latice/application/LaticeApplicationWindow.java b/src/main/java/latice/application/LaticeApplicationWindow.java index 6c7aee6..ad80c56 100644 --- a/src/main/java/latice/application/LaticeApplicationWindow.java +++ b/src/main/java/latice/application/LaticeApplicationWindow.java @@ -5,6 +5,9 @@ import java.util.HashMap; import java.util.Map; import javafx.application.Application; +import javafx.beans.binding.Bindings; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; import javafx.event.EventHandler; import javafx.fxml.FXMLLoader; import javafx.geometry.Insets; @@ -45,6 +48,7 @@ import latice.model.Tile; import latice.model.console.Deck; import latice.model.console.Rack; import latice.model.console.Score; +import latice.model.window.PlayerFX; import latice.model.window.RectangleFX; public class LaticeApplicationWindow extends Application { @@ -79,14 +83,14 @@ public class LaticeApplicationWindow extends Application { //settings players - public Player player1; - public Player player2; + //public Player player1; + //public Player player2; - //root layout - BorderPane root = new BorderPane(); + //borderPane layout + public static BorderPane borderPane = new BorderPane(); - //StackPane for background image + BorderPane root onto it - StackPane stackPane = new StackPane(); + //StackPane for background image + BorderPane onto it + StackPane root = new StackPane(); static Stage primaryStageCopy; StackPane parentStackPane = new StackPane(); @@ -118,14 +122,14 @@ public class LaticeApplicationWindow extends Application { moonErrorLabel.setFont(new Font(20)); moonErrorLabel.setTextFill(realColor.RED); topVbox.getChildren().add(moonErrorLabel); - root.setTop(topVbox); + borderPane.setTop(topVbox); //Image Pane pane = new Pane(); BackgroundImage myBG= new BackgroundImage(image, BackgroundRepeat.NO_REPEAT, BackgroundRepeat.NO_REPEAT, BackgroundPosition.CENTER, BackgroundSize.DEFAULT); - stackPane.setBackground(new Background(myBG)); + root.setBackground(new Background(myBG)); //-------------------------------------------------------------------------------------- //Creating rectangle for tiles placement @@ -147,7 +151,7 @@ public class LaticeApplicationWindow extends Application { counterI++; } - root.setCenter(pane); + borderPane.setCenter(pane); System.out.println(r); //-------------------------------------------------------------------------------------- @@ -157,7 +161,7 @@ public class LaticeApplicationWindow extends Application { for (Color color : Color.values()) { for (Shape shape : Shape.values()) { Tile tile = new Tile(color, shape); - System.out.println(color.getStringColor() + shape.getStringShape()+ ".png"); + //System.out.println(color.getStringColor() + shape.getStringShape()+ ".png"); listOfTile.add(tile); @@ -169,12 +173,15 @@ public class LaticeApplicationWindow extends Application { Deck deck2 = new Deck(listOfTile); //setting player names - //String name1 = PlayerNameInputController.getNomJoueur1().getText(); - //String name2 = PlayerNameInputController.getNomJoueur2().getText(); - - - Player player1 = new Player(namePlayer1.getText(), new Score(), deck1, new Rack(deck1)); - Player player2 = new Player(namePlayer2.getText(), new Score(), deck2, new Rack(deck2)); + StringProperty name1 = new SimpleStringProperty(); + StringProperty name2 = new SimpleStringProperty(); + //name1.bind(PlayerNameInputController.namePlayer1); + //name2.bind(PlayerNameInputController.namePlayer2); + + //Player player1 = new Player(namePlayer1.getText(), new Score(), deck1, new Rack(deck1)); + //Player player2 = new Player(namePlayer2.getText(), new Score(), deck2, new Rack(deck2)); + //Player player1 = MSC.instanciatePlayer(PlayerNameInputController.getNomJoueur1()); + //Player player2 = MSC.instanciatePlayer(PlayerNameInputController.getNomJoueur2()); //-------------------------------------------------------------------------------------- //Rack @@ -255,7 +262,7 @@ public class LaticeApplicationWindow extends Application { }); rackImage.getChildren().addAll(confirmButton, changeButton); - root.setBottom(rackImage); + borderPane.setBottom(rackImage); //Adding lists to Arraylists listRackTile = rack2.getListRackTile(); @@ -359,37 +366,10 @@ public class LaticeApplicationWindow extends Application { //rules / referee implementaion - this.transition(namePlayer1, namePlayer2); + //this.transition(namePlayer1, namePlayer2); //root.setLeft(namePlayer1); - //###################### display name, score and deck of each player ######################// - HBox players = new HBox(); - ArrayList allPlayers = new ArrayList<>(); - allPlayers.add(player1); - allPlayers.add(player2); - - for (Player nameplayer : allPlayers ) { - VBox player = new VBox(); - - Text name = new Text(); - name.setFont(Font.font(nameplayer.getName(), FontWeight.BOLD, 20)); - name.setText(nameplayer.getName()); - - Text score = new Text(); - score.setText("Score : "); - - Text nbrOfTiles = new Text(); - nbrOfTiles.setText("Tuiles restantes : "); - - player.getChildren().addAll(name, score, nbrOfTiles); - player.setSpacing(5); - - players.getChildren().add(player); - players.setMargin(player, new Insets(50,0,0,55)); - } - System.out.println("largeur : " + root.getMaxWidth()); - players.setSpacing(850); @@ -401,8 +381,9 @@ public class LaticeApplicationWindow extends Application { //-------------------------------------------------------------------------------------- setPrimaryStage(primaryStage); - setRootLayout(stackPane); - stackPane.getChildren().addAll(players, root); + + setRootLayout(root); + //root.getChildren().add(borderPane); primaryStage.setResizable(false); primaryStage.setTitle("Latice"); @@ -413,6 +394,10 @@ public class LaticeApplicationWindow extends Application { + + + + private void setDragnDropOnRack(HBox rackImage) { //Setting drag n drop on tiles for (int i=0; i<5; i++) { @@ -485,8 +470,8 @@ public class LaticeApplicationWindow extends Application { public void transition(Label player1, Label player2) { - root.setLeft(player1); - root.setRight(player2); + borderPane.setLeft(player1); + borderPane.setRight(player2); } } diff --git a/src/main/java/latice/controller/MainScreenController.java b/src/main/java/latice/controller/MainScreenController.java index 470b2e3..fd1f79a 100644 --- a/src/main/java/latice/controller/MainScreenController.java +++ b/src/main/java/latice/controller/MainScreenController.java @@ -16,6 +16,7 @@ import javafx.scene.Scene; import javafx.scene.control.Label; import javafx.scene.input.MouseEvent; import javafx.scene.layout.BorderPane; +import javafx.scene.layout.HBox; import javafx.scene.layout.StackPane; import javafx.scene.shape.Rectangle; import javafx.stage.Modality; @@ -29,6 +30,7 @@ import latice.model.Tile; import latice.model.console.Deck; import latice.model.console.Rack; import latice.model.console.Score; +import latice.model.window.PlayerFX; public class MainScreenController extends LaticeApplicationWindow{ @FXML @@ -45,9 +47,9 @@ public class MainScreenController extends LaticeApplicationWindow{ private static StackPane parentStackPaneStock; - public Player player1; public Player player2; + public HBox players; // Event Listener on Rectangle[#playButton].onMouseClicked @FXML @@ -59,6 +61,7 @@ public class MainScreenController extends LaticeApplicationWindow{ System.out.println(mainStage); if (!PlayerNameInputController.btnClicked) { playerNamesInput(event); + } } @@ -133,6 +136,9 @@ public class MainScreenController extends LaticeApplicationWindow{ System.out.println(parentStackPaneStock); parentStackPane.getChildren().add(root); + players = PlayerFX.displayPlayers(parentStackPane,player1, player2); + root.getChildren().addAll(players,LaticeApplicationWindow.borderPane); + //parameters of the animation Timeline timeline = new Timeline(); KeyValue kv = new KeyValue(root.translateYProperty(), 0, Interpolator.EASE_IN); @@ -154,6 +160,7 @@ public class MainScreenController extends LaticeApplicationWindow{ this.parentStackPane = parentStackPane; } + public Player instanciatePlayer(String namePlayer) { //###################### Instantiating of players ######################/// //create the list of all tiles @@ -161,7 +168,7 @@ public class MainScreenController extends LaticeApplicationWindow{ for (Color color : Color.values()) { for (Shape shape : Shape.values()) { Tile tile = new Tile(color, shape); - System.out.println(color.getStringColor() + shape.getStringShape()+ ".png"); + //System.out.println(color.getStringColor() + shape.getStringShape()+ ".png"); listOfTile.add(tile); @@ -174,4 +181,6 @@ public class MainScreenController extends LaticeApplicationWindow{ Player player = new Player(namePlayer, new Score(), deck, new Rack(deck)); return player; } + + } diff --git a/src/main/java/latice/controller/PlayerNameInputController.java b/src/main/java/latice/controller/PlayerNameInputController.java index 637c635..89b180c 100644 --- a/src/main/java/latice/controller/PlayerNameInputController.java +++ b/src/main/java/latice/controller/PlayerNameInputController.java @@ -1,5 +1,9 @@ package latice.controller; +import java.util.ArrayList; + +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; import javafx.fxml.FXML; import javafx.scene.Node; import javafx.scene.control.Button; @@ -8,18 +12,29 @@ import javafx.scene.input.MouseEvent; import javafx.scene.layout.StackPane; import javafx.stage.Stage; import latice.application.LaticeApplicationWindow; +import latice.model.Color; +import latice.model.Player; +import latice.model.Shape; +import latice.model.Tile; +import latice.model.console.Deck; +import latice.model.console.Rack; +import latice.model.console.Score; +import latice.model.window.PlayerFX; public class PlayerNameInputController { @FXML - private TextField nomJoueur1; + public TextField nomJoueur1; @FXML - private TextField nomJoueur2; + public TextField nomJoueur2; @FXML public Button btnValid; public static boolean btnClicked = false; MainScreenController mainScreenController = new MainScreenController(); LaticeApplicationWindow laticeApplicationWindow = new LaticeApplicationWindow(); + public static String namePlayer1; + public static String namePlayer2; + @FXML public void validBtnClicked(MouseEvent event) { System.out.println("valid Button Clicked"); @@ -27,26 +42,32 @@ public class PlayerNameInputController { //setting player names String name1 = nomJoueur1.getText(); String name2 = nomJoueur2.getText(); - + System.out.println(nomJoueur1.getText()); + System.out.println("nom des joueurs"); + System.out.println(nomJoueur2.getText()); + namePlayer1 = name1; + namePlayer2 = name2; btnClicked = true; nameInputStage.close(); playerNamesEntered(); - laticeApplicationWindow.player1 = mainScreenController.instanciatePlayer(name1); - laticeApplicationWindow.player2 = mainScreenController.instanciatePlayer(name2); + mainScreenController.player1 = mainScreenController.instanciatePlayer(name1); + mainScreenController.player2 = mainScreenController.instanciatePlayer(name2); + + //PlayerFX.displayPlayers(root ,laticeApplicationWindow.player1, laticeApplicationWindow.player2); mainScreenController.startGameInstruction(); } - public TextField getNomJoueur1() { - return nomJoueur1; + public String getNomJoueur1() { + return nomJoueur1.getText(); } public void setNomJoueur1(TextField nomJoueur1) { this.nomJoueur1 = nomJoueur1; } - public TextField getNomJoueur2() { - return nomJoueur2; + public String getNomJoueur2() { + return nomJoueur2.getText(); } public void setNomJoueur2(TextField nomJoueur2) { @@ -62,4 +83,5 @@ public class PlayerNameInputController { } + } diff --git a/src/main/java/latice/model/window/PlayerFX.java b/src/main/java/latice/model/window/PlayerFX.java new file mode 100644 index 0000000..c764e37 --- /dev/null +++ b/src/main/java/latice/model/window/PlayerFX.java @@ -0,0 +1,49 @@ +package latice.model.window; + +import java.util.ArrayList; + +import javafx.geometry.Insets; +import javafx.scene.layout.HBox; +import javafx.scene.layout.StackPane; +import javafx.scene.layout.VBox; +import javafx.scene.text.Font; +import javafx.scene.text.FontWeight; +import javafx.scene.text.Text; +import latice.model.Player; + +public class PlayerFX { + + + public static HBox displayPlayers(StackPane root, Player player1, Player player2) { + //###################### display name, score and deck of each player ######################// + HBox players = new HBox(); + + ArrayList allPlayers = new ArrayList<>(); + allPlayers.add(player1); + allPlayers.add(player2); + + for (Player nameplayer : allPlayers ) { + VBox player = new VBox(); + + Text name = new Text(); + name.setFont(Font.font(nameplayer.getName(), FontWeight.BOLD, 20)); + name.setText(nameplayer.getName()); + + Text score = new Text(); + score.setText("Score : "); + + Text nbrOfTiles = new Text(); + nbrOfTiles.setText("Tuiles restantes : "); + + player.getChildren().addAll(name, score, nbrOfTiles); + player.setSpacing(5); + + players.getChildren().add(player); + players.setMargin(player, new Insets(50,0,0,55)); + } + System.out.println("largeur : " + root.getMaxWidth()); + players.setSpacing(850); + return players; + } + +}