update javafx's tp with beautiful graphics

master
antoine.perederii 2 years ago
parent 0df9fb988a
commit 6d6cc5b013

@ -1,23 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.text.Text?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.text.Text?>
<BorderPane xmlns="http://javafx.com/javafx/18" xmlns:fx="http://javafx.com/fxml/1" fx:controller="view.Fenetre">
<top>
<Text fx:id="topText" text="Fight de Cedric et Jerome" BorderPane.alignment="CENTER" />
</top>
<center>
<HBox spacing="10" alignment="CENTER">
<Button fx:id="buttonHold" mnemonicParsing="false" text="Hold" onAction="#onButtonHoldClicked" />
<ImageView fx:id="diceImage" fitHeight="150.0" fitWidth="150.0" preserveRatio="true" />
<Button fx:id="buttonRoll" mnemonicParsing="false" text="Roll" onAction="#onButtonRollClicked"/>
</HBox>
</center>
<bottom>
<Text fx:id="bottomText" BorderPane.alignment="CENTER" />
</bottom>
<BorderPane style="-fx-background-color: #ecf0f1;" xmlns="http://javafx.com/javafx/18" xmlns:fx="http://javafx.com/fxml/1" fx:controller="view.Fenetre">
<top>
<Text fx:id="topText" text="Fight de Cedric et Jerome" BorderPane.alignment="CENTER" style="-fx-background-color: #3498db;" />
</top>
<center>
<HBox alignment="CENTER" spacing="10" style="-fx-background-color: #ecf0f1;">
<Button fx:id="buttonHold" mnemonicParsing="false" onAction="#onButtonHoldClicked" style="-fx-background-color: #f39c12;" text="Hold" />
<ImageView fx:id="diceImage" fitHeight="150.0" fitWidth="150.0" preserveRatio="true" />
<Button fx:id="buttonRoll" mnemonicParsing="false" onAction="#onButtonRollClicked" style="-fx-background-color: #2ecc71;" text="Roll" />
</HBox>
</center>
<bottom>
<Text fx:id="bottomText" BorderPane.alignment="CENTER" style="-fx-background-color: #e74c3c;" />
</bottom>
</BorderPane>

@ -0,0 +1,13 @@
package data;
import model.Game;
import model.Player;
public class Stub {
public Game loadPlayer() {
Game game = new Game();
game.addPlayer(new Player("Cedric"));
game.addPlayer(new Player("Jérome"));
return game;
}
}

@ -5,10 +5,7 @@ import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import view.Fenetre;
import java.io.IOException;
import java.util.Objects;
public class Launch extends Application {
Parent root = FXMLLoader.load(getClass().getResource("/fxml/Fenetre.fxml"));

@ -1,5 +1,6 @@
package view;
import data.Stub;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.image.Image;
@ -27,17 +28,7 @@ public class Fenetre {
@FXML
private ImageView diceImage;
private boolean hasRolled = false;
private Game game;
private final Player p1 = new Player("Cedrice");
private final Player p2 = new Player("Jerome");
public void initialize() {
game = new Game();
game.addPlayer(p1);
game.addPlayer(p2);
updateUI();
}
private final Game game = new Stub().loadPlayer();
@FXML
private void onButtonHoldClicked() {
@ -85,7 +76,22 @@ public class Fenetre {
Image image = new Image(getClass().getResourceAsStream(imagePath));
diceImage.setImage(image);
}
// Vérifier si un joueur a gagné
if (currentPlayer.getTotalScore() >= Game.SCORE_TO_WIN) {
topText.setText(currentPlayer.getName() + " wins the game!");
topText.setStyle("-fx-fill: #e74c3c;"); // Définir la couleur du texte en rouge
buttonRoll.setDisable(true);
buttonHold.setDisable(true);
} else {
// Si le jeu n'est pas terminé, utilisez la couleur par défaut ou une autre couleur de votre choix
topText.setStyle("-fx-fill: black;");
}
}
public void initialize() {
// topText.textProperty().bind(game.getCurrentPlayer());
updateUI();
}
}

Loading…
Cancel
Save