added finished game screen and adjustments to player name input

master
Cemal Odabasioglu 2022-06-04 16:41:01 +02:00
parent 9310eb6bc7
commit a8e96c3306
9 changed files with 163 additions and 73 deletions

View File

@ -1,5 +1,6 @@
package latice.application; package latice.application;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -41,6 +42,7 @@ import javafx.scene.text.Font;
import javafx.scene.text.Text; import javafx.scene.text.Text;
import javafx.stage.Stage; import javafx.stage.Stage;
import javafx.util.Duration; import javafx.util.Duration;
import latice.controller.GameFinishedScreenController;
import latice.controller.MainScreenController; import latice.controller.MainScreenController;
import latice.model.Color; import latice.model.Color;
import latice.model.Constant; import latice.model.Constant;
@ -64,10 +66,7 @@ public class LaticeApplicationWindow extends Application {
ArrayList<Tile> listRackTile; ArrayList<Tile> listRackTile;
ArrayList<Image> listRackImage; ArrayList<Image> listRackImage;
ArrayList<Tile> listOfTile = new ArrayList<Tile>(); ArrayList<Tile> listOfTile = new ArrayList<Tile>();
Map<Rectangle, Tile> assocRectangleTile = new HashMap<Rectangle, Tile>();
static StackPane rootLayout; static StackPane rootLayout;
private Label namePlayer1 = new Label("Anonyme");
private Label namePlayer2 = new Label("Anonyme");
public static int indexTileClicked; public static int indexTileClicked;
@ -108,13 +107,13 @@ public class LaticeApplicationWindow extends Application {
StackPane root = new StackPane(); StackPane root = new StackPane();
static Stage primaryStageCopy; Stage primaryStageCopy;
StackPane parentStackPane = new StackPane(); StackPane parentStackPane = new StackPane();
Label ErrorLabel = new Label(); Label ErrorLabel = new Label();
HBox rackImage; HBox rackImage;
int validateBtnClickedCount; int confirmBtnClickedCount;
public static void main(String[] args) { public static void main(String[] args) {
@ -132,8 +131,7 @@ public class LaticeApplicationWindow extends Application {
MainScreenController MSC = new MainScreenController(); MainScreenController MSC = new MainScreenController();
parentStackPane = MSC.getParentStackPane(); parentStackPane = MSC.getParentStackPane();
primaryStageCopy = primaryStage;
setPrimaryStage(primaryStageCopy);
setRootLayout(root); setRootLayout(root);
@ -146,14 +144,14 @@ public class LaticeApplicationWindow extends Application {
public void startGame(Stage stage, StackPane parentStackPaneStock, Player player1, Player player2, Object menuBorderPane) { public void startGame(Stage stage, StackPane parentStackPaneStock, Player player1, Player player2, Object menuBorderPane) {
parentStackPane = parentStackPaneStock; parentStackPane = parentStackPaneStock;
//StackPane root = getRootLayout(); StackPane root = getRootLayout();
//root.translateYProperty().set(stage.getHeight()); root.translateYProperty().set(stage.getHeight());
System.out.println(parentStackPane); System.out.println(parentStackPane);
System.out.println(parentStackPaneStock); System.out.println(parentStackPaneStock);
parentStackPane.getChildren().add(root); parentStackPane.getChildren().add(root);
//parameters of the animation //settings for the animation
Timeline timeline = new Timeline(); Timeline timeline = new Timeline();
KeyValue kv = new KeyValue(root.translateYProperty(), 0, Interpolator.EASE_IN); KeyValue kv = new KeyValue(root.translateYProperty(), 0, Interpolator.EASE_IN);
KeyFrame kf = new KeyFrame(Duration.seconds(1), kv); KeyFrame kf = new KeyFrame(Duration.seconds(1), kv);
@ -301,7 +299,14 @@ public class LaticeApplicationWindow extends Application {
System.out.println("confirmed placement"); System.out.println("confirmed placement");
validateBtnClickedCount++; try {
switchToGameFinishedScreen();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
confirmBtnClickedCount++;
player.getRack().displayRack(); player.getRack().displayRack();
player.getRack().updateRack(); 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); playerFX.setFillName(Constant.realColor.BLACK);
player = player1; player = player1;
playerFX = player1FX; 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(); player.getRack().updateRack();
////// changing player ////// ////// changing player //////
validateBtnClickedCount++; confirmBtnClickedCount++;
if (validateBtnClickedCount%2 == 0) { if (confirmBtnClickedCount%2 == 0) {
playerFX.setFillName(Constant.realColor.BLACK); playerFX.setFillName(Constant.realColor.BLACK);
player = player1; player = player1;
playerFX = player1FX; playerFX = player1FX;
@ -684,7 +704,7 @@ public class LaticeApplicationWindow extends Application {
public static int getIndexTileClicked() { public static int getIndexTileClicked() {
return indexTileClicked; return indexTileClicked;
} }
public void setPrimaryStage(Stage primaryStage) { public void setPrimaryStage(Stage primaryStage) {
this.primaryStageCopy = primaryStage; this.primaryStageCopy = primaryStage;
} }

View File

@ -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");
}
}

View File

@ -7,12 +7,14 @@ import javafx.beans.property.StringProperty;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.Node; import javafx.scene.Node;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField; import javafx.scene.control.TextField;
import javafx.scene.input.MouseEvent; import javafx.scene.input.MouseEvent;
import javafx.scene.layout.StackPane; import javafx.scene.layout.StackPane;
import javafx.stage.Stage; import javafx.stage.Stage;
import latice.application.LaticeApplicationWindow; import latice.application.LaticeApplicationWindow;
import latice.model.Color; import latice.model.Color;
import latice.model.Constant;
import latice.model.Player; import latice.model.Player;
import latice.model.Shape; import latice.model.Shape;
import latice.model.Tile; import latice.model.Tile;
@ -28,6 +30,11 @@ public class PlayerNameInputController {
public TextField nomJoueur2; public TextField nomJoueur2;
@FXML @FXML
public Button btnValid; public Button btnValid;
@FXML
public Label label1;
@FXML
public Label label2;
public static boolean btnClicked = false; public static boolean btnClicked = false;
MainScreenController mainScreenController = new MainScreenController(); MainScreenController mainScreenController = new MainScreenController();
LaticeApplicationWindow laticeApplicationWindow = new LaticeApplicationWindow(); LaticeApplicationWindow laticeApplicationWindow = new LaticeApplicationWindow();
@ -35,27 +42,38 @@ public class PlayerNameInputController {
public static String namePlayer1; public static String namePlayer1;
public static String namePlayer2; public static String namePlayer2;
@FXML @FXML
public void validBtnClicked(MouseEvent event) { public void validBtnClicked(MouseEvent event) {
System.out.println("valid Button Clicked"); 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; if(nomJoueur1.getText().length() < 3 || nomJoueur1.getText().length() > 16) {
nameInputStage.close(); label1.setVisible(true);
playerNamesEntered(); }
mainScreenController.player1 = mainScreenController.instanciatePlayer(name1); if(nomJoueur2.getText().length() < 3 || nomJoueur2.getText().length() > 16) {
mainScreenController.player2 = mainScreenController.instanciatePlayer(name2); label2.setVisible(true);
}
//PlayerFX.displayPlayers(root ,laticeApplicationWindow.player1, laticeApplicationWindow.player2); else {
mainScreenController.startGameInstruction();
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() { public String getNomJoueur1() {

View File

@ -71,7 +71,8 @@ public class PlayGame {
static Stage primaryStageCopy; static Stage primaryStageCopy;
int validateBtnClickedCount;
int confirmBtnClickedCount;
public Stage playGame(Stage StageToGame) { public Stage playGame(Stage StageToGame) {
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
@ -93,8 +94,8 @@ public class PlayGame {
//###################### creating all rectangles and DragnDrop ######################// //###################### creating all rectangles and DragnDrop ######################//
RectangleFX rectFX = new RectangleFX(); RectangleFX rectFX = new RectangleFX();
rectFX.createRectangle(borderPane, pane); rectFX.createRectangle(borderPane, pane);
rectFX.dragnDropOnAllRectangles(player1, indexTileClicked, validateBtnClickedCount); rectFX.dragnDropOnAllRectangles(player1, indexTileClicked, confirmBtnClickedCount);
rectFX.dragnDropOnAllRectangles(player2, indexTileClicked, validateBtnClickedCount); rectFX.dragnDropOnAllRectangles(player2, indexTileClicked, confirmBtnClickedCount);
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
borderPane.setCenter(pane); borderPane.setCenter(pane);
@ -139,7 +140,7 @@ public class PlayGame {
@Override @Override
public void handle(MouseEvent arg0) { public void handle(MouseEvent arg0) {
validateBtnClickedCount++; confirmBtnClickedCount++;
System.out.println("confirmed placement"); System.out.println("confirmed placement");
} }

View File

@ -7,19 +7,18 @@
<?import javafx.scene.layout.BorderPane?> <?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.Pane?> <?import javafx.scene.layout.Pane?>
<BorderPane prefHeight="720.0" prefWidth="1280.0" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" fx:controller="latice.controller.GameFinishedScreenController">
<BorderPane prefHeight="241.0" prefWidth="386.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/17">
<center> <center>
<Pane prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER"> <Pane prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER">
<children> <children>
<Button fx:id="replayBtn" layoutX="42.0" layoutY="163.0" mnemonicParsing="false" prefHeight="50.0" prefWidth="127.0" textFill="TRANSPARENT" /> <Button fx:id="quitBtn" layoutX="750.0" layoutY="555.0" mnemonicParsing="false" onMouseClicked="#quitBtnClicked" prefHeight="140.0" prefWidth="380.0" textFill="TRANSPARENT" />
<Button fx:id="quitBtn" layoutX="221.0" layoutY="163.0" mnemonicParsing="false" prefHeight="51.0" prefWidth="129.0" textFill="TRANSPARENT" /> <Button fx:id="replayBtn" layoutX="175.0" layoutY="555.0" mnemonicParsing="false" onMouseClicked="#replayBtnClicked" prefHeight="140.0" prefWidth="380.0" textFill="TRANSPARENT" />
<ImageView fitHeight="241.0" fitWidth="386.0" pickOnBounds="true" preserveRatio="true"> <ImageView fitHeight="720.0" fitWidth="1280.0" pickOnBounds="true" preserveRatio="true">
<image> <image>
<Image url="@../../../resources/GameFinishedImage.png" /> <Image url="@/gameFinishedImage.png" />
</image> </image>
</ImageView> </ImageView>
<Label alignment="CENTER_RIGHT" layoutX="4.0" layoutY="73.0" prefHeight="22.0" prefWidth="154.0" textAlignment="CENTER" /> <Label fx:id="nameWinner" alignment="CENTER_RIGHT" layoutX="450.0" layoutY="250.0" prefHeight="22.0" prefWidth="300.0" textAlignment="CENTER" />
</children> </children>
</Pane> </Pane>
</center> </center>

View File

@ -4,37 +4,62 @@
<?import javafx.scene.control.Button?> <?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?> <?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?> <?import javafx.scene.control.TextField?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.ColumnConstraints?> <?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?> <?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?> <?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.StackPane?>
<?import javafx.scene.text.Font?>
<GridPane alignment="CENTER" hgap="50.0" prefHeight="300.0" prefWidth="600.0" vgap="10.0" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" fx:controller="latice.controller.PlayerNameInputController"> <StackPane xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" fx:controller="latice.controller.PlayerNameInputController">
<children> <children>
<Label alignment="TOP_LEFT" text="Nom joueur 1 : "> <ImageView fitHeight="402.0" fitWidth="633.0" pickOnBounds="true" preserveRatio="true">
<GridPane.margin> <image>
<Insets left="35.0" /> <Image url="@/namesInputBackground.jpg" />
</GridPane.margin> </image>
</Label> </ImageView>
<Label text="Nom joueur 2 : " GridPane.columnIndex="1"> <GridPane alignment="CENTER" hgap="50.0" prefHeight="300.0" prefWidth="600.0" vgap="10.0">
<GridPane.margin> <children>
<Insets left="35.0" /> <Label alignment="TOP_LEFT" text="Name Player 1 :" textFill="#ff00f5" GridPane.rowIndex="1">
</GridPane.margin> <GridPane.margin>
</Label> <Insets />
<TextField fx:id="nomJoueur1" GridPane.rowIndex="1" /> </GridPane.margin>
<TextField fx:id="nomJoueur2" GridPane.columnIndex="1" GridPane.rowIndex="1" /> <font>
<Button fx:id="validBtn" mnemonicParsing="false" onMouseClicked="#validBtnClicked" text="Valider" GridPane.columnIndex="1" GridPane.rowIndex="2"> <Font name="Arial Black" size="18.0" />
<GridPane.margin> </font>
<Insets left="100.0" top="50.0" /> </Label>
</GridPane.margin> <TextField fx:id="nomJoueur1" GridPane.rowIndex="2" />
</Button> <TextField fx:id="nomJoueur2" GridPane.columnIndex="1" GridPane.rowIndex="2" />
</children> <Label fx:id="label1" text="Please enter a name between 3-16 caracters" textFill="RED" underline="true" visible="false" GridPane.rowIndex="3">
<columnConstraints> <font>
<ColumnConstraints /> <Font size="13.0" />
<ColumnConstraints /> </font></Label>
</columnConstraints> <Label fx:id="label2" text="Please enter a name between 3-16 caracters" textFill="RED" underline="true" visible="false" GridPane.columnIndex="1" GridPane.rowIndex="3">
<rowConstraints> <font>
<RowConstraints maxHeight="39.99999389648437" minHeight="22.40001831054687" prefHeight="25.599999999999994" /> <Font size="13.0" />
<RowConstraints maxHeight="25.59998168945313" minHeight="8.00000610351563" prefHeight="22.400000000000006" /> </font></Label>
<RowConstraints maxHeight="25.59998168945313" minHeight="10.0" prefHeight="30.0" /> <Button fx:id="validBtn" defaultButton="true" mnemonicParsing="false" onMouseClicked="#validBtnClicked" text="Valider" GridPane.columnIndex="1" GridPane.rowIndex="3">
</rowConstraints> <GridPane.margin>
</GridPane> <Insets left="100.0" top="100.0" />
</GridPane.margin>
</Button>
<Label alignment="CENTER" text="Name Player 2 :" textFill="#ff00f5" GridPane.columnIndex="1" GridPane.rowIndex="1">
<font>
<Font name="Arial Black" size="18.0" />
</font>
</Label>
</children>
<columnConstraints>
<ColumnConstraints />
<ColumnConstraints />
</columnConstraints>
<rowConstraints>
<RowConstraints />
<RowConstraints maxHeight="39.99999389648437" minHeight="22.40001831054687" prefHeight="25.599999999999994" />
<RowConstraints maxHeight="25.59998168945313" minHeight="8.00000610351563" prefHeight="22.400000000000006" />
<RowConstraints maxHeight="25.59998168945313" minHeight="10.0" prefHeight="30.0" />
</rowConstraints>
</GridPane>
</children>
</StackPane>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 228 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 MiB