2020-04-17 15:51:50 +02:00
|
|
|
|
package ihm.controller;
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.net.URL;
|
2020-04-21 20:45:29 +02:00
|
|
|
|
import java.util.ArrayList;
|
2020-04-22 12:34:16 +02:00
|
|
|
|
import java.util.List;
|
2020-04-17 15:51:50 +02:00
|
|
|
|
import java.util.ResourceBundle;
|
|
|
|
|
|
|
|
|
|
import javafx.fxml.FXML;
|
|
|
|
|
import javafx.fxml.FXMLLoader;
|
|
|
|
|
import javafx.fxml.Initializable;
|
2020-04-22 12:34:16 +02:00
|
|
|
|
import javafx.scene.Parent;
|
|
|
|
|
import javafx.scene.control.Alert;
|
|
|
|
|
import javafx.scene.control.Alert.AlertType;
|
2020-04-21 20:45:29 +02:00
|
|
|
|
import javafx.scene.control.Button;
|
|
|
|
|
import javafx.scene.control.CheckBox;
|
2020-04-20 13:46:18 +02:00
|
|
|
|
import javafx.scene.control.TextField;
|
2020-04-17 15:51:50 +02:00
|
|
|
|
import javafx.scene.input.MouseEvent;
|
|
|
|
|
import javafx.scene.layout.BorderPane;
|
2020-04-21 20:45:29 +02:00
|
|
|
|
import javafx.scene.layout.HBox;
|
2020-04-22 12:34:16 +02:00
|
|
|
|
import main.Joueur;
|
|
|
|
|
import main.JoueurVirtuel;
|
2020-04-23 10:06:54 +02:00
|
|
|
|
import main.View;
|
2020-04-17 15:51:50 +02:00
|
|
|
|
|
|
|
|
|
public class PlayersController implements Initializable{
|
2020-04-21 20:45:29 +02:00
|
|
|
|
|
|
|
|
|
@FXML private BorderPane rootPane;
|
|
|
|
|
|
2020-04-22 12:34:16 +02:00
|
|
|
|
@FXML private HBox hb1;
|
|
|
|
|
@FXML private HBox hb2;
|
|
|
|
|
@FXML private HBox hb3;
|
|
|
|
|
@FXML private HBox hb4;
|
|
|
|
|
@FXML private HBox hb5;
|
|
|
|
|
@FXML private HBox hb6;
|
|
|
|
|
@FXML private HBox hb7;
|
|
|
|
|
@FXML private HBox hb8;
|
2020-04-21 20:45:29 +02:00
|
|
|
|
|
2020-04-22 12:34:16 +02:00
|
|
|
|
private List<HBox> ligne = new ArrayList<HBox>();
|
|
|
|
|
private List<Button> plus = new ArrayList<Button>();
|
|
|
|
|
private List<TextField> txt = new ArrayList<TextField>();
|
|
|
|
|
private List<CheckBox> ia = new ArrayList<CheckBox>();
|
2020-04-21 20:45:29 +02:00
|
|
|
|
|
2020-04-22 20:42:18 +02:00
|
|
|
|
private List<Joueur> joueurs = new ArrayList<Joueur>();
|
2020-04-21 20:45:29 +02:00
|
|
|
|
|
2020-04-20 14:39:19 +02:00
|
|
|
|
|
2020-04-22 12:34:16 +02:00
|
|
|
|
/**
|
2020-04-22 17:04:37 +02:00
|
|
|
|
* recup<EFBFBD>re chaque bouton textField et Checkebox a partir des hbox
|
2020-04-22 12:34:16 +02:00
|
|
|
|
*/
|
2020-04-17 15:51:50 +02:00
|
|
|
|
@Override
|
|
|
|
|
public void initialize(URL arg0, ResourceBundle arg1) {
|
2020-04-22 12:34:16 +02:00
|
|
|
|
ligne.add(hb1);
|
|
|
|
|
ligne.add(hb2);
|
|
|
|
|
ligne.add(hb3);
|
|
|
|
|
ligne.add(hb4);
|
|
|
|
|
ligne.add(hb5);
|
|
|
|
|
ligne.add(hb6);
|
|
|
|
|
ligne.add(hb7);
|
|
|
|
|
ligne.add(hb8);
|
|
|
|
|
for (HBox hb : ligne) {
|
|
|
|
|
txt.add((TextField) hb.getChildren().get(0));
|
|
|
|
|
plus.add((Button) hb.getChildren().get(1));
|
|
|
|
|
ia.add((CheckBox) hb.getChildren().get(2));
|
2020-04-21 20:45:29 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-22 12:34:16 +02:00
|
|
|
|
int i=0;
|
|
|
|
|
for (Button btn : plus) {
|
|
|
|
|
int compteur = i;
|
|
|
|
|
btn.setOnAction(e -> {ajoutJoueur(compteur);});
|
|
|
|
|
i++;
|
|
|
|
|
}
|
2020-04-21 20:45:29 +02:00
|
|
|
|
|
2020-04-22 12:34:16 +02:00
|
|
|
|
for (TextField tf : txt) {
|
|
|
|
|
tf.setEditable(false);
|
|
|
|
|
tf.setStyle("-fx-background-color: silver;");
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-04-21 20:45:29 +02:00
|
|
|
|
|
|
|
|
|
|
2020-04-17 15:51:50 +02:00
|
|
|
|
@FXML
|
|
|
|
|
public void commencerJeux(MouseEvent mouseEvent) throws IOException{
|
2020-04-22 12:34:16 +02:00
|
|
|
|
//ajout des joueurs finalement selectionner
|
2020-04-22 20:42:18 +02:00
|
|
|
|
int nbJoueurs = 0;
|
|
|
|
|
|
2020-04-22 12:34:16 +02:00
|
|
|
|
for (HBox hb : ligne) {
|
2020-04-22 20:42:18 +02:00
|
|
|
|
|
2020-04-22 12:34:16 +02:00
|
|
|
|
TextField tf = (TextField) hb.getChildren().get(0);
|
|
|
|
|
CheckBox cb = (CheckBox) hb.getChildren().get(2);
|
|
|
|
|
Joueur j;
|
2020-04-22 20:42:18 +02:00
|
|
|
|
|
2020-04-22 12:34:16 +02:00
|
|
|
|
if (tf.isEditable()) {
|
2020-04-22 20:42:18 +02:00
|
|
|
|
if(cb.isSelected()) {
|
|
|
|
|
joueurs.add(new Joueur(tf.getText()));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
joueurs.add(new JoueurVirtuel(tf.getText()));
|
|
|
|
|
}
|
2020-04-23 09:26:05 +02:00
|
|
|
|
joueurs.add(null);
|
2020-04-22 20:42:18 +02:00
|
|
|
|
nbJoueurs++;
|
|
|
|
|
}
|
2020-04-23 09:26:05 +02:00
|
|
|
|
|
2020-04-22 12:34:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-22 20:42:18 +02:00
|
|
|
|
if (nbJoueurs < 4) {
|
2020-04-22 16:56:45 +02:00
|
|
|
|
Alert alert = new Alert(AlertType.WARNING, "Il faut au moins de 4 joueurs !");
|
2020-04-22 12:34:16 +02:00
|
|
|
|
alert.showAndWait();
|
|
|
|
|
}else {
|
|
|
|
|
System.out.println("Lancement du jeu...");
|
2020-04-23 10:06:54 +02:00
|
|
|
|
View.initPartie(joueurs);
|
2020-04-22 12:34:16 +02:00
|
|
|
|
FXMLLoader loader = new FXMLLoader(getClass().getResource("../ressources/Plateau.fxml"));
|
|
|
|
|
Parent root = loader.load();
|
|
|
|
|
|
|
|
|
|
PlateauController pc = loader.getController();
|
2020-04-22 20:42:18 +02:00
|
|
|
|
pc.showInformation(joueurs);
|
2020-04-22 12:34:16 +02:00
|
|
|
|
|
|
|
|
|
rootPane.getChildren().setAll(root);
|
|
|
|
|
}
|
2020-04-17 15:51:50 +02:00
|
|
|
|
}
|
2020-04-22 12:34:16 +02:00
|
|
|
|
|
2020-04-22 20:42:18 +02:00
|
|
|
|
|
|
|
|
|
|
2020-04-22 12:34:16 +02:00
|
|
|
|
/**
|
2020-04-22 17:04:37 +02:00
|
|
|
|
* Autorise a <EFBFBD>crire dans le text filed le nom du joueur ajouter
|
2020-04-22 12:34:16 +02:00
|
|
|
|
*
|
2020-04-22 17:04:37 +02:00
|
|
|
|
* @param indice : pour savoir quel bouton a <EFBFBD>t<EFBFBD> cliqu<EFBFBD>
|
2020-04-22 12:34:16 +02:00
|
|
|
|
*/
|
|
|
|
|
public void ajoutJoueur(int indice){
|
|
|
|
|
System.out.println("Ajout du joueur " + (indice+1));
|
|
|
|
|
plus.get(indice).setText("- ");
|
|
|
|
|
txt.get(indice).setEditable(true);
|
|
|
|
|
txt.get(indice).setStyle("-fx-background-color: white;");
|
|
|
|
|
plus.get(indice).setOnAction(e -> {enleverJoueur(indice);});
|
2020-04-20 14:39:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-22 12:34:16 +02:00
|
|
|
|
/**
|
2020-04-22 17:14:38 +02:00
|
|
|
|
* Retire le joueur précedemnt ajouter
|
2020-04-22 12:34:16 +02:00
|
|
|
|
*
|
2020-04-22 17:04:37 +02:00
|
|
|
|
* @param indice : pour savoir quel bouton a <EFBFBD>t<EFBFBD> cliqu<EFBFBD>
|
2020-04-22 12:34:16 +02:00
|
|
|
|
*/
|
|
|
|
|
public void enleverJoueur(int indice) {
|
|
|
|
|
System.out.println("Desistement du joueur " + (indice+1));
|
|
|
|
|
plus.get(indice).setText("+");
|
|
|
|
|
txt.get(indice).setEditable(false);
|
|
|
|
|
txt.get(indice).setText("");
|
|
|
|
|
txt.get(indice).setStyle("-fx-background-color: silver;");
|
|
|
|
|
plus.get(indice).setOnAction(e -> {ajoutJoueur(indice);});
|
|
|
|
|
}
|
2020-04-17 15:51:50 +02:00
|
|
|
|
}
|