Ajout des capacités spéciales
This commit is contained in:
parent
80f7266ffb
commit
dc3414c023
@ -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);
|
||||
|
@ -65,9 +65,9 @@ public class PlateauController implements Initializable {
|
||||
private Map<Carte,BufferedImage> mapRessourcesCartes;
|
||||
private Map<String,BufferedImage> 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,23 +503,6 @@ 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);
|
||||
@ -525,12 +510,10 @@ public class PlateauController implements Initializable {
|
||||
Pane p = new Pane(iv);
|
||||
PopUp pu = new PopUp(p,"Image");
|
||||
pu.getStage().focusedProperty().addListener((obs,wasFocused,isNowFocused) -> {
|
||||
|
||||
if(!isNowFocused) {
|
||||
GestionnaireJeu.notifyPlateau();
|
||||
pu.getStage().hide();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
pu.display();
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -8,27 +8,27 @@
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
<?import javafx.scene.text.Font?>
|
||||
|
||||
<AnchorPane xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ihm.controller.RecevoirCarte">
|
||||
<AnchorPane prefHeight="344.0" prefWidth="385.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ihm.controller.RecevoirCarte">
|
||||
<children>
|
||||
<SplitPane dividerPositions="0.6212121212121212" styleClass="background" stylesheets="@style/plateau.css" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||
<SplitPane dividerPositions="0.9921671018276762" styleClass="background" stylesheets="@style/plateau.css" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||
<items>
|
||||
<AnchorPane>
|
||||
<children>
|
||||
<VBox alignment="CENTER" spacing="30.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||
<children>
|
||||
<Label fx:id="label" styleClass="text" text="Vous arrivez sur cette Carte Lieu" textOverrun="CLIP" wrapText="true">
|
||||
<Label fx:id="label" minHeight="0.0" minWidth="0.0" styleClass="text" text="Glissez la barre" textOverrun="CLIP" wrapText="true">
|
||||
<font>
|
||||
<Font size="14.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<Button fx:id="okButton" mnemonicParsing="false" styleClass="bouton" text="Ok" />
|
||||
<Button fx:id="okButton" minHeight="0.0" minWidth="0.0" mnemonicParsing="false" styleClass="bouton" text="Ok" />
|
||||
</children>
|
||||
</VBox>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
<AnchorPane>
|
||||
<children>
|
||||
<ImageView fx:id="imageView" fitHeight="158.0" fitWidth="132.0" pickOnBounds="true" preserveRatio="true" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
|
||||
<ImageView fx:id="imageView" pickOnBounds="true" preserveRatio="true" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
</items>
|
||||
|
@ -25,6 +25,8 @@ public class GestionnaireJeu {
|
||||
|
||||
private RessourceLoader ressourceLoader;
|
||||
|
||||
private static Thread lastThread;
|
||||
|
||||
private static Plateau plateau;
|
||||
public static PlateauController pc;
|
||||
|
||||
@ -165,34 +167,14 @@ public class GestionnaireJeu {
|
||||
this.waitPlateau();
|
||||
}
|
||||
|
||||
public int jouerDes(Joueur joueur, Contexte c) {
|
||||
|
||||
public void rollDice(Joueur joueur, int typeDice, int ... rolls){
|
||||
|
||||
Platform.runLater(() -> {
|
||||
try {
|
||||
pc.afficherLancerDes(joueur, c);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
pc.rollDice(joueur,typeDice,rolls, null);
|
||||
});
|
||||
|
||||
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) {
|
||||
@ -226,10 +208,10 @@ public class GestionnaireJeu {
|
||||
return null;
|
||||
}
|
||||
public void waitPlateau() {
|
||||
Thread currentThread = Thread.currentThread();
|
||||
synchronized(currentThread) {
|
||||
lastThread = Thread.currentThread();
|
||||
synchronized(lastThread) {
|
||||
try {
|
||||
currentThread.wait();
|
||||
lastThread.wait();
|
||||
} catch (InterruptedException e) {
|
||||
|
||||
}
|
||||
@ -237,9 +219,10 @@ public class GestionnaireJeu {
|
||||
}
|
||||
|
||||
public static void notifyPlateau() {
|
||||
synchronized(plateau) {
|
||||
plateau.notify();
|
||||
synchronized(lastThread) {
|
||||
lastThread.notify();
|
||||
}
|
||||
lastThread = null;
|
||||
}
|
||||
|
||||
public Type choisirCarte(Joueur joueur) {
|
||||
@ -272,10 +255,7 @@ public class GestionnaireJeu {
|
||||
|
||||
return null;
|
||||
}
|
||||
public void rollDice(Joueur joueur, int typeDice, int ... rolls){
|
||||
|
||||
pc.rollDice(joueur,typeDice,rolls);
|
||||
}
|
||||
|
||||
public void setConfiguration(Configuration c) {
|
||||
|
||||
|
@ -68,10 +68,6 @@ public class Joueur {
|
||||
this.stats.put(key, valeur);
|
||||
}
|
||||
public void setStat(String key, int valeur) {
|
||||
System.out.println(this.nom+" "+this);
|
||||
if(key.contentEquals(PLAYER_HP)) {
|
||||
this.plateau.alerationVie(this,valeur);
|
||||
}
|
||||
this.stats.put(key, valeur);
|
||||
updateVictoirePlateau();
|
||||
updateVie();
|
||||
@ -112,7 +108,6 @@ public class Joueur {
|
||||
}
|
||||
|
||||
public int getStat(String key) {
|
||||
|
||||
if(stats.containsKey(key)) {
|
||||
return stats.get(key);
|
||||
}else {
|
||||
@ -164,6 +159,9 @@ public class Joueur {
|
||||
public void addToStat(String key, int valeur)
|
||||
{
|
||||
int valeurBase = this.getStat(key);
|
||||
if(key.contentEquals(PLAYER_HP)) {
|
||||
this.plateau.alerationVie(this,valeur);
|
||||
}
|
||||
this.setStat(key,valeurBase+valeur);
|
||||
}
|
||||
|
||||
@ -189,8 +187,6 @@ public class Joueur {
|
||||
this.plateau = plateau2;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void utiliserEffetLieu() {
|
||||
this.carteLieu.utiliser(this);
|
||||
}
|
||||
@ -246,10 +242,6 @@ 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);
|
||||
}
|
||||
@ -277,8 +269,4 @@ public class Joueur {
|
||||
this.cartePersonnage.utiliser();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -266,9 +266,7 @@ public class Plateau extends Thread{
|
||||
|
||||
System.out.println(joueurs.size());
|
||||
Joueur currentJoueur = this.joueurs.get(i % nbJoueurs);
|
||||
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);
|
||||
@ -356,7 +354,6 @@ public class Plateau extends Thread{
|
||||
|
||||
int roll4 =rollRandom(4);
|
||||
int roll6 = rollRandom(6);
|
||||
|
||||
gj.rollDice(j, PlateauController.DICE_BOTH, roll4,roll6);
|
||||
return Math.abs(roll4-roll6);
|
||||
}
|
||||
@ -383,7 +380,12 @@ public class Plateau extends Thread{
|
||||
|
||||
public int sumRolls(Joueur j)
|
||||
{
|
||||
return roll6(j) + roll4(j);
|
||||
int roll4 =rollRandom(4);
|
||||
int roll6 = rollRandom(6);
|
||||
int sum = Math.abs(roll4+roll6);
|
||||
gj.rollDice(j, PlateauController.DICE_BOTH, roll4,roll6);
|
||||
return 3;
|
||||
//return Math.abs(roll4+roll6);
|
||||
}
|
||||
|
||||
public List<Joueur> getJoueurs() {
|
||||
@ -477,8 +479,4 @@ 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