Merge branch 'development' of https://github.com/PTE-SH/ShadowHunterGame into development
This commit is contained in:
commit
83c080f719
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;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.Random;
|
||||
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
import ihm.Die;
|
||||
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.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{
|
||||
@FXML private Label d6;
|
||||
@FXML private Label d4;
|
||||
@FXML private Button btnStop;
|
||||
@FXML private Button btnLancer;
|
||||
public class LancerDes {
|
||||
private int resultat;
|
||||
private Contexte contexte;
|
||||
public LancerDes(Contexte c){
|
||||
contexte = c;
|
||||
}
|
||||
|
||||
private int[] valeurD6 = {1, 2, 3, 4, 5, 6};
|
||||
private int[] valeurD4 = {1, 2, 3, 4};
|
||||
public VBox initLancer() {
|
||||
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
|
||||
public void initialize(URL arg0, ResourceBundle arg1) {
|
||||
// TODO Auto-generated method stub
|
||||
btnStop.setVisible(false);
|
||||
|
||||
btnLancer.setOnAction(e -> {
|
||||
try {
|
||||
btnLancer.setVisible(false);
|
||||
btnStop.setVisible(true);
|
||||
lancement();
|
||||
} catch (InterruptedException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
private VBox initLancerD4() {
|
||||
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(.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 -> {
|
||||
//à remplir avec les valeurs donné par le gestionnaire de jeux
|
||||
lancement = false;
|
||||
d6.setText(Integer.toString(resultatD6));
|
||||
d4.setText(Integer.toString(resultatD4));
|
||||
});
|
||||
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;
|
||||
}
|
||||
|
||||
public void lancement() throws InterruptedException {
|
||||
/*int i=0;
|
||||
while (lancement) {
|
||||
d6.setText(Integer.toString(valeurD6[i%6]));
|
||||
d4.setText(Integer.toString(valeurD4[i%4]));
|
||||
i++;
|
||||
//Thread.sleep(500);
|
||||
}*/
|
||||
private VBox initLancerD6() {
|
||||
DieImages images = new DieImages();
|
||||
Die die = new Die(images.getImages());
|
||||
Die die2 = new Die(images.getImages());
|
||||
ImageView stackpane = die.getdieFace();
|
||||
ImageView stackpane2 = die2.getdieFace();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -57,6 +57,7 @@ public class PlateauController implements Initializable {
|
||||
private ChoisirBoolean cb;
|
||||
private ChoisirEquipement ce;
|
||||
private ChoisirJoueur cj;
|
||||
private LancerDes ld;
|
||||
|
||||
|
||||
|
||||
@ -208,8 +209,6 @@ public class PlateauController implements Initializable {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void applyImageLieu(ImageView iv, Image im) {
|
||||
|
||||
StackPane sp = (StackPane) iv.getParent();
|
||||
@ -479,6 +478,22 @@ public class PlateauController implements Initializable {
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
|
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,
|
||||
VOLER_EQUIP,
|
||||
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
|
||||
|
||||
}
|
||||
|
@ -163,7 +163,37 @@ public class GestionnaireJeu {
|
||||
});
|
||||
|
||||
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) {
|
||||
|
||||
|
@ -246,6 +246,10 @@ public class Joueur {
|
||||
return this.plateau.choisir(this, activerEffetLieu);
|
||||
}
|
||||
|
||||
public int lancerDes(Contexte typeLancer) {
|
||||
return this.plateau.lancerDes(this, typeLancer);
|
||||
}
|
||||
|
||||
public Object choisir(List<?> list,Class cls) {
|
||||
return this.plateau.choisir(this,list, cls);
|
||||
}
|
||||
|
@ -266,8 +266,9 @@ public class Plateau extends Thread{
|
||||
|
||||
System.out.println(joueurs.size());
|
||||
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(lancer);
|
||||
System.out.println("Au tour de "+currentJoueur.getNom());
|
||||
System.out.println("Lancement des dés.");
|
||||
deplacer(currentJoueur);
|
||||
@ -476,4 +477,8 @@ public class Plateau extends Thread{
|
||||
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