diff --git a/src/main/java/latice/application/LaticeApplicationWindow.java b/src/main/java/latice/application/LaticeApplicationWindow.java index 3a21188..16ce422 100644 --- a/src/main/java/latice/application/LaticeApplicationWindow.java +++ b/src/main/java/latice/application/LaticeApplicationWindow.java @@ -1,5 +1,6 @@ package latice.application; +import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; @@ -41,6 +42,7 @@ import javafx.scene.text.Font; import javafx.scene.text.Text; import javafx.stage.Stage; import javafx.util.Duration; +import latice.controller.GameFinishedScreenController; import latice.controller.MainScreenController; import latice.model.Color; import latice.model.Constant; @@ -64,10 +66,7 @@ public class LaticeApplicationWindow extends Application { ArrayList listRackTile; ArrayList listRackImage; ArrayList listOfTile = new ArrayList(); - Map assocRectangleTile = new HashMap(); static StackPane rootLayout; - private Label namePlayer1 = new Label("Anonyme"); - private Label namePlayer2 = new Label("Anonyme"); public static int indexTileClicked; @@ -108,13 +107,13 @@ public class LaticeApplicationWindow extends Application { StackPane root = new StackPane(); - static Stage primaryStageCopy; + Stage primaryStageCopy; StackPane parentStackPane = new StackPane(); Label ErrorLabel = new Label(); HBox rackImage; - int validateBtnClickedCount; + int confirmBtnClickedCount; public static void main(String[] args) { @@ -132,8 +131,7 @@ public class LaticeApplicationWindow extends Application { MainScreenController MSC = new MainScreenController(); parentStackPane = MSC.getParentStackPane(); - - setPrimaryStage(primaryStageCopy); + primaryStageCopy = primaryStage; setRootLayout(root); @@ -146,14 +144,14 @@ public class LaticeApplicationWindow extends Application { public void startGame(Stage stage, StackPane parentStackPaneStock, Player player1, Player player2, Object menuBorderPane) { parentStackPane = parentStackPaneStock; - //StackPane root = getRootLayout(); - //root.translateYProperty().set(stage.getHeight()); + StackPane root = getRootLayout(); + root.translateYProperty().set(stage.getHeight()); System.out.println(parentStackPane); System.out.println(parentStackPaneStock); parentStackPane.getChildren().add(root); - //parameters of the animation + //settings for the animation Timeline timeline = new Timeline(); KeyValue kv = new KeyValue(root.translateYProperty(), 0, Interpolator.EASE_IN); KeyFrame kf = new KeyFrame(Duration.seconds(1), kv); @@ -301,7 +299,14 @@ public class LaticeApplicationWindow extends Application { System.out.println("confirmed placement"); - validateBtnClickedCount++; + try { + switchToGameFinishedScreen(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + confirmBtnClickedCount++; player.getRack().displayRack(); player.getRack().updateRack(); @@ -321,7 +326,7 @@ public class LaticeApplicationWindow extends Application { - if (validateBtnClickedCount%2 == 0) { + if (confirmBtnClickedCount%2 == 0) { playerFX.setFillName(Constant.realColor.BLACK); player = player1; playerFX = player1FX; @@ -344,6 +349,21 @@ public class LaticeApplicationWindow extends Application { } + private void switchToGameFinishedScreen() throws IOException { + System.out.println("confirmBtnClickedCount : " + confirmBtnClickedCount); + if (confirmBtnClickedCount>=2) { + Parent loader = FXMLLoader.load(getClass().getResource("../view/GameFinishedScreen.fxml")); + Scene gameFinishedScreenScene = new Scene(loader, 1280, 720); + System.out.println("lancement :::::" + stage); + //TODO saisir le nom du gagnant : GameFinishedScreenController.nameWinner.setText(); + stage.setScene(gameFinishedScreenScene); + + //---------------------------------------- + + + } + } + }); @@ -382,8 +402,8 @@ public class LaticeApplicationWindow extends Application { player.getRack().updateRack(); ////// changing player ////// - validateBtnClickedCount++; - if (validateBtnClickedCount%2 == 0) { + confirmBtnClickedCount++; + if (confirmBtnClickedCount%2 == 0) { playerFX.setFillName(Constant.realColor.BLACK); player = player1; playerFX = player1FX; @@ -684,7 +704,7 @@ public class LaticeApplicationWindow extends Application { public static int getIndexTileClicked() { return indexTileClicked; } - public void setPrimaryStage(Stage primaryStage) { + public void setPrimaryStage(Stage primaryStage) { this.primaryStageCopy = primaryStage; } diff --git a/src/main/java/latice/controller/GameFinishedScreenController.java b/src/main/java/latice/controller/GameFinishedScreenController.java new file mode 100644 index 0000000..ee92af2 --- /dev/null +++ b/src/main/java/latice/controller/GameFinishedScreenController.java @@ -0,0 +1,27 @@ +package latice.controller; + +import javafx.fxml.FXML; + +import javafx.scene.control.Button; +import javafx.scene.control.Label; +import javafx.scene.input.MouseEvent; + +public class GameFinishedScreenController { + @FXML + private Button replayBtn; + @FXML + private Button quitBtn; + @FXML + public static Label nameWinner; + + // Event Listener on Button[#replayBtn].onMouseClicked + @FXML + public void replayBtnClicked(MouseEvent event) { + System.out.println("replayBtnClicked"); + } + // Event Listener on Button[#quitBtn].onMouseClicked + @FXML + public void quitBtnClicked(MouseEvent event) { + System.out.println("quitBtnClicked"); + } +} diff --git a/src/main/java/latice/controller/PlayerNameInputController.java b/src/main/java/latice/controller/PlayerNameInputController.java index 89b180c..de617dc 100644 --- a/src/main/java/latice/controller/PlayerNameInputController.java +++ b/src/main/java/latice/controller/PlayerNameInputController.java @@ -7,12 +7,14 @@ import javafx.beans.property.StringProperty; import javafx.fxml.FXML; import javafx.scene.Node; import javafx.scene.control.Button; +import javafx.scene.control.Label; import javafx.scene.control.TextField; 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.Constant; import latice.model.Player; import latice.model.Shape; import latice.model.Tile; @@ -28,6 +30,11 @@ public class PlayerNameInputController { public TextField nomJoueur2; @FXML public Button btnValid; + @FXML + public Label label1; + @FXML + public Label label2; + public static boolean btnClicked = false; MainScreenController mainScreenController = new MainScreenController(); LaticeApplicationWindow laticeApplicationWindow = new LaticeApplicationWindow(); @@ -35,27 +42,38 @@ public class PlayerNameInputController { public static String namePlayer1; public static String namePlayer2; + @FXML public void validBtnClicked(MouseEvent event) { System.out.println("valid Button Clicked"); - Stage nameInputStage = (Stage) ((Node) event.getTarget()).getScene().getWindow(); - //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(); - mainScreenController.player1 = mainScreenController.instanciatePlayer(name1); - mainScreenController.player2 = mainScreenController.instanciatePlayer(name2); - - //PlayerFX.displayPlayers(root ,laticeApplicationWindow.player1, laticeApplicationWindow.player2); - mainScreenController.startGameInstruction(); + if(nomJoueur1.getText().length() < 3 || nomJoueur1.getText().length() > 16) { + label1.setVisible(true); + } + if(nomJoueur2.getText().length() < 3 || nomJoueur2.getText().length() > 16) { + label2.setVisible(true); + } + else { + + Stage nameInputStage = (Stage) ((Node) event.getTarget()).getScene().getWindow(); + //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(); + mainScreenController.player1 = mainScreenController.instanciatePlayer(name1); + mainScreenController.player2 = mainScreenController.instanciatePlayer(name2); + + //PlayerFX.displayPlayers(root ,laticeApplicationWindow.player1, laticeApplicationWindow.player2); + mainScreenController.startGameInstruction(); + } } public String getNomJoueur1() { diff --git a/src/main/java/latice/model/window/PlayGame.java b/src/main/java/latice/model/window/PlayGame.java index 5301049..684dae4 100644 --- a/src/main/java/latice/model/window/PlayGame.java +++ b/src/main/java/latice/model/window/PlayGame.java @@ -71,7 +71,8 @@ public class PlayGame { static Stage primaryStageCopy; - int validateBtnClickedCount; + + int confirmBtnClickedCount; public Stage playGame(Stage StageToGame) { //-------------------------------------------------------------------------------------- @@ -93,8 +94,8 @@ public class PlayGame { //###################### creating all rectangles and DragnDrop ######################// RectangleFX rectFX = new RectangleFX(); rectFX.createRectangle(borderPane, pane); - rectFX.dragnDropOnAllRectangles(player1, indexTileClicked, validateBtnClickedCount); - rectFX.dragnDropOnAllRectangles(player2, indexTileClicked, validateBtnClickedCount); + rectFX.dragnDropOnAllRectangles(player1, indexTileClicked, confirmBtnClickedCount); + rectFX.dragnDropOnAllRectangles(player2, indexTileClicked, confirmBtnClickedCount); //-------------------------------------------------------------------------------------- borderPane.setCenter(pane); @@ -139,7 +140,7 @@ public class PlayGame { @Override public void handle(MouseEvent arg0) { - validateBtnClickedCount++; + confirmBtnClickedCount++; System.out.println("confirmed placement"); } diff --git a/src/main/java/latice/view/GameFinishedScreen.fxml b/src/main/java/latice/view/GameFinishedScreen.fxml index de9474d..a064209 100644 --- a/src/main/java/latice/view/GameFinishedScreen.fxml +++ b/src/main/java/latice/view/GameFinishedScreen.fxml @@ -7,19 +7,18 @@ - - +
-
diff --git a/src/main/java/latice/view/PlayerNameInput.fxml b/src/main/java/latice/view/PlayerNameInput.fxml index 294994e..290d88c 100644 --- a/src/main/java/latice/view/PlayerNameInput.fxml +++ b/src/main/java/latice/view/PlayerNameInput.fxml @@ -4,37 +4,62 @@ + + + + - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/GameFinishedImage.png b/src/main/resources/GameFinishedImage.png deleted file mode 100644 index b40dc15..0000000 Binary files a/src/main/resources/GameFinishedImage.png and /dev/null differ diff --git a/src/main/resources/gameFinishedImage.png b/src/main/resources/gameFinishedImage.png new file mode 100644 index 0000000..d5532ec Binary files /dev/null and b/src/main/resources/gameFinishedImage.png differ diff --git a/src/main/resources/namesInputBackground.jpg b/src/main/resources/namesInputBackground.jpg new file mode 100644 index 0000000..4b80def Binary files /dev/null and b/src/main/resources/namesInputBackground.jpg differ