From dc3414c0237d5967428eb58503748eea930cc419 Mon Sep 17 00:00:00 2001 From: Paul Gross Date: Wed, 13 May 2020 10:35:38 +0200 Subject: [PATCH] =?UTF-8?q?Ajout=20des=20capacit=C3=A9s=20sp=C3=A9ciales?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ihm/controller/LancerDes.java | 118 ++++++++++++++++++---- src/ihm/controller/PlateauController.java | 35 ++----- src/ihm/controller/RecevoirCarte.java | 13 ++- src/ihm/ressources/RecevoirCarte.fxml | 10 +- src/main/GestionnaireJeu.java | 48 +++------ src/main/Joueur.java | 20 +--- src/main/Plateau.java | 14 ++- 7 files changed, 146 insertions(+), 112 deletions(-) diff --git a/src/ihm/controller/LancerDes.java b/src/ihm/controller/LancerDes.java index 39601fb..a691e14 100644 --- a/src/ihm/controller/LancerDes.java +++ b/src/ihm/controller/LancerDes.java @@ -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); diff --git a/src/ihm/controller/PlateauController.java b/src/ihm/controller/PlateauController.java index 2c9f94a..61372af 100644 --- a/src/ihm/controller/PlateauController.java +++ b/src/ihm/controller/PlateauController.java @@ -65,9 +65,9 @@ public class PlateauController implements Initializable { private Map mapRessourcesCartes; private Map mapRessourcesDosCartes; - public static int DICE_SIX = 2; - public static int DICE_QUATRE = 1; - public static int DICE_BOTH = 0; + public static int DICE_SIX = 1; + public static int DICE_QUATRE = 0; + public static int DICE_BOTH = 2; /** * initialise les données du plateau @@ -333,9 +333,11 @@ public class PlateauController implements Initializable { } } - public void rollDice(Joueur joueur, int typeDice, int[] rolls) { - + public void rollDice(Joueur joueur, int typeDice, int[] rolls, Contexte c) { + this.ld=new LancerDes(typeDice,rolls,c); + JoueurIHM jihm = getJoueurIHM(joueur); + jihm.setZoneJoueur(ld.initLancer()); } public void afficherChoisir(Joueur j, Contexte contexte) throws IOException { @@ -493,7 +495,7 @@ public class PlateauController implements Initializable { } - public void close () throws IOException { + public void close() throws IOException { final URL fxmlURL = PlateauController.class.getResource("/ihm/ressources/Menu.fxml"); final ResourceBundle bundle = ResourceBundle.getBundle("domaine.properties.langue", Locale.FRANCE); final FXMLLoader fxmlLoader = new FXMLLoader(fxmlURL, bundle); @@ -501,36 +503,17 @@ public class PlateauController implements Initializable { rootPane.getChildren().setAll(pane); } - - public Integer getChoixLancerDes(Joueur joueur) { - JoueurIHM jihm = getJoueurIHM(joueur); - int result = this.ld.getResult(); - this.ld = null; - jihm.getZoneJoueur().getChildren().setAll(); - return result; - } - - - public void afficherLancerDes(Joueur j, Contexte c) throws IOException { - this.ld=new LancerDes(c); - JoueurIHM jihm = getJoueurIHM(j); - jihm.setZoneJoueur(ld.initLancer()); - } - - public void afficherLT(Joueur j, CartePiochable cartePiochable) throws IOException { Image i = getImageCarte(cartePiochable); ImageView iv = new ImageView(i); Pane p = new Pane(iv); PopUp pu = new PopUp(p,"Image"); - pu.getStage().focusedProperty().addListener((obs,wasFocused,isNowFocused) -> { - + pu.getStage().focusedProperty().addListener((obs,wasFocused,isNowFocused) -> { if(!isNowFocused) { GestionnaireJeu.notifyPlateau(); pu.getStage().hide(); } - }); pu.display(); diff --git a/src/ihm/controller/RecevoirCarte.java b/src/ihm/controller/RecevoirCarte.java index 2fe32a6..59f79a9 100644 --- a/src/ihm/controller/RecevoirCarte.java +++ b/src/ihm/controller/RecevoirCarte.java @@ -10,6 +10,12 @@ import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.image.Image; import javafx.scene.image.ImageView; +import javafx.scene.layout.AnchorPane; +import javafx.scene.layout.Background; +import javafx.scene.layout.BackgroundImage; +import javafx.scene.layout.BackgroundPosition; +import javafx.scene.layout.BackgroundRepeat; +import javafx.scene.layout.BackgroundSize; import main.GestionnaireJeu; public class RecevoirCarte implements Initializable { @@ -31,6 +37,11 @@ public class RecevoirCarte implements Initializable { } public void setImageView(Image imageCarte) { - this.imageView.setImage(imageCarte); + AnchorPane ap = (AnchorPane) imageView.getParent(); + + BackgroundImage myBI= new BackgroundImage(imageCarte, + BackgroundRepeat.NO_REPEAT, BackgroundRepeat.NO_REPEAT, BackgroundPosition.DEFAULT, + new BackgroundSize(BackgroundSize.AUTO,1.0,true,true,false,false)); + ap.setBackground(new Background(myBI)); } } diff --git a/src/ihm/ressources/RecevoirCarte.fxml b/src/ihm/ressources/RecevoirCarte.fxml index ef51990..7bfcf8b 100644 --- a/src/ihm/ressources/RecevoirCarte.fxml +++ b/src/ihm/ressources/RecevoirCarte.fxml @@ -8,27 +8,27 @@ - + - + -