lancer des
This commit is contained in:
parent
985a085e74
commit
8963221080
40
src/ihm/Die.java
Normal file
40
src/ihm/Die.java
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
package ihm;
|
||||||
|
|
||||||
|
//adaptation du code a la source : https://stackoverflow.com/questions/50021161/java-how-to-update-dice-image-when-button-clicked-and-equal-to-number-given
|
||||||
|
import javafx.scene.image.Image;
|
||||||
|
import javafx.scene.image.ImageView;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author blj0011
|
||||||
|
*/
|
||||||
|
public class Die {
|
||||||
|
ImageView dieFace;
|
||||||
|
Image[] images;
|
||||||
|
int currentFace;
|
||||||
|
|
||||||
|
public Die(Image[] images) {
|
||||||
|
this.images = images;
|
||||||
|
dieFace = new ImageView(this.images[0]);// set default to image 0
|
||||||
|
}
|
||||||
|
|
||||||
|
public Die(Image[] images, int dieFaceValue) {
|
||||||
|
// Need to catch for values less than 1 and greater than 6!
|
||||||
|
this.images = images;
|
||||||
|
dieFace = new ImageView(this.images[dieFaceValue - 1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImageView getdieFace() {
|
||||||
|
return dieFace;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCurrentFace() {
|
||||||
|
return currentFace;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDieFace(int dieFaceValue) {
|
||||||
|
// Need to catch for values less than 1 and greater than 6!
|
||||||
|
dieFace.setImage(this.images[dieFaceValue - 1]);
|
||||||
|
currentFace = dieFaceValue;
|
||||||
|
}
|
||||||
|
}
|
36
src/ihm/DieImages.java
Normal file
36
src/ihm/DieImages.java
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
package ihm;
|
||||||
|
|
||||||
|
//adaptation du code a la source : https://stackoverflow.com/questions/50021161/java-how-to-update-dice-image-when-button-clicked-and-equal-to-number-given
|
||||||
|
|
||||||
|
import javafx.scene.image.Image;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author blj0011
|
||||||
|
*/
|
||||||
|
public class DieImages {
|
||||||
|
final Image die1 = new Image(getClass().getResourceAsStream("ressources/img/des1.png"));
|
||||||
|
final Image die2 = new Image(getClass().getResourceAsStream("ressources/img/des2.png"));
|
||||||
|
final Image die3 = new Image(getClass().getResourceAsStream("ressources/img/des3.png"));
|
||||||
|
final Image die4 = new Image(getClass().getResourceAsStream("ressources/img/des4.png"));
|
||||||
|
final Image die5 = new Image(getClass().getResourceAsStream("ressources/img/des5.png"));
|
||||||
|
final Image die6 = new Image(getClass().getResourceAsStream("ressources/img/des6.png"));
|
||||||
|
|
||||||
|
final Image[] images = new Image[6];
|
||||||
|
|
||||||
|
public DieImages() {
|
||||||
|
images[0] = die1;
|
||||||
|
images[1] = die2;
|
||||||
|
images[2] = die3;
|
||||||
|
images[3] = die4;
|
||||||
|
images[4] = die5;
|
||||||
|
images[5] = die6;
|
||||||
|
for (int i = 0; i < images.length; i++) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Image[] getImages() {
|
||||||
|
return images;
|
||||||
|
}
|
||||||
|
}
|
@ -1,20 +0,0 @@
|
|||||||
package ihm.controller;
|
|
||||||
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.ResourceBundle;
|
|
||||||
|
|
||||||
import javafx.fxml.FXML;
|
|
||||||
import javafx.scene.control.Label;
|
|
||||||
import main.Joueur;
|
|
||||||
|
|
||||||
public class JouerSonTour4Controller extends LancerDes{
|
|
||||||
@FXML private Label defenseur;
|
|
||||||
|
|
||||||
private Joueur j;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void initialize(URL arg0, ResourceBundle arg1) {
|
|
||||||
super.initialize(arg0, arg1);
|
|
||||||
//defenseur.setText(j.getNom());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,57 +1,125 @@
|
|||||||
package ihm.controller;
|
package ihm.controller;
|
||||||
|
|
||||||
import java.net.URL;
|
import java.util.Random;
|
||||||
import java.util.ResourceBundle;
|
|
||||||
|
|
||||||
import javafx.fxml.FXML;
|
import ihm.Die;
|
||||||
import javafx.fxml.Initializable;
|
import ihm.DieImages;
|
||||||
|
import javafx.animation.KeyFrame;
|
||||||
|
import javafx.animation.Timeline;
|
||||||
|
import javafx.event.ActionEvent;
|
||||||
|
import javafx.geometry.Pos;
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.image.ImageView;
|
||||||
|
import javafx.scene.layout.HBox;
|
||||||
|
import javafx.scene.layout.StackPane;
|
||||||
|
import javafx.scene.layout.VBox;
|
||||||
|
import javafx.scene.paint.Color;
|
||||||
|
import javafx.scene.text.Font;
|
||||||
|
import javafx.scene.text.Text;
|
||||||
|
import javafx.util.Duration;
|
||||||
|
import main.Contexte;
|
||||||
|
import main.GestionnaireJeu;
|
||||||
|
|
||||||
public class LancerDes implements Initializable{
|
public class LancerDes {
|
||||||
@FXML private Label d6;
|
private int resultat;
|
||||||
@FXML private Label d4;
|
private Contexte contexte;
|
||||||
@FXML private Button btnStop;
|
public LancerDes(Contexte c){
|
||||||
@FXML private Button btnLancer;
|
contexte = c;
|
||||||
|
}
|
||||||
|
|
||||||
private int[] valeurD6 = {1, 2, 3, 4, 5, 6};
|
public VBox initLancer() {
|
||||||
private int[] valeurD4 = {1, 2, 3, 4};
|
switch (contexte) {
|
||||||
|
case LANCER_DES_4:
|
||||||
|
return initLancerD4();
|
||||||
|
case LANCER_DES_6:
|
||||||
|
return initLancerD6();
|
||||||
|
default :
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private int resultatD6;
|
|
||||||
private int resultatD4;
|
|
||||||
|
|
||||||
private boolean lancement = true;
|
|
||||||
|
|
||||||
@Override
|
private VBox initLancerD4() {
|
||||||
public void initialize(URL arg0, ResourceBundle arg1) {
|
DieImages images = new DieImages();
|
||||||
// TODO Auto-generated method stub
|
Die die = new Die(images.getImages());
|
||||||
btnStop.setVisible(false);
|
ImageView stackpane = die.getdieFace();
|
||||||
|
stackpane.setFitHeight(100);
|
||||||
btnLancer.setOnAction(e -> {
|
stackpane.setFitWidth(100);
|
||||||
try {
|
Button btn = new Button();
|
||||||
btnLancer.setVisible(false);
|
Text txt = new Text("Lancez le dés pour attaquer");
|
||||||
btnStop.setVisible(true);
|
txt.setFont(Font.font(null, null, null, 12));
|
||||||
lancement();
|
txt.setFill(Color.WHITE);
|
||||||
} catch (InterruptedException e1) {
|
btn.setText("Lancer dés");
|
||||||
e1.printStackTrace();
|
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;
|
||||||
|
die.setDieFace(tempRandom);
|
||||||
|
}));
|
||||||
|
|
||||||
|
timeline.setCycleCount(random.nextInt(20) + 1);
|
||||||
|
timeline.play();
|
||||||
|
timeline.setOnFinished(actionEvent -> {
|
||||||
|
int res = die.getCurrentFace();
|
||||||
|
txt.setText("Vous avez obtenu "+res+"!");
|
||||||
|
resultat = res;
|
||||||
|
GestionnaireJeu.notifyPlateau();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
btnStop.setOnAction(e -> {
|
HBox des = new HBox(stackpane);
|
||||||
//à remplir avec les valeurs donné par le gestionnaire de jeux
|
des.setAlignment(Pos.CENTER);
|
||||||
lancement = false;
|
VBox root = new VBox(txt,des, new StackPane(btn));
|
||||||
d6.setText(Integer.toString(resultatD6));
|
root.setAlignment(Pos.CENTER);
|
||||||
d4.setText(Integer.toString(resultatD4));
|
root.setSpacing(20);
|
||||||
});
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void lancement() throws InterruptedException {
|
private VBox initLancerD6() {
|
||||||
/*int i=0;
|
DieImages images = new DieImages();
|
||||||
while (lancement) {
|
Die die = new Die(images.getImages());
|
||||||
d6.setText(Integer.toString(valeurD6[i%6]));
|
Die die2 = new Die(images.getImages());
|
||||||
d4.setText(Integer.toString(valeurD4[i%4]));
|
ImageView stackpane = die.getdieFace();
|
||||||
i++;
|
ImageView stackpane2 = die2.getdieFace();
|
||||||
//Thread.sleep(500);
|
stackpane.setFitHeight(100);
|
||||||
}*/
|
stackpane2.setFitHeight(100);
|
||||||
|
stackpane.setFitWidth(100);
|
||||||
|
stackpane2.setFitWidth(100);
|
||||||
|
Button btn = new Button();
|
||||||
|
Text txt = new Text("Lancez les dés pour vous deplacer");
|
||||||
|
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(.3), (actionEvent) -> {
|
||||||
|
int tempRandom = random.nextInt(6) + 1;
|
||||||
|
int tempRandom2 = random.nextInt(6) + 1;
|
||||||
|
die.setDieFace(tempRandom);
|
||||||
|
die2.setDieFace(tempRandom2);
|
||||||
|
}));
|
||||||
|
|
||||||
|
timeline.setCycleCount(random.nextInt(20) + 1);
|
||||||
|
timeline.play();
|
||||||
|
timeline.setOnFinished(actionEvent -> {
|
||||||
|
int res = die.getCurrentFace()+die2.getCurrentFace();
|
||||||
|
txt.setText("Vous avez obtenu "+res+"!");
|
||||||
|
resultat = res;
|
||||||
|
GestionnaireJeu.notifyPlateau();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
HBox des = new HBox(stackpane, stackpane2);
|
||||||
|
des.setAlignment(Pos.CENTER);
|
||||||
|
VBox root = new VBox(txt,des, new StackPane(btn));
|
||||||
|
root.setAlignment(Pos.CENTER);
|
||||||
|
root.setSpacing(20);
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getResult() {
|
||||||
|
return resultat;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,6 +53,7 @@ public class PlateauController implements Initializable {
|
|||||||
private ChoisirBoolean cb;
|
private ChoisirBoolean cb;
|
||||||
private ChoisirEquipement ce;
|
private ChoisirEquipement ce;
|
||||||
private ChoisirJoueur cj;
|
private ChoisirJoueur cj;
|
||||||
|
private LancerDes ld;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -472,11 +473,20 @@ public class PlateauController implements Initializable {
|
|||||||
Pane pane = fxmlLoader.load();
|
Pane pane = fxmlLoader.load();
|
||||||
rootPane.getChildren().setAll(pane);
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
BIN
src/ihm/ressources/img/des1.png
Normal file
BIN
src/ihm/ressources/img/des1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.5 KiB |
BIN
src/ihm/ressources/img/des2.png
Normal file
BIN
src/ihm/ressources/img/des2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.0 KiB |
BIN
src/ihm/ressources/img/des3.png
Normal file
BIN
src/ihm/ressources/img/des3.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.8 KiB |
BIN
src/ihm/ressources/img/des4.png
Normal file
BIN
src/ihm/ressources/img/des4.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.7 KiB |
BIN
src/ihm/ressources/img/des5.png
Normal file
BIN
src/ihm/ressources/img/des5.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.2 KiB |
BIN
src/ihm/ressources/img/des6.png
Normal file
BIN
src/ihm/ressources/img/des6.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.0 KiB |
@ -5,6 +5,10 @@ public enum Contexte {
|
|||||||
ATTAQUER,
|
ATTAQUER,
|
||||||
VOLER_EQUIP,
|
VOLER_EQUIP,
|
||||||
EFFET_NEGATIF_SUR_AUTRES,
|
EFFET_NEGATIF_SUR_AUTRES,
|
||||||
EFFET_POSITIF_SUR_AUTRES, ACTIVER_EFFET_LIEU, EFFET_BOB
|
EFFET_POSITIF_SUR_AUTRES,
|
||||||
|
ACTIVER_EFFET_LIEU,
|
||||||
|
EFFET_BOB,
|
||||||
|
LANCER_DES_4,
|
||||||
|
LANCER_DES_6
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -166,7 +166,37 @@ public class GestionnaireJeu {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.waitPlateau();
|
this.waitPlateau();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int jouerDes(Joueur joueur, Contexte c) {
|
||||||
|
Platform.runLater(() -> {
|
||||||
|
try {
|
||||||
|
pc.afficherLancerDes(joueur, c);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.waitPlateau();
|
||||||
|
|
||||||
|
final FutureTask<Integer> query = new FutureTask<Integer>(new Callable<Integer>() {
|
||||||
|
@Override
|
||||||
|
public Integer call() throws Exception {
|
||||||
|
return pc.getChoixLancerDes(joueur);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Platform.runLater(query);
|
||||||
|
|
||||||
|
try {
|
||||||
|
return query.get();
|
||||||
|
} catch (InterruptedException | ExecutionException e) {
|
||||||
|
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
public Joueur choisirJoueur(Joueur joueur, List<Joueur> joueurs, Contexte contexte) {
|
public Joueur choisirJoueur(Joueur joueur, List<Joueur> joueurs, Contexte contexte) {
|
||||||
|
|
||||||
|
@ -246,6 +246,10 @@ public class Joueur {
|
|||||||
return this.plateau.choisir(this, activerEffetLieu);
|
return this.plateau.choisir(this, activerEffetLieu);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int lancerDes(Contexte typeLancer) {
|
||||||
|
return this.plateau.lancerDes(this, typeLancer);
|
||||||
|
}
|
||||||
|
|
||||||
public Object choisir(List<?> list,Class cls) {
|
public Object choisir(List<?> list,Class cls) {
|
||||||
return this.plateau.choisir(this,list, cls);
|
return this.plateau.choisir(this,list, cls);
|
||||||
}
|
}
|
||||||
|
@ -266,8 +266,9 @@ public class Plateau extends Thread{
|
|||||||
|
|
||||||
System.out.println(joueurs.size());
|
System.out.println(joueurs.size());
|
||||||
Joueur currentJoueur = this.joueurs.get(i % nbJoueurs);
|
Joueur currentJoueur = this.joueurs.get(i % nbJoueurs);
|
||||||
currentJoueur.choisir(joueurs, Joueur.class);
|
int lancer = currentJoueur.lancerDes(Contexte.LANCER_DES_4);
|
||||||
System.out.println("\n\n\n\n\n");
|
System.out.println("\n\n\n\n\n");
|
||||||
|
System.out.println(lancer);
|
||||||
System.out.println("Au tour de "+currentJoueur.getNom());
|
System.out.println("Au tour de "+currentJoueur.getNom());
|
||||||
System.out.println("Lancement des dés.");
|
System.out.println("Lancement des dés.");
|
||||||
deplacer(currentJoueur);
|
deplacer(currentJoueur);
|
||||||
@ -477,4 +478,8 @@ public class Plateau extends Thread{
|
|||||||
gj.retirerEquipement(joueur,e);
|
gj.retirerEquipement(joueur,e);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int lancerDes(Joueur joueur, Contexte typeLancer) {
|
||||||
|
return gj.jouerDes(joueur, typeLancer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user