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-23 10:11:41 +02:00
|
|
|
|
import java.util.HashMap;
|
2020-04-22 12:34:16 +02:00
|
|
|
|
import java.util.List;
|
2020-04-24 10:09:30 +02:00
|
|
|
|
import java.util.Map;
|
2020-04-17 15:51:50 +02:00
|
|
|
|
import java.util.ResourceBundle;
|
|
|
|
|
|
2020-04-23 10:30:03 +02:00
|
|
|
|
import ihm.Couple;
|
2020-04-17 15:51:50 +02:00
|
|
|
|
import javafx.fxml.FXML;
|
|
|
|
|
import javafx.fxml.FXMLLoader;
|
|
|
|
|
import javafx.fxml.Initializable;
|
2020-04-23 13:47:40 +02:00
|
|
|
|
import javafx.scene.Node;
|
2020-04-22 12:34:16 +02:00
|
|
|
|
import javafx.scene.Parent;
|
2020-04-23 13:47:40 +02:00
|
|
|
|
import javafx.scene.Scene;
|
2020-04-22 12:34:16 +02:00
|
|
|
|
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;
|
2020-04-23 13:47:40 +02:00
|
|
|
|
import javafx.scene.layout.AnchorPane;
|
2020-04-21 20:45:29 +02:00
|
|
|
|
import javafx.scene.layout.HBox;
|
2020-04-23 13:47:40 +02:00
|
|
|
|
import javafx.stage.Stage;
|
2020-04-24 10:09:30 +02:00
|
|
|
|
import main.Configuration;
|
|
|
|
|
import main.GestionnaireJeu;
|
|
|
|
|
import main.Joueur;
|
2020-04-17 15:51:50 +02:00
|
|
|
|
|
|
|
|
|
public class PlayersController implements Initializable{
|
2020-04-21 20:45:29 +02:00
|
|
|
|
|
2020-04-23 13:47:40 +02:00
|
|
|
|
@FXML private AnchorPane rootPane;
|
2020-04-24 11:52:19 +02:00
|
|
|
|
@FXML private Button btnCommencer;
|
2020-04-21 20:45:29 +02:00
|
|
|
|
|
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-23 10:30:03 +02:00
|
|
|
|
private HashMap<Integer, Couple> joueurs = new HashMap<Integer, Couple>();
|
2020-04-24 11:52:19 +02:00
|
|
|
|
|
|
|
|
|
private int nbJoueursH = 0;
|
|
|
|
|
private int nbJoueursV = 0;
|
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;
|
2020-04-24 11:52:19 +02:00
|
|
|
|
btn.setOnAction(e -> {ajoutJoueur(compteur);});
|
2020-04-22 12:34:16 +02:00
|
|
|
|
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-24 11:52:19 +02:00
|
|
|
|
|
|
|
|
|
int j=0;
|
|
|
|
|
for (CheckBox cb : ia) {
|
|
|
|
|
int compteur = j;
|
|
|
|
|
cb.setOnAction(e -> {mettreNomDefaut(compteur);});
|
|
|
|
|
j++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
btnCommencer.setStyle("-fx-background-color: gray; -fx-text-fill: black;");
|
2020-04-22 12:34:16 +02:00
|
|
|
|
}
|
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-24 11:52:19 +02:00
|
|
|
|
if (nbJoueursH + nbJoueursV >= 4) {
|
|
|
|
|
//ajout des joueurs finalement selectionner
|
|
|
|
|
int i = 0;
|
|
|
|
|
for (HBox hb : ligne) {
|
|
|
|
|
TextField tf = (TextField) hb.getChildren().get(0);
|
|
|
|
|
CheckBox cb = (CheckBox) hb.getChildren().get(2);
|
|
|
|
|
if (tf.isEditable()) {
|
|
|
|
|
if(cb.isSelected()) {
|
|
|
|
|
joueurs.put(i, new Couple(tf.getText(), true));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
joueurs.put(i, new Couple(tf.getText(), false));
|
|
|
|
|
}
|
2020-04-22 20:42:18 +02:00
|
|
|
|
}
|
2020-04-24 11:52:19 +02:00
|
|
|
|
i++;
|
2020-04-22 20:42:18 +02:00
|
|
|
|
}
|
2020-04-24 11:52:19 +02:00
|
|
|
|
// Creer une configuration
|
|
|
|
|
//View.applyConfiguration(new Configuration(joueurs, nbJoueursV, nbJoueursH));
|
|
|
|
|
|
|
|
|
|
FXMLLoader loader = new FXMLLoader(getClass().getResource("../ressources/Plateau.fxml"));
|
|
|
|
|
Parent root = loader.load();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PlateauController pc = loader.getController();
|
|
|
|
|
GestionnaireJeu.setPlateauController(pc);
|
|
|
|
|
GestionnaireJeu.setConfiguration(new Configuration(this.joueurs));
|
|
|
|
|
Map<Integer, Joueur> map = GestionnaireJeu.getJoueursMap(new Configuration(this.joueurs));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pc.showInformation(map);
|
|
|
|
|
Scene scene = new Scene(root);
|
|
|
|
|
Stage appStage = (Stage) ((Node) mouseEvent.getSource()).getScene().getWindow();
|
|
|
|
|
appStage.setScene(scene);
|
|
|
|
|
appStage.show();
|
|
|
|
|
GestionnaireJeu.lancerPartie();
|
2020-04-22 12:34:16 +02:00
|
|
|
|
}
|
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-24 11:52:19 +02:00
|
|
|
|
|
|
|
|
|
if (ia.get(indice).isSelected()) {
|
|
|
|
|
nbJoueursV++;
|
|
|
|
|
}else
|
|
|
|
|
nbJoueursH++;
|
|
|
|
|
|
|
|
|
|
if (nbJoueursH + nbJoueursV >= 4) {
|
|
|
|
|
btnCommencer.setStyle("-fx-background-color: #1d1d1d; -fx-text-fill: #d8d8d8;");
|
|
|
|
|
}
|
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-24 11:52:19 +02:00
|
|
|
|
|
|
|
|
|
if (ia.get(indice).isSelected())
|
|
|
|
|
nbJoueursV--;
|
|
|
|
|
else
|
|
|
|
|
nbJoueursH--;
|
|
|
|
|
|
|
|
|
|
if (nbJoueursH + nbJoueursV < 4) {
|
|
|
|
|
btnCommencer.setStyle("-fx-background-color: gray; -fx-text-fill: black;");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void mettreNomDefaut(int indice) {
|
|
|
|
|
if (ia.get(indice).isSelected()) {
|
|
|
|
|
ajoutJoueur(indice);
|
|
|
|
|
txt.get(indice).setText("Joueur" + indice);
|
|
|
|
|
}else
|
|
|
|
|
enleverJoueur(indice);
|
2020-04-22 12:34:16 +02:00
|
|
|
|
}
|
2020-04-17 15:51:50 +02:00
|
|
|
|
}
|