choix de la difficulté de l'ia

This commit is contained in:
Bastien NOEL 2020-05-13 19:56:23 +02:00
parent fc717845c4
commit 6bdd64a1cf
3 changed files with 218 additions and 41 deletions

View File

@ -3,10 +3,17 @@ package ihm;
public class Couple { public class Couple {
private String nom; private String nom;
private boolean ia; // true -> joueur virtuel private boolean ia; // true -> joueur virtuel
private int lvlIa;
public Couple (String nom, boolean ia) { public Couple (String nom) {
this.nom = nom; this.nom = nom;
this.ia = ia; this.ia = false;
}
public Couple (String nom, int niveau) {
this.nom = nom;
this.lvlIa = niveau;
this.ia = true;
} }
public String getNom() { public String getNom() {
@ -17,6 +24,7 @@ public class Couple {
this.nom = nom; this.nom = nom;
} }
public boolean isIa() { public boolean isIa() {
return ia; return ia;
} }
@ -25,4 +33,14 @@ public class Couple {
this.ia = ia; this.ia = ia;
} }
public int getLvlIa() {
return lvlIa;
}
public void setLvlIa(int lvlIa) {
this.lvlIa = lvlIa;
}
} }

View File

@ -19,7 +19,9 @@ import javafx.scene.Node;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import javafx.scene.control.CheckBox; import javafx.scene.control.CheckBox;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextField; import javafx.scene.control.TextField;
import javafx.scene.control.ToggleGroup;
import javafx.scene.input.MouseEvent; import javafx.scene.input.MouseEvent;
import javafx.scene.layout.AnchorPane; import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox; import javafx.scene.layout.HBox;
@ -43,18 +45,48 @@ public class PlayersController implements Initializable{
@FXML private HBox hb7; @FXML private HBox hb7;
@FXML private HBox hb8; @FXML private HBox hb8;
//pour les radios boutons
@FXML private HBox hbr1;
@FXML private HBox hbr2;
@FXML private HBox hbr3;
@FXML private HBox hbr4;
@FXML private HBox hbr5;
@FXML private HBox hbr6;
@FXML private HBox hbr7;
@FXML private HBox hbr8;
@FXML private ToggleGroup tg1;
@FXML private ToggleGroup tg2;
@FXML private ToggleGroup tg3;
@FXML private ToggleGroup tg4;
@FXML private ToggleGroup tg5;
@FXML private ToggleGroup tg6;
@FXML private ToggleGroup tg7;
@FXML private ToggleGroup tg8;
private List<HBox> ligne = new ArrayList<HBox>(); private List<HBox> ligne = new ArrayList<HBox>();
private List<Button> plus = new ArrayList<Button>(); private List<Button> plus = new ArrayList<Button>();
private List<TextField> txt = new ArrayList<TextField>(); private List<TextField> txt = new ArrayList<TextField>();
private List<CheckBox> ia = new ArrayList<CheckBox>(); private List<CheckBox> ia = new ArrayList<CheckBox>();
private List<HBox> listeHbIA = new ArrayList<HBox>();
private List<RadioButton> listeIaLv1 = new ArrayList<RadioButton>();
private List<RadioButton> listeIaLv2 = new ArrayList<RadioButton>();
private List<RadioButton> listeIaLv3 = new ArrayList<RadioButton>();
private List<ToggleGroup> listeToggleRbIa = new ArrayList<ToggleGroup>();
private HashMap<Integer, Couple> joueurs = new HashMap<Integer, Couple>(); private HashMap<Integer, Couple> joueurs = new HashMap<Integer, Couple>();
private int nbJoueursH = 0; private int nbJoueursH = 0;
private int nbJoueursV = 0; private int nbJoueursV = 0;
/** /**
* recup<EFBFBD>re chaque bouton textField et Checkebox a partir des hbox * recupère chaque bouton textField et Checkebox à partir des hbox
*/ */
@Override @Override
public void initialize(URL arg0, ResourceBundle arg1) { public void initialize(URL arg0, ResourceBundle arg1) {
@ -66,12 +98,44 @@ public class PlayersController implements Initializable{
ligne.add(hb6); ligne.add(hb6);
ligne.add(hb7); ligne.add(hb7);
ligne.add(hb8); ligne.add(hb8);
listeHbIA.add(hbr1);
listeHbIA.add(hbr2);
listeHbIA.add(hbr3);
listeHbIA.add(hbr4);
listeHbIA.add(hbr5);
listeHbIA.add(hbr6);
listeHbIA.add(hbr7);
listeHbIA.add(hbr8);
listeToggleRbIa.add(tg1);
listeToggleRbIa.add(tg2);
listeToggleRbIa.add(tg3);
listeToggleRbIa.add(tg4);
listeToggleRbIa.add(tg5);
listeToggleRbIa.add(tg6);
listeToggleRbIa.add(tg7);
listeToggleRbIa.add(tg8);
for (HBox hb : ligne) { for (HBox hb : ligne) {
txt.add((TextField) hb.getChildren().get(0)); txt.add((TextField) hb.getChildren().get(0));
plus.add((Button) hb.getChildren().get(1)); plus.add((Button) hb.getChildren().get(1));
ia.add((CheckBox) hb.getChildren().get(2)); ia.add((CheckBox) hb.getChildren().get(2));
} }
for (HBox hbr : listeHbIA) {
listeIaLv1.add((RadioButton) hbr.getChildren().get(0));
listeIaLv2.add((RadioButton) hbr.getChildren().get(1));
listeIaLv3.add((RadioButton) hbr.getChildren().get(2));
hbr.getChildren().get(0).setVisible(false);
hbr.getChildren().get(1).setVisible(false);
hbr.getChildren().get(2).setVisible(false);
}
int i=0; int i=0;
for (Button btn : plus) { for (Button btn : plus) {
int compteur = i; int compteur = i;
@ -106,10 +170,10 @@ public class PlayersController implements Initializable{
CheckBox cb = (CheckBox) hb.getChildren().get(2); CheckBox cb = (CheckBox) hb.getChildren().get(2);
if (tf.isEditable()) { if (tf.isEditable()) {
if(cb.isSelected()) { if(cb.isSelected()) {
joueurs.put(i, new Couple(tf.getText(), true)); joueurs.put(i, new Couple(tf.getText(), choixDifficulte(listeToggleRbIa.get(i))));
} }
else { else {
joueurs.put(i, new Couple(tf.getText(), false)); joueurs.put(i, new Couple(tf.getText()));
} }
} }
i++; i++;
@ -170,6 +234,12 @@ public class PlayersController implements Initializable{
plus.get(indice).setOnAction(e -> {enleverJoueur(indice);}); plus.get(indice).setOnAction(e -> {enleverJoueur(indice);});
if (ia.get(indice).isSelected()) { if (ia.get(indice).isSelected()) {
listeIaLv1.get(indice).setVisible(true);
listeIaLv2.get(indice).setVisible(true);
listeIaLv3.get(indice).setVisible(true);
nbJoueursV++; nbJoueursV++;
}else { }else {
nbJoueursH++; nbJoueursH++;
@ -197,16 +267,47 @@ public class PlayersController implements Initializable{
txt.get(indice).setStyle("-fx-background-color: silver;"); txt.get(indice).setStyle("-fx-background-color: silver;");
plus.get(indice).setOnAction(e -> {ajoutJoueur(indice);}); plus.get(indice).setOnAction(e -> {ajoutJoueur(indice);});
if (ia.get(indice).isSelected()) if (ia.get(indice).isSelected()) {
nbJoueursV--; nbJoueursV--;
else }
else {
nbJoueursH--; nbJoueursH--;
}
listeIaLv1.get(indice).setVisible(false);
listeIaLv2.get(indice).setVisible(false);
listeIaLv3.get(indice).setVisible(false);
if (nbJoueursH + nbJoueursV < 4) { if (nbJoueursH + nbJoueursV < 4) {
btnCommencer.setStyle("-fx-background-color: gray; -fx-text-fill: black;"); btnCommencer.setStyle("-fx-background-color: gray; -fx-text-fill: black;");
} }
} }
public int choixDifficulte(ToggleGroup tog) {
if(tog.getSelectedToggle() == tog.getToggles().get(0)) {
System.out.println("ia facile");
return 1;
}
else if (tog.getSelectedToggle() == tog.getToggles().get(1)) {
System.out.println("ia moyenne");
return 2;
}
else if (tog.getSelectedToggle() == tog.getToggles().get(2)) {
System.out.println("ia difficile");
return 3;
}
else {
System.out.println("erreur choix difficulté de l'ia");
return -1;
}
}
public void mettreNomDefaut(int indice) { public void mettreNomDefaut(int indice) {
if (ia.get(indice).isSelected()) { if (ia.get(indice).isSelected()) {
ajoutJoueur(indice); ajoutJoueur(indice);

View File

@ -25,11 +25,19 @@
<children> <children>
<VBox alignment="BOTTOM_CENTER" prefHeight="100.0" prefWidth="214.0"> <VBox alignment="BOTTOM_CENTER" prefHeight="100.0" prefWidth="214.0">
<children> <children>
<HBox alignment="CENTER" prefHeight="43.0" prefWidth="295.0"> <HBox fx:id="hbr8" alignment="CENTER" prefHeight="43.0" prefWidth="295.0">
<children> <children>
<RadioButton mnemonicParsing="false" text="RadioButton" /> <RadioButton mnemonicParsing="false" styleClass="titre" text="Facile">
<RadioButton mnemonicParsing="false" text="RadioButton" /> <toggleGroup>
<RadioButton mnemonicParsing="false" text="RadioButton" /> <ToggleGroup fx:id="tg8" />
</toggleGroup>
</RadioButton>
<RadioButton mnemonicParsing="false" selected="true" styleClass="titre" text="Moyen" toggleGroup="$tg8">
<padding>
<Insets left="20.0" right="20.0" />
</padding>
</RadioButton>
<RadioButton mnemonicParsing="false" styleClass="titre" text="Difficile" toggleGroup="$tg8" />
</children> </children>
</HBox> </HBox>
<HBox fx:id="hb8" alignment="CENTER" prefHeight="100.0" prefWidth="200.0"> <HBox fx:id="hb8" alignment="CENTER" prefHeight="100.0" prefWidth="200.0">
@ -65,11 +73,19 @@
<children> <children>
<VBox alignment="BOTTOM_CENTER" prefHeight="100.0" prefWidth="214.0"> <VBox alignment="BOTTOM_CENTER" prefHeight="100.0" prefWidth="214.0">
<children> <children>
<HBox alignment="CENTER" prefHeight="43.0" prefWidth="295.0"> <HBox fx:id="hbr7" alignment="CENTER" prefHeight="43.0" prefWidth="295.0">
<children> <children>
<RadioButton mnemonicParsing="false" text="RadioButton" /> <RadioButton mnemonicParsing="false" styleClass="titre" text="Facile">
<RadioButton mnemonicParsing="false" text="RadioButton" /> <toggleGroup>
<RadioButton mnemonicParsing="false" text="RadioButton" /> <ToggleGroup fx:id="tg7" />
</toggleGroup>
</RadioButton>
<RadioButton mnemonicParsing="false" selected="true" styleClass="titre" text="Moyen" toggleGroup="$tg7">
<padding>
<Insets left="20.0" right="20.0" />
</padding>
</RadioButton>
<RadioButton mnemonicParsing="false" styleClass="titre" text="Difficile" toggleGroup="$tg7" />
</children> </children>
</HBox> </HBox>
<HBox fx:id="hb7" alignment="CENTER" prefHeight="100.0" prefWidth="200.0"> <HBox fx:id="hb7" alignment="CENTER" prefHeight="100.0" prefWidth="200.0">
@ -113,11 +129,19 @@
<children> <children>
<VBox alignment="BOTTOM_CENTER" prefHeight="100.0" prefWidth="214.0"> <VBox alignment="BOTTOM_CENTER" prefHeight="100.0" prefWidth="214.0">
<children> <children>
<HBox alignment="CENTER" prefHeight="43.0" prefWidth="295.0"> <HBox fx:id="hbr4" alignment="CENTER" prefHeight="43.0" prefWidth="295.0">
<children> <children>
<RadioButton mnemonicParsing="false" text="RadioButton" /> <RadioButton mnemonicParsing="false" styleClass="titre" text="Facile">
<RadioButton mnemonicParsing="false" text="RadioButton" /> <toggleGroup>
<RadioButton mnemonicParsing="false" text="RadioButton" /> <ToggleGroup fx:id="tg4" />
</toggleGroup>
</RadioButton>
<RadioButton mnemonicParsing="false" selected="true" styleClass="titre" text="Moyen" toggleGroup="$tg4">
<padding>
<Insets left="20.0" right="20.0" />
</padding>
</RadioButton>
<RadioButton mnemonicParsing="false" styleClass="titre" text="Difficile" toggleGroup="$tg4" />
</children> </children>
</HBox> </HBox>
<HBox fx:id="hb4" alignment="CENTER" prefHeight="100.0" prefWidth="200.0"> <HBox fx:id="hb4" alignment="CENTER" prefHeight="100.0" prefWidth="200.0">
@ -153,11 +177,19 @@
<children> <children>
<VBox alignment="BOTTOM_CENTER" prefHeight="100.0" prefWidth="214.0"> <VBox alignment="BOTTOM_CENTER" prefHeight="100.0" prefWidth="214.0">
<children> <children>
<HBox alignment="CENTER" prefHeight="43.0" prefWidth="295.0"> <HBox fx:id="hbr3" alignment="CENTER" prefHeight="43.0" prefWidth="295.0">
<children> <children>
<RadioButton mnemonicParsing="false" text="RadioButton" /> <RadioButton mnemonicParsing="false" styleClass="titre" text="Facile">
<RadioButton mnemonicParsing="false" text="RadioButton" /> <toggleGroup>
<RadioButton mnemonicParsing="false" text="RadioButton" /> <ToggleGroup fx:id="tg3" />
</toggleGroup>
</RadioButton>
<RadioButton mnemonicParsing="false" selected="true" styleClass="titre" text="Moyen" toggleGroup="$tg3">
<padding>
<Insets left="20.0" right="20.0" />
</padding>
</RadioButton>
<RadioButton mnemonicParsing="false" styleClass="titre" text="Difficile" toggleGroup="$tg3" />
</children> </children>
</HBox> </HBox>
<HBox fx:id="hb3" alignment="CENTER" prefHeight="100.0" prefWidth="200.0"> <HBox fx:id="hb3" alignment="CENTER" prefHeight="100.0" prefWidth="200.0">
@ -234,7 +266,7 @@
<children> <children>
<VBox alignment="CENTER" prefHeight="110.0" prefWidth="559.0" spacing="10.0"> <VBox alignment="CENTER" prefHeight="110.0" prefWidth="559.0" spacing="10.0">
<children> <children>
<HBox fx:id="hb6" alignment="CENTER" prefWidth="754.0"> <HBox fx:id="hb6" alignment="CENTER" prefWidth="754.0" rotate="180.0">
<children> <children>
<TextField> <TextField>
<font> <font>
@ -256,18 +288,24 @@
</CheckBox> </CheckBox>
</children> </children>
</HBox> </HBox>
<HBox alignment="CENTER" prefHeight="20.0" prefWidth="762.0"> <HBox fx:id="hbr6" alignment="CENTER" prefHeight="20.0" prefWidth="762.0">
<children> <children>
<RadioButton contentDisplay="CENTER" mnemonicParsing="false" rotate="180.0" text="RadioButton" /> <RadioButton contentDisplay="CENTER" mnemonicParsing="false" rotate="180.0" styleClass="titre" text="Difficile">
<RadioButton mnemonicParsing="false" rotate="180.0" text="RadioButton" /> <toggleGroup>
<RadioButton mnemonicParsing="false" rotate="180.0" text="RadioButton" /> <ToggleGroup fx:id="tg6" />
</toggleGroup></RadioButton>
<RadioButton mnemonicParsing="false" rotate="180.0" selected="true" styleClass="titre" text="Moyen" toggleGroup="$tg6">
<padding>
<Insets left="20.0" right="20.0" />
</padding></RadioButton>
<RadioButton mnemonicParsing="false" rotate="180.0" styleClass="titre" text="Facile" toggleGroup="$tg6" />
</children> </children>
</HBox> </HBox>
</children> </children>
</VBox> </VBox>
<VBox alignment="CENTER" spacing="10.0"> <VBox alignment="CENTER" spacing="10.0">
<children> <children>
<HBox fx:id="hb5" alignment="CENTER" prefHeight="55.0" prefWidth="537.0"> <HBox fx:id="hb5" alignment="CENTER" prefHeight="55.0" prefWidth="537.0" rotate="180.0">
<children> <children>
<TextField accessibleRole="PARENT"> <TextField accessibleRole="PARENT">
<font> <font>
@ -292,11 +330,17 @@
</CheckBox> </CheckBox>
</children> </children>
</HBox> </HBox>
<HBox alignment="CENTER" prefHeight="6.0" prefWidth="356.0"> <HBox fx:id="hbr5" alignment="CENTER" prefHeight="6.0" prefWidth="356.0">
<children> <children>
<RadioButton mnemonicParsing="false" rotate="180.0" text="RadioButton" /> <RadioButton mnemonicParsing="false" rotate="180.0" styleClass="titre" text="Difficile">
<RadioButton mnemonicParsing="false" rotate="180.0" text="RadioButton" /> <toggleGroup>
<RadioButton mnemonicParsing="false" rotate="180.0" text="RadioButton" /> <ToggleGroup fx:id="tg5" />
</toggleGroup></RadioButton>
<RadioButton mnemonicParsing="false" rotate="180.0" selected="true" styleClass="titre" text="Moyen" toggleGroup="$tg5">
<padding>
<Insets left="20.0" right="20.0" />
</padding></RadioButton>
<RadioButton mnemonicParsing="false" rotate="180.0" styleClass="titre" text="Facile" toggleGroup="$tg5" />
</children> </children>
</HBox> </HBox>
</children> </children>
@ -311,14 +355,20 @@
<children> <children>
<VBox alignment="CENTER" prefHeight="70.0" prefWidth="1338.0" spacing="20.0"> <VBox alignment="CENTER" prefHeight="70.0" prefWidth="1338.0" spacing="20.0">
<children> <children>
<HBox alignment="CENTER" prefHeight="43.0" prefWidth="688.0"> <HBox fx:id="hbr1" alignment="CENTER" prefHeight="43.0" prefWidth="688.0">
<children> <children>
<RadioButton mnemonicParsing="false" text="RadioButton"> <RadioButton mnemonicParsing="false" styleClass="titre" text="Facile">
<opaqueInsets>
<Insets />
</opaqueInsets>
<toggleGroup> <toggleGroup>
<ToggleGroup fx:id="tg1" /> <ToggleGroup fx:id="tg1" />
</toggleGroup></RadioButton> </toggleGroup></RadioButton>
<RadioButton mnemonicParsing="false" text="RadioButton" toggleGroup="$tg1" /> <RadioButton mnemonicParsing="false" selected="true" styleClass="titre" text="Moyen" toggleGroup="$tg1">
<RadioButton mnemonicParsing="false" text="RadioButton" toggleGroup="$tg1" /> <padding>
<Insets left="20.0" right="20.0" />
</padding></RadioButton>
<RadioButton mnemonicParsing="false" styleClass="titre" text="Difficile" toggleGroup="$tg1" />
</children> </children>
<padding> <padding>
<Insets bottom="-5.0" /> <Insets bottom="-5.0" />
@ -356,11 +406,19 @@
</VBox> </VBox>
<VBox alignment="CENTER" prefHeight="70.0" prefWidth="1213.0"> <VBox alignment="CENTER" prefHeight="70.0" prefWidth="1213.0">
<children> <children>
<HBox alignment="CENTER" prefHeight="43.0" prefWidth="688.0"> <HBox fx:id="hbr2" alignment="CENTER" prefHeight="43.0" prefWidth="688.0">
<children> <children>
<RadioButton mnemonicParsing="false" text="RadioButton" /> <RadioButton mnemonicParsing="false" styleClass="titre" text="Facile">
<RadioButton mnemonicParsing="false" text="RadioButton" /> <toggleGroup>
<RadioButton mnemonicParsing="false" text="RadioButton" /> <ToggleGroup fx:id="tg2" />
</toggleGroup>
</RadioButton>
<RadioButton mnemonicParsing="false" selected="true" styleClass="titre" text="Moyen" toggleGroup="$tg2">
<padding>
<Insets left="20.0" right="20.0" />
</padding>
</RadioButton>
<RadioButton mnemonicParsing="false" styleClass="titre" text="Difficile" toggleGroup="$tg2" />
</children> </children>
<padding> <padding>
<Insets bottom="10.0" /> <Insets bottom="10.0" />