update javafx's tp

master
antoine.perederii 1 year ago
parent fe3f65775b
commit bd35ce46b2

@ -1,25 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?> <?import javafx.scene.control.Button?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.BorderPane?> <?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.text.Text?> <?import javafx.scene.text.Text?>
<BorderPane xmlns="http://javafx.com/javafx/18" xmlns:fx="http://javafx.com/fxml/1"> <?import javafx.scene.image.ImageView?>
<right> <?import javafx.scene.layout.HBox?>
<Button fx:id="buttonHold" mnemonicParsing="false" text="H" BorderPane.alignment="CENTER" />
</right> <BorderPane xmlns="http://javafx.com/javafx/18" xmlns:fx="http://javafx.com/fxml/1" fx:controller="view.Fenetre">
<left>
<Button fx:id="buttonRoll" mnemonicParsing="false" text="R" BorderPane.alignment="CENTER" />
</left>
<top> <top>
<Text fx:id="topText" text="Fight de Cedric et Jerome" BorderPane.alignment="CENTER" /> <Text fx:id="topText" text="Fight de Cedric et Jerome" BorderPane.alignment="CENTER" />
</top> </top>
<bottom>
<Text fx:id="bottomText" text="Jerome à fait 1, il pert ! Gros noob !" BorderPane.alignment="CENTER" />
</bottom>
<center> <center>
<Text fx:id="centerText" text="Jérome lance le dé, il fait 1" BorderPane.alignment="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> </center>
<bottom>
<Text fx:id="bottomText" BorderPane.alignment="CENTER" />
</bottom>
</BorderPane> </BorderPane>

@ -2,76 +2,90 @@ package view;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.text.Text; import javafx.scene.text.Text;
import launcher.ConsoleGame;
import model.Game; import model.Game;
import model.Player; import model.Player;
import java.util.Scanner; import java.util.Objects;
public class Fenetre { public class Fenetre {
@FXML @FXML
private Button buttonHold; private Button buttonHold;
@FXML @FXML
private Button buttonRoll; private Button buttonRoll;
@FXML @FXML
private Text topText; private Text topText;
@FXML @FXML
private Text bottomText; private Text bottomText;
@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();
}
@FXML
private void onButtonHoldClicked() {
game.passToNextPlayer();
hasRolled = true;
updateUI();
}
@FXML @FXML
private Text centerText; private void onButtonRollClicked() {
hasRolled = true;
game.rollDice();
// private static final String PROMPT = ", enter R to roll the dice or H to hold your score: ";
// private static final String ALLOWED_KEYS = "[rRhH]"; int diceValue = 0;
// try {
// private enum Choice {ROLL, HOLD, QUIT} diceValue = game.getDiceValue();
//// } catch (IllegalAccessException e) {
// public Choice readChoice(String playerName) { e.printStackTrace();
// if(this.buttonHold.getOnMouseClicked()) { }
// return Choice.HOLD; String imagePath = "/dice/" + diceValue + ".png";
// } else if(this.buttonRoll.getOnMouseClicked()) { Image image = new Image(getClass().getResourceAsStream(imagePath));
// return Choice.ROLL; diceImage.setImage(image);
// }
// return null; updateUI();
// }
// Si le dé affiche la valeur 1, passez au joueur suivant et mettre à jour l'interface graphique.
// public static void main(String[] args) { if (diceValue == 1) {
// Game teacherFight = new Game(); topText.setText("Le joueur précedent à perdue\n" + game.getCurrentPlayer().getName() + ", press R to roll the dice or H to hold your score.");
// teacherFight.addPlayer(new Player("Laurent")); imagePath = "/dice/0.png";
// teacherFight.addPlayer(new Player("Cédric")); image = new Image(getClass().getResourceAsStream(imagePath));
// diceImage.setImage(image);
// System.out.println("Laurent and Cédric are about to start a dice fight !"); hasRolled = false;
// }
// while (!teacherFight.isGameOver()) { }
// Player currentPlayer = teacherFight.getCurrentPlayer();
// System.out.println(currentPlayer);
// ConsoleGame.Choice choice = readChoice(currentPlayer.getName()); private void updateUI() {
// switch (choice) { Player currentPlayer = game.getCurrentPlayer();
// case ROLL -> {
// teacherFight.rollDice(); topText.setText(currentPlayer.getName() + ", press R to roll the dice or H to hold your score.");
// int diceValue = 0; bottomText.setText(currentPlayer.getName() + "(" + currentPlayer.getTotalScore() + ")" + " has currently " + currentPlayer.getCurrentScore());
// try {
// diceValue = teacherFight.getDiceValue(); if (!hasRolled) {
// } catch (IllegalAccessException e) { String imagePath = "/dice/0.png";
// teacherFight.rollDice(); Image image = new Image(getClass().getResourceAsStream(imagePath));
// } diceImage.setImage(image);
// System.out.println(currentPlayer.getName() + " is rolling the dice… and get a " + diceValue); }
// if (diceValue == Game.LOSE_DICE_VALUE) }
// System.out.println(currentPlayer.getName() + " loses his turn.");
// }
// case HOLD -> {
// teacherFight.passToNextPlayer();
// System.out.println(currentPlayer.getName() + " decides to hold his score and has now " + currentPlayer.getTotalScore());
// }
// case QUIT -> {
// System.out.println(currentPlayer.getName() + " quits.");
// return;
// }
// }
// }
//
// Player winner = teacherFight.getCurrentPlayer();
// System.out.println(winner.getName() + " wins the game !");
// }
} }

Loading…
Cancel
Save