diff --git a/src/main/java/com/example/testig/Ecouteur.java b/src/main/java/com/example/testig/Ecouteur.java index 4326fc1bf24ae9e94f66b8695ba935eb5db0708e..066e4124cd1611477a9c025eaa33edbac1450070 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 2653ed9c9c83600f54cf05f04b85c53c19af109f..694bad68969197d8da8a397a7d06546a78394e43 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();