Ajout des capacités spéciales

This commit is contained in:
Paul Gross
2020-05-13 10:35:38 +02:00
parent 80f7266ffb
commit dc3414c023
7 changed files with 146 additions and 112 deletions

View File

@ -23,16 +23,27 @@ import main.GestionnaireJeu;
public class LancerDes {
private int resultat;
private Contexte contexte;
public LancerDes(Contexte c){
contexte = c;
private int typeDe;
private int[] rolls;
private final static int LANCER_DE_4 = 0;
private final static int LANCER_DE_6 = 1;
private final static int LANCER_DES = 2;
public LancerDes(int typeDe, int[] rolls, Contexte c){
this.typeDe = typeDe;
this.rolls = rolls;
this.contexte = c;
}
public VBox initLancer() {
switch (contexte) {
case LANCER_DES_4:
switch (typeDe) {
case LANCER_DE_4:
return initLancerD4();
case LANCER_DES_6:
case LANCER_DE_6:
return initLancerD6();
case LANCER_DES:
return initLancerBoth();
default :
return null;
}
@ -53,19 +64,26 @@ public class LancerDes {
btn.setOnAction((ActionEvent event) -> {
btn.setDisable(true);// Disable Button
Random random = new Random();
Timeline timeline = new Timeline(new KeyFrame(Duration.seconds(.3), (actionEvent) -> {
int tempRandom = random.nextInt(4) + 1;
Timeline timeline = new Timeline(new KeyFrame(Duration.seconds(0.1), (actionEvent) -> {
int tempRandom = random.nextInt(4)+1;
die.setDieFace(tempRandom);
}));
timeline.setCycleCount(random.nextInt(20) + 1);
timeline.setCycleCount(20);
timeline.play();
timeline.setOnFinished(actionEvent -> {
int res = die.getCurrentFace();
txt.setText("Vous avez obtenu "+res+"!");
resultat = res;
GestionnaireJeu.notifyPlateau();
});
die.setDieFace(rolls[0]);
txt.setText("Vous avez obtenu "+rolls[0]);
Timeline timeline2 = new Timeline(new KeyFrame(
Duration.millis(2000),
ae -> {
GestionnaireJeu.notifyPlateau();
}));
timeline2.play();
});
});
HBox des = new HBox(stackpane);
@ -77,6 +95,50 @@ public class LancerDes {
}
private VBox initLancerD6() {
DieImages images = new DieImages();
Die die = new Die(images.getImages());
ImageView stackpane = die.getdieFace();
stackpane.setFitHeight(100);
stackpane.setFitWidth(100);
Button btn = new Button();
Text txt = new Text("Lancez le dés pour attaquer");
txt.setFont(Font.font(null, null, null, 12));
txt.setFill(Color.WHITE);
btn.setText("Lancer dés");
btn.setOnAction((ActionEvent event) -> {
btn.setDisable(true);// Disable Button
Random random = new Random();
Timeline timeline = new Timeline(new KeyFrame(Duration.seconds(.1), (actionEvent) -> {
int tempRandom = random.nextInt(6)+1;
die.setDieFace(tempRandom);
}));
timeline.setCycleCount(20);
timeline.play();
timeline.setOnFinished(actionEvent -> {
die.setDieFace(rolls[0]);
txt.setText("Vous avez obtenu "+rolls[0]);
Timeline timeline2 = new Timeline(new KeyFrame(
Duration.millis(2000),
ae -> {
GestionnaireJeu.notifyPlateau();
}));
timeline2.play();
});
});
HBox des = new HBox(stackpane);
des.setAlignment(Pos.CENTER);
VBox root = new VBox(txt,des, new StackPane(btn));
root.setAlignment(Pos.CENTER);
root.setSpacing(20);
return root;
}
private VBox initLancerBoth() {
DieImages images = new DieImages();
Die die = new Die(images.getImages());
Die die2 = new Die(images.getImages());
@ -94,21 +156,33 @@ public class LancerDes {
btn.setOnAction((ActionEvent event) -> {
btn.setDisable(true);// Disable Button
Random random = new Random();
Timeline timeline = new Timeline(new KeyFrame(Duration.seconds(.3), (actionEvent) -> {
int tempRandom = random.nextInt(6) + 1;
int tempRandom2 = random.nextInt(6) + 1;
Timeline timeline = new Timeline(new KeyFrame(Duration.seconds(.1), (actionEvent) -> {
int tempRandom = random.nextInt(4)+1;
int tempRandom2 = random.nextInt(6)+1;
die.setDieFace(tempRandom);
die2.setDieFace(tempRandom2);
}));
timeline.setCycleCount(random.nextInt(20) + 1);
timeline.setCycleCount(20);
timeline.play();
timeline.setOnFinished(actionEvent -> {
int res = die.getCurrentFace()+die2.getCurrentFace();
txt.setText("Vous avez obtenu "+res+"!");
resultat = res;
GestionnaireJeu.notifyPlateau();
});
die.setDieFace(rolls[0]);
die2.setDieFace(rolls[1]);
int result = rolls[0]+rolls[1];
txt.setText("Vous avez obtenu "+result);
Timeline timeline2 = new Timeline(new KeyFrame(
Duration.millis(2000),
ae -> {
GestionnaireJeu.notifyPlateau();
}));
timeline2.play();
});
});
HBox des = new HBox(stackpane, stackpane2);