From 94e6c00001cc3f708560aa6a6761bf696b26db8a Mon Sep 17 00:00:00 2001 From: Paul Gross Date: Mon, 27 Apr 2020 11:40:14 +0200 Subject: [PATCH 1/7] =?UTF-8?q?Lancer=20de=20d=C3=A9s,=20nouvelle=20dispos?= =?UTF-8?q?ition=20IHM=20etc...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ihm/Dice.java | 60 ++ src/ihm/Main.java | 11 +- src/ihm/PopUpBoolean.java | 6 - src/ihm/SpriteAnimation.java | 47 ++ src/ihm/controller/ChoisirBoolean.java | 4 +- src/ihm/controller/PlateauController.java | 25 +- src/ihm/controller/PlateauControllerTest.java | 161 ++++++ src/ihm/ressources/Dialog.fxml | 11 + src/ihm/ressources/Dés.fxml | 11 + src/ihm/ressources/PlateauTestPaul.fxml | 523 ++++++++++++++++++ src/ihm/ressources/choisirBoolean.fxml | 15 +- src/ihm/ressources/img/de.gif | Bin 0 -> 60493 bytes src/ihm/ressources/img/dice.sprite.png | Bin 0 -> 54130 bytes src/ihm/ressources/img/diceSprite.png | Bin 0 -> 92630 bytes src/ihm/ressources/img/dosCartesLumière.jpg | Bin 0 -> 91767 bytes src/ihm/ressources/img/dosCartesNoires.jpg | Bin 0 -> 111662 bytes .../ressources/img/dosCartesPersonnage.jpg | Bin 0 -> 111788 bytes .../ressources/img/dosCartesPersonnageRot.jpg | Bin 0 -> 130839 bytes src/ihm/ressources/img/dosCartesVision.jpg | Bin 0 -> 127105 bytes src/ihm/ressources/img/dé.png | Bin 0 -> 149278 bytes src/ihm/ressources/img/dé1.jpg | Bin 0 -> 25440 bytes src/ihm/ressources/img/dé2.jpg | Bin 0 -> 26306 bytes src/ihm/ressources/img/dé3.jpg | Bin 0 -> 27290 bytes src/ihm/ressources/img/dé4.jpg | Bin 0 -> 28657 bytes src/ihm/ressources/img/dé5.jpg | Bin 0 -> 28892 bytes src/ihm/ressources/img/dé6.jpg | Bin 0 -> 30549 bytes src/ihm/ressources/img/dés.fxml | 11 + src/ihm/ressources/img/dés.jpg | Bin 0 -> 27833 bytes src/main/GestionnaireJeu.java | 6 + src/main/Plateau.java | 43 +- src/personnage/Franklin.java | 2 +- src/personnage/Georges.java | 2 +- 32 files changed, 898 insertions(+), 40 deletions(-) create mode 100644 src/ihm/Dice.java create mode 100644 src/ihm/SpriteAnimation.java create mode 100644 src/ihm/controller/PlateauControllerTest.java create mode 100644 src/ihm/ressources/Dialog.fxml create mode 100644 src/ihm/ressources/Dés.fxml create mode 100644 src/ihm/ressources/PlateauTestPaul.fxml create mode 100644 src/ihm/ressources/img/de.gif create mode 100644 src/ihm/ressources/img/dice.sprite.png create mode 100644 src/ihm/ressources/img/diceSprite.png create mode 100644 src/ihm/ressources/img/dosCartesLumière.jpg create mode 100644 src/ihm/ressources/img/dosCartesNoires.jpg create mode 100644 src/ihm/ressources/img/dosCartesPersonnage.jpg create mode 100644 src/ihm/ressources/img/dosCartesPersonnageRot.jpg create mode 100644 src/ihm/ressources/img/dosCartesVision.jpg create mode 100644 src/ihm/ressources/img/dé.png create mode 100644 src/ihm/ressources/img/dé1.jpg create mode 100644 src/ihm/ressources/img/dé2.jpg create mode 100644 src/ihm/ressources/img/dé3.jpg create mode 100644 src/ihm/ressources/img/dé4.jpg create mode 100644 src/ihm/ressources/img/dé5.jpg create mode 100644 src/ihm/ressources/img/dé6.jpg create mode 100644 src/ihm/ressources/img/dés.fxml create mode 100644 src/ihm/ressources/img/dés.jpg diff --git a/src/ihm/Dice.java b/src/ihm/Dice.java new file mode 100644 index 0000000..586c07a --- /dev/null +++ b/src/ihm/Dice.java @@ -0,0 +1,60 @@ +package ihm; + +/** + * @author https://www.programcreek.com/java-api-examples/?code=AlmasB%2FFXTutorials%2FFXTutorials-master%2Fsrc%2Fcom%2Falmasb%2Ftutorial5%2FDice.java + * + */ + +import javafx.animation.RotateTransition; +import javafx.beans.property.SimpleIntegerProperty; +import javafx.geometry.Pos; +import javafx.scene.layout.StackPane; +import javafx.scene.paint.Color; +import javafx.scene.shape.Rectangle; +import javafx.scene.text.Text; +import javafx.util.Duration; + +public class Dice extends StackPane { + + public static int MAX_VALUE = 6; + public static final int MIN_VALUE = 1; + + public final SimpleIntegerProperty valueProperty = new SimpleIntegerProperty(); + + int i = 0; + + public Dice(int valeurMax) { + + MAX_VALUE = valeurMax; + Rectangle rect = new Rectangle(50, 50); + + Text text = new Text(); + text.setFill(Color.WHITE); + text.textProperty().bind(valueProperty.asString()); + + this.setAlignment(Pos.CENTER); + getChildren().addAll(rect, text); + + this.setOnMouseClicked(event -> roll()); + } + + public void roll() { + RotateTransition rt = new RotateTransition(Duration.seconds(0.5), this); + rt.setFromAngle(0); + rt.setToAngle(360); + int cycles = 2000; + + rt.setOnFinished(event -> { + + valueProperty.set((int)(Math.random() * (MAX_VALUE - MIN_VALUE + 1)) + MIN_VALUE); + + if(cycles < i) { + + rt.play(); + i++; + } + + }); + rt.play(); + } +} \ No newline at end of file diff --git a/src/ihm/Main.java b/src/ihm/Main.java index 2b11853..103d74b 100644 --- a/src/ihm/Main.java +++ b/src/ihm/Main.java @@ -3,7 +3,6 @@ package ihm; import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Scene; -import javafx.scene.layout.AnchorPane; import javafx.scene.layout.Pane; import javafx.stage.Stage; @@ -12,11 +11,15 @@ public class Main extends Application { public void start(Stage primaryStage) throws Exception { System.out.println("Lancement de l'application"); - Pane root = FXMLLoader.load(getClass().getResource("ressources/Menu.fxml")); // "ressources/Jouer_tour(1)lancer_des.fxml" - + Pane root = FXMLLoader.load(getClass().getResource("ressources/PlateauTestPaul.fxml")); // "ressources/Jouer_tour(1)lancer_des.fxml" + + primaryStage.show(); + + primaryStage.setTitle("Shadow Hunters"); primaryStage.setScene(new Scene(root)); primaryStage.centerOnScreen(); + primaryStage.setMaximized(true); primaryStage.show(); } @@ -24,7 +27,7 @@ public class Main extends Application { String filepath = "src//ihm//ressources//musique//The_Red_Fox_Tavern.wav"; // lien vers la musique : // https://www.youtube.com/watch?v=LBpKUIyOHdo - Musique musiqueObjet = new Musique(); + //Musique musiqueObjet = new Musique(); //musiqueObjet.playMusique(filepath); launch(args); diff --git a/src/ihm/PopUpBoolean.java b/src/ihm/PopUpBoolean.java index 9d98bc3..6bc8ed7 100644 --- a/src/ihm/PopUpBoolean.java +++ b/src/ihm/PopUpBoolean.java @@ -21,10 +21,6 @@ public class PopUpBoolean { private double xOffSet = 0; private double yOffSet = 0; - - - - public PopUpBoolean (Parent p, String titre) { @@ -62,8 +58,6 @@ public class PopUpBoolean { }); } - - public boolean display() { popup.setScene(scene); diff --git a/src/ihm/SpriteAnimation.java b/src/ihm/SpriteAnimation.java new file mode 100644 index 0000000..7fc9579 --- /dev/null +++ b/src/ihm/SpriteAnimation.java @@ -0,0 +1,47 @@ +package ihm; + +import javafx.animation.Interpolator; +import javafx.animation.Transition; +import javafx.geometry.Rectangle2D; +import javafx.scene.image.ImageView; +import javafx.util.Duration; + +public class SpriteAnimation extends Transition { + + private final ImageView imageView; + private final int count; + private final int columns; + private final int offsetX; + private final int offsetY; + private final int width; + private final int height; + + private int lastIndex; + + public SpriteAnimation( + ImageView imageView, + Duration duration, + int count, int columns, + int offsetX, int offsetY, + int width, int height) { + this.imageView = imageView; + this.count = count; + this.columns = columns; + this.offsetX = offsetX; + this.offsetY = offsetY; + this.width = width; + this.height = height; + setCycleDuration(duration); + setInterpolator(Interpolator.LINEAR); + } + + protected void interpolate(double k) { + final int index = Math.min((int) Math.floor(k * count), count - 1); + if (index != lastIndex) { + final int x = (index % columns) * width + offsetX; + final int y = (index / columns) * height + offsetY; + imageView.setViewport(new Rectangle2D(x, y, width, height)); + lastIndex = index; + } + } +} \ No newline at end of file diff --git a/src/ihm/controller/ChoisirBoolean.java b/src/ihm/controller/ChoisirBoolean.java index 57c3f45..483c5c2 100644 --- a/src/ihm/controller/ChoisirBoolean.java +++ b/src/ihm/controller/ChoisirBoolean.java @@ -23,14 +23,13 @@ public class ChoisirBoolean implements Initializable{ public void initialize(URL arg0, ResourceBundle arg1) { } + @FXML public void choixOui(MouseEvent mouseEvent) throws IOException{ PopUpBoolean.result = true; final Node source = (Node) mouseEvent.getSource(); final Stage stage = (Stage) source.getScene().getWindow(); stage.close(); - return; - } @FXML @@ -40,6 +39,5 @@ public class ChoisirBoolean implements Initializable{ final Node source = (Node) mouseEvent.getSource(); final Stage stage = (Stage) source.getScene().getWindow(); stage.close(); - return; } } diff --git a/src/ihm/controller/PlateauController.java b/src/ihm/controller/PlateauController.java index db8d508..1a80819 100644 --- a/src/ihm/controller/PlateauController.java +++ b/src/ihm/controller/PlateauController.java @@ -10,15 +10,23 @@ import java.util.ResourceBundle; import ihm.PopUp; import ihm.PopUpBoolean; +import ihm.SpriteAnimation; +import javafx.animation.Animation; +import javafx.event.Event; +import javafx.event.EventHandler; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; import javafx.fxml.Initializable; +import javafx.geometry.Rectangle2D; +import javafx.scene.Group; import javafx.scene.Parent; import javafx.scene.control.Button; import javafx.scene.control.Label; +import javafx.scene.image.ImageView; +import javafx.scene.layout.AnchorPane; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; -import main.GestionnaireJeu; +import javafx.util.Duration; import main.Joueur; import main.View; @@ -40,6 +48,10 @@ public class PlateauController implements Initializable { @FXML private VBox joueur7; @FXML private VBox joueur8; + public static int DICE_SIX = 2; + public static int DICE_QUATRE = 1; + public static int DICE_BOTH = 0; + /** * initialise les donn�es du plateau */ @@ -113,9 +125,7 @@ public class PlateauController implements Initializable { Parent root = loader.load(); PopUpBoolean popup = new PopUpBoolean(root, "Consulter sa carte"); - return popup.display(); - - + return popup.display(); } /** @@ -146,4 +156,11 @@ public class PlateauController implements Initializable { } } } + + public void rollDice(Joueur joueur, int typeDice, int[] rolls) { + + + + } + } diff --git a/src/ihm/controller/PlateauControllerTest.java b/src/ihm/controller/PlateauControllerTest.java new file mode 100644 index 0000000..16146d9 --- /dev/null +++ b/src/ihm/controller/PlateauControllerTest.java @@ -0,0 +1,161 @@ +package ihm.controller; + + +import java.io.IOException; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.ResourceBundle; + +import ihm.PopUp; +import ihm.PopUpBoolean; +import ihm.SpriteAnimation; +import javafx.animation.Animation; +import javafx.event.Event; +import javafx.event.EventHandler; +import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +import javafx.fxml.Initializable; +import javafx.geometry.Rectangle2D; +import javafx.scene.Group; +import javafx.scene.Parent; +import javafx.scene.control.Button; +import javafx.scene.control.Label; +import javafx.scene.image.ImageView; +import javafx.scene.layout.AnchorPane; +import javafx.scene.layout.VBox; +import javafx.util.Duration; +import main.Joueur; + +public class PlateauControllerTest implements Initializable { + private List listJoueur = new ArrayList(); + private List vboxJoueur = new ArrayList(); + private List