From 066f51b041d8cfbdf53595cac562b67508b3de74 Mon Sep 17 00:00:00 2001 From: Sami Zouari <sami.zouari@univ-lorraine.fr> Date: Thu, 27 Jan 2022 13:15:06 +0100 Subject: [PATCH] question 6 finie --- .../java/com/example/testig/Ecouteur.java | 24 +++++++++++++++---- .../com/example/testig/HelloApplication.java | 12 ++++++---- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/example/testig/Ecouteur.java b/src/main/java/com/example/testig/Ecouteur.java index 4326fc1..066e412 100644 --- a/src/main/java/com/example/testig/Ecouteur.java +++ b/src/main/java/com/example/testig/Ecouteur.java @@ -12,27 +12,33 @@ public class Ecouteur implements EventHandler<ActionEvent> { private Label label1; private Label label2; private Label label3; + private Label label4; + private int nb421 = 0; + private int nbCoups = 1; private Random random = new Random(); public Ecouteur(){} - public Ecouteur(Label l1, Label l2, Label l3){ + public Ecouteur(Label l1, Label l2, Label l3, Label l4){ this.label1 = l1; this.label2 = l2; this.label3 = l3; + this.label4 = l4; } @Override public void handle(ActionEvent actionEvent) { - System.out.println("Bienvenue dans le Jeu !"); - System.out.println("Nombre de clicks : " + compteur); + + + System.out.println("Bienvenue dans le Jeu !"); //Question 2 + System.out.println("Nombre de clicks : " + compteur); //Question 3 compteur += 1; int n, x, y; - n = random.nextInt(7); + n = random.nextInt(7); //Question 5 x = random.nextInt(7); y = random.nextInt(7); @@ -40,5 +46,15 @@ public class Ecouteur implements EventHandler<ActionEvent> { label2.setText(""+ x); label3.setText(""+ y); + if(n == 4 && x == 2 && y == 1){ + + nb421 += 1; + } + + //Question 6 + + label4.setText("Nombre de fois ou 421 est apparu : " + nb421 + " Nombre de coups joués : " + nbCoups); + nbCoups += 1; + } } diff --git a/src/main/java/com/example/testig/HelloApplication.java b/src/main/java/com/example/testig/HelloApplication.java index 2653ed9..694bad6 100644 --- a/src/main/java/com/example/testig/HelloApplication.java +++ b/src/main/java/com/example/testig/HelloApplication.java @@ -17,21 +17,25 @@ public class HelloApplication extends Application { @Override public void start(Stage stage) throws IOException { - /* question 1 */ - stage.setTitle("Titre TP!"); + + stage.setTitle("Titre TP!"); //Question 1 BorderPane border = new BorderPane(); Button bouton = new Button("Jouer"); HBox box = new HBox(); + HBox box2 = new HBox(); - Label l1 = new Label("1"); + Label l1 = new Label("1"); //Question 4 Label l2 = new Label("1"); Label l3 = new Label("1"); + Label l4 = new Label("Nombre de fois ou 421 est apparu : 0 Nombre de coups joués : 0"); box.getChildren().addAll(l1, l2, l3); + box2.getChildren().addAll(l4); border.setCenter(box); border.setBottom(bouton); - bouton.setOnAction(new Ecouteur(l1,l2,l3)); + border.setTop(box2); + bouton.setOnAction(new Ecouteur(l1,l2,l3, l4)); Scene scene = new Scene(border, 400, 400); stage.setScene(scene); stage.show(); -- GitLab