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;
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<Tile> listRackTile;
ArrayList<Image> listRackImage;
ArrayList<Tile> listOfTile = new ArrayList<Tile>();
Map<Rectangle, Tile> assocRectangleTile = new HashMap<Rectangle, Tile>();
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;
}

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.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() {

View File

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

View File

@ -7,19 +7,18 @@
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.Pane?>
<BorderPane prefHeight="241.0" prefWidth="386.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/17">
<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">
<center>
<Pane prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER">
<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="221.0" layoutY="163.0" mnemonicParsing="false" prefHeight="51.0" prefWidth="129.0" textFill="TRANSPARENT" />
<ImageView fitHeight="241.0" fitWidth="386.0" pickOnBounds="true" preserveRatio="true">
<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="replayBtn" layoutX="175.0" layoutY="555.0" mnemonicParsing="false" onMouseClicked="#replayBtnClicked" prefHeight="140.0" prefWidth="380.0" textFill="TRANSPARENT" />
<ImageView fitHeight="720.0" fitWidth="1280.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../../../resources/GameFinishedImage.png" />
<Image url="@/gameFinishedImage.png" />
</image>
</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>
</Pane>
</center>

View File

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