diff options
| author | polo <ordipolo@gmx.fr> | 2026-07-02 00:14:17 +0200 |
|---|---|---|
| committer | polo <ordipolo@gmx.fr> | 2026-07-02 00:14:17 +0200 |
| commit | 0c2c3ee5a55f36d270171f2f67938542e251fdc5 (patch) | |
| tree | 8ea4d6a7ad09a5b1389b829980a7a5476982e754 | |
| download | ppe_javafx-0c2c3ee5a55f36d270171f2f67938542e251fdc5.tar.gz ppe_javafx-0c2c3ee5a55f36d270171f2f67938542e251fdc5.tar.bz2 ppe_javafx-0c2c3ee5a55f36d270171f2f67938542e251fdc5.zip | |
fork utilisant maven
63 files changed, 5054 insertions, 0 deletions
diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..fe27910 --- /dev/null +++ b/.classpath | |||
| @@ -0,0 +1,40 @@ | |||
| 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | <classpath> | ||
| 3 | <classpathentry kind="src" output="target/classes" path="src/main/java"> | ||
| 4 | <attributes> | ||
| 5 | <attribute name="optional" value="true"/> | ||
| 6 | <attribute name="maven.pomderived" value="true"/> | ||
| 7 | </attributes> | ||
| 8 | </classpathentry> | ||
| 9 | <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"> | ||
| 10 | <attributes> | ||
| 11 | <attribute name="maven.pomderived" value="true"/> | ||
| 12 | <attribute name="optional" value="true"/> | ||
| 13 | </attributes> | ||
| 14 | </classpathentry> | ||
| 15 | <classpathentry kind="src" output="target/test-classes" path="src/test/java"> | ||
| 16 | <attributes> | ||
| 17 | <attribute name="optional" value="true"/> | ||
| 18 | <attribute name="maven.pomderived" value="true"/> | ||
| 19 | <attribute name="test" value="true"/> | ||
| 20 | </attributes> | ||
| 21 | </classpathentry> | ||
| 22 | <classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"> | ||
| 23 | <attributes> | ||
| 24 | <attribute name="maven.pomderived" value="true"/> | ||
| 25 | <attribute name="test" value="true"/> | ||
| 26 | <attribute name="optional" value="true"/> | ||
| 27 | </attributes> | ||
| 28 | </classpathentry> | ||
| 29 | <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21"> | ||
| 30 | <attributes> | ||
| 31 | <attribute name="maven.pomderived" value="true"/> | ||
| 32 | </attributes> | ||
| 33 | </classpathentry> | ||
| 34 | <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> | ||
| 35 | <attributes> | ||
| 36 | <attribute name="maven.pomderived" value="true"/> | ||
| 37 | </attributes> | ||
| 38 | </classpathentry> | ||
| 39 | <classpathentry kind="output" path="target/classes"/> | ||
| 40 | </classpath> | ||
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b83d222 --- /dev/null +++ b/.gitignore | |||
| @@ -0,0 +1 @@ | |||
| /target/ | |||
diff --git a/.project b/.project new file mode 100644 index 0000000..5a70ae9 --- /dev/null +++ b/.project | |||
| @@ -0,0 +1,23 @@ | |||
| 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | <projectDescription> | ||
| 3 | <name>ppe-javafx</name> | ||
| 4 | <comment></comment> | ||
| 5 | <projects> | ||
| 6 | </projects> | ||
| 7 | <buildSpec> | ||
| 8 | <buildCommand> | ||
| 9 | <name>org.eclipse.jdt.core.javabuilder</name> | ||
| 10 | <arguments> | ||
| 11 | </arguments> | ||
| 12 | </buildCommand> | ||
| 13 | <buildCommand> | ||
| 14 | <name>org.eclipse.m2e.core.maven2Builder</name> | ||
| 15 | <arguments> | ||
| 16 | </arguments> | ||
| 17 | </buildCommand> | ||
| 18 | </buildSpec> | ||
| 19 | <natures> | ||
| 20 | <nature>org.eclipse.jdt.core.javanature</nature> | ||
| 21 | <nature>org.eclipse.m2e.core.maven2Nature</nature> | ||
| 22 | </natures> | ||
| 23 | </projectDescription> | ||
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..623e652 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | eclipse.preferences.version=1 | ||
| 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=21 | ||
| 3 | org.eclipse.jdt.core.compiler.compliance=21 | ||
| 4 | org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled | ||
| 5 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning | ||
| 6 | org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore | ||
| 7 | org.eclipse.jdt.core.compiler.release=enabled | ||
| 8 | org.eclipse.jdt.core.compiler.source=21 | ||
diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/.settings/org.eclipse.m2e.core.prefs | |||
| @@ -0,0 +1,4 @@ | |||
| 1 | activeProfiles= | ||
| 2 | eclipse.preferences.version=1 | ||
| 3 | resolveWorkspaceProjects=true | ||
| 4 | version=1 | ||
| @@ -0,0 +1,55 @@ | |||
| 1 | <project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| 2 | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| 3 | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 | ||
| 4 | https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| 5 | |||
| 6 | <modelVersion>4.0.0</modelVersion> | ||
| 7 | <groupId>bts_sio</groupId> | ||
| 8 | <artifactId>ppe_javafx</artifactId> | ||
| 9 | <version>0.0.1-SNAPSHOT</version> | ||
| 10 | |||
| 11 | <properties> | ||
| 12 | <maven.compiler.release>21</maven.compiler.release> | ||
| 13 | <javafx.version>21.0.5</javafx.version> | ||
| 14 | <mariadb.version>3.5.8</mariadb.version> | ||
| 15 | </properties> | ||
| 16 | |||
| 17 | <dependencies> | ||
| 18 | <dependency> | ||
| 19 | <groupId>org.openjfx</groupId> | ||
| 20 | <artifactId>javafx-controls</artifactId> | ||
| 21 | <version>${javafx.version}</version> | ||
| 22 | </dependency> | ||
| 23 | <dependency> | ||
| 24 | <groupId>org.mariadb.jdbc</groupId> | ||
| 25 | <artifactId>mariadb-java-client</artifactId> | ||
| 26 | <version>${mariadb.version}</version> | ||
| 27 | </dependency> | ||
| 28 | </dependencies> | ||
| 29 | |||
| 30 | <build> | ||
| 31 | <plugins> | ||
| 32 | <!-- compilateur Java --> | ||
| 33 | <plugin> | ||
| 34 | <groupId>org.apache.maven.plugins</groupId> | ||
| 35 | <artifactId>maven-compiler-plugin</artifactId> | ||
| 36 | <version>3.13.0</version> | ||
| 37 | <configuration> | ||
| 38 | <release>${maven.compiler.release}</release> | ||
| 39 | </configuration> | ||
| 40 | </plugin> | ||
| 41 | |||
| 42 | <!-- plugin permettant d'utiliser javafx en dev --> | ||
| 43 | <plugin> | ||
| 44 | <groupId>org.openjfx</groupId> | ||
| 45 | <artifactId>javafx-maven-plugin</artifactId> | ||
| 46 | <version>0.0.8</version> | ||
| 47 | <configuration> | ||
| 48 | <mainClass>application.Main</mainClass> | ||
| 49 | <launcher>ppe_javafx</launcher> <!-- nom du lanceur créé par jlink, mode prod --> | ||
| 50 | </configuration> | ||
| 51 | </plugin> | ||
| 52 | |||
| 53 | </plugins> | ||
| 54 | </build> | ||
| 55 | </project> \ No newline at end of file | ||
diff --git a/src/main/java/application/Battle.java b/src/main/java/application/Battle.java new file mode 100644 index 0000000..4799b20 --- /dev/null +++ b/src/main/java/application/Battle.java | |||
| @@ -0,0 +1,90 @@ | |||
| 1 | package application; | ||
| 2 | |||
| 3 | import java.lang.reflect.Field; | ||
| 4 | import modele.Arme; | ||
| 5 | import modele.Armee; | ||
| 6 | import modele.ArmeeListe; | ||
| 7 | import modele.Unit; | ||
| 8 | |||
| 9 | /* mémoire des actions de l'utilisateurs, liste, unités, PV, armes, aptitudes */ | ||
| 10 | public class Battle | ||
| 11 | { | ||
| 12 | static private ArmeeListe selected_list1 = null; | ||
| 13 | static private ArmeeListe selected_list2 = null; | ||
| 14 | static private Armee army1; | ||
| 15 | static private Armee army2; | ||
| 16 | static private int index_selected_unit1 = -1; | ||
| 17 | static private int index_selected_unit2 = -1; | ||
| 18 | |||
| 19 | // getters/setters | ||
| 20 | static public ArmeeListe getSelectedList(int nb) { | ||
| 21 | return (nb == 1 ? selected_list1 : selected_list2); | ||
| 22 | } | ||
| 23 | static public void setSelectedList(int nb, ArmeeListe list) { | ||
| 24 | if(nb == 1) { | ||
| 25 | selected_list1 = list; | ||
| 26 | } | ||
| 27 | else if(nb == 2) { | ||
| 28 | selected_list2 = list; | ||
| 29 | } | ||
| 30 | else { | ||
| 31 | System.out.println("le paramètre nb doit valoir 1 ou 2"); | ||
| 32 | } | ||
| 33 | } | ||
| 34 | static public Armee getArmy(int nb) { | ||
| 35 | return (nb == 1 ? army1 : army2); | ||
| 36 | } | ||
| 37 | static public void setArmy(int nb, Armee a) { | ||
| 38 | if(nb == 1) { | ||
| 39 | army1 = a; | ||
| 40 | } | ||
| 41 | else if(nb == 2) { | ||
| 42 | army2 = a; | ||
| 43 | } | ||
| 44 | else { | ||
| 45 | System.out.println("le paramètre nb doit valoir 1 ou 2"); | ||
| 46 | } | ||
| 47 | } | ||
| 48 | static public Unit getSelectedUnit(int nb) { | ||
| 49 | return (nb == 1 ? selected_list1.getUnits().get(index_selected_unit1) : selected_list2.getUnits().get(index_selected_unit2)); | ||
| 50 | } | ||
| 51 | static public int getSelectedUnitIndex(int nb) { | ||
| 52 | return (nb == 1 ? index_selected_unit1 : index_selected_unit2); | ||
| 53 | } | ||
| 54 | static public void setSelectedUnit(int nb, int unit_list_index) { | ||
| 55 | if(nb == 1) { | ||
| 56 | index_selected_unit1 = unit_list_index; | ||
| 57 | } | ||
| 58 | else if(nb == 2) { | ||
| 59 | index_selected_unit2 = unit_list_index; | ||
| 60 | } | ||
| 61 | else { | ||
| 62 | System.out.println("le paramètre nb doit valoir 1 ou 2"); | ||
| 63 | } | ||
| 64 | } | ||
| 65 | static public Arme getSeletedWeapon(int nb, String group_name) { | ||
| 66 | return getSelectedUnit(nb).getIdenticalFigsGroups().get(group_name).get(0).getSelectedWeapon(); | ||
| 67 | } | ||
| 68 | static public void reverseArmies() | ||
| 69 | { | ||
| 70 | Field[] fields = selected_list1.getClass().getDeclaredFields(); | ||
| 71 | try { | ||
| 72 | for (Field field : fields) { | ||
| 73 | field.setAccessible(true); | ||
| 74 | Object temp = field.get(selected_list1); | ||
| 75 | field.set(selected_list1, field.get(selected_list2)); | ||
| 76 | field.set(selected_list2, temp); | ||
| 77 | } | ||
| 78 | } catch (IllegalAccessException e) { | ||
| 79 | e.printStackTrace(); | ||
| 80 | } | ||
| 81 | } | ||
| 82 | static public void clean() { | ||
| 83 | selected_list1 = null; | ||
| 84 | selected_list2 = null; | ||
| 85 | army1 = null; | ||
| 86 | army2 = null; | ||
| 87 | index_selected_unit1 = -1; | ||
| 88 | index_selected_unit2 = -1; | ||
| 89 | } | ||
| 90 | } | ||
diff --git a/src/main/java/application/Main.java b/src/main/java/application/Main.java new file mode 100644 index 0000000..4054705 --- /dev/null +++ b/src/main/java/application/Main.java | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | package application; | ||
| 2 | |||
| 3 | import javafx.application.Application; | ||
| 4 | import javafx.stage.Stage; | ||
| 5 | import vue.AfficheConnexion; | ||
| 6 | |||
| 7 | public class Main extends Application { | ||
| 8 | |||
| 9 | // le main appelle la vue de connexion | ||
| 10 | @Override | ||
| 11 | public void start(Stage primaryStage) { | ||
| 12 | try { | ||
| 13 | |||
| 14 | AfficheConnexion.affiche(primaryStage); | ||
| 15 | } catch (Exception e) { | ||
| 16 | e.printStackTrace(); | ||
| 17 | } | ||
| 18 | } | ||
| 19 | |||
| 20 | public static void main(String[] args) { | ||
| 21 | launch(args); | ||
| 22 | |||
| 23 | } | ||
| 24 | } | ||
diff --git a/src/main/java/application/application.css b/src/main/java/application/application.css new file mode 100644 index 0000000..060d859 --- /dev/null +++ b/src/main/java/application/application.css | |||
| @@ -0,0 +1,7 @@ | |||
| 1 | /* JavaFX CSS - Leave this comment until you have at least create one rule which uses -fx-Property */ | ||
| 2 | |||
| 3 | .vbox-border { | ||
| 4 | -fx-border-color: black; | ||
| 5 | -fx-border-width: 2px; | ||
| 6 | -fx-border-radius: 5px; | ||
| 7 | } | ||
diff --git a/src/main/java/controlleur/BDD.java b/src/main/java/controlleur/BDD.java new file mode 100644 index 0000000..af1a754 --- /dev/null +++ b/src/main/java/controlleur/BDD.java | |||
| @@ -0,0 +1,322 @@ | |||
| 1 | package controlleur; | ||
| 2 | |||
| 3 | import java.sql.Connection; | ||
| 4 | import java.sql.Date; | ||
| 5 | import java.sql.DriverManager; | ||
| 6 | import java.sql.PreparedStatement; | ||
| 7 | import java.sql.ResultSet; | ||
| 8 | import java.sql.ResultSetMetaData; | ||
| 9 | import java.sql.SQLException; | ||
| 10 | import java.sql.Statement; | ||
| 11 | import java.util.ArrayList; | ||
| 12 | import java.util.List; | ||
| 13 | |||
| 14 | import javafx.scene.layout.VBox; | ||
| 15 | import modele.Arme; | ||
| 16 | import modele.ArmeeListe; | ||
| 17 | import modele.Evenement; | ||
| 18 | import modele.Unit; | ||
| 19 | import modele.User; | ||
| 20 | |||
| 21 | public class BDD { | ||
| 22 | |||
| 23 | private Connection connec; | ||
| 24 | private PreparedStatement stat = null; | ||
| 25 | private ResultSet rs ; | ||
| 26 | |||
| 27 | private static String user; | ||
| 28 | private static String password; | ||
| 29 | private static String dbname; | ||
| 30 | |||
| 31 | public BDD() { | ||
| 32 | try { | ||
| 33 | //Class.forName("com.mysql.cj.jdbc.Driver"); | ||
| 34 | Class.forName("org.mariadb.jdbc.Driver"); | ||
| 35 | //String host = "mysql-stathammer.alwaysdata.net"; | ||
| 36 | String host = "localhost"; | ||
| 37 | //this.connec = DriverManager.getConnection("jdbc:mysql://" + host + ":3306/"+ dbname, user, password); | ||
| 38 | this.connec = DriverManager.getConnection("jdbc:mariadb://" + host + ":3306/"+ dbname, user, password); | ||
| 39 | this.rs = connec.prepareStatement("SELECT * FROM faction;").executeQuery(); | ||
| 40 | } catch (ClassNotFoundException e) { | ||
| 41 | // TODO: handle exception | ||
| 42 | |||
| 43 | e.printStackTrace(); | ||
| 44 | } catch (SQLException e) { | ||
| 45 | System.err.println(e.getMessage()); | ||
| 46 | } | ||
| 47 | } | ||
| 48 | |||
| 49 | public static void setInfos(String login, String pwd, String base) | ||
| 50 | { | ||
| 51 | user = login; | ||
| 52 | password = pwd; | ||
| 53 | dbname = base; | ||
| 54 | } | ||
| 55 | |||
| 56 | public Statement getStatement() throws SQLException | ||
| 57 | { | ||
| 58 | return connec.createStatement(); | ||
| 59 | } | ||
| 60 | |||
| 61 | public PreparedStatement getPreparedStatement(String sql, Object... params) throws SQLException | ||
| 62 | { | ||
| 63 | stat = connec.prepareStatement(sql); | ||
| 64 | if(params.length > 0) | ||
| 65 | { | ||
| 66 | for (int i = 0; i < params.length; i++) { | ||
| 67 | stat.setObject(i + 1, params[i]); | ||
| 68 | } | ||
| 69 | } | ||
| 70 | return stat; | ||
| 71 | } | ||
| 72 | |||
| 73 | public ArrayList<Object> selectUtilisateur(String nom, String mdp) { | ||
| 74 | ArrayList<Object> rendu = new ArrayList<Object>(); | ||
| 75 | try { | ||
| 76 | |||
| 77 | String requete = "SELECT id_utilisateur, nom_utilisateur, role_utilisateur FROM utilisateur WHERE nom_utilisateur=? AND mdp_utilisateur = ?;"; | ||
| 78 | stat = connec.prepareStatement(requete); | ||
| 79 | stat.setString(1, nom); | ||
| 80 | stat.setString(2,String.valueOf(mdp)); | ||
| 81 | //stat.setString(2,String.valueOf(mdp.hashCode())); | ||
| 82 | |||
| 83 | ResultSet rs = stat.executeQuery(); | ||
| 84 | ResultSetMetaData md = rs.getMetaData(); | ||
| 85 | ArrayList<String> column = new ArrayList<String>(); | ||
| 86 | |||
| 87 | for (int i = 1; i <= md.getColumnCount(); i++) { | ||
| 88 | column.add(md.getColumnName(i)); | ||
| 89 | } | ||
| 90 | while (rs.next()) { | ||
| 91 | rendu.add(rs.getString("nom_utilisateur")); | ||
| 92 | rendu.add(rs.getInt("id_utilisateur")); | ||
| 93 | rendu.add(rs.getString("role_utilisateur")); | ||
| 94 | } | ||
| 95 | return rendu; | ||
| 96 | |||
| 97 | } catch (SQLException e) { | ||
| 98 | // TODO: handle exception | ||
| 99 | System.err.println(e.getMessage()); | ||
| 100 | |||
| 101 | } | ||
| 102 | return rendu; | ||
| 103 | } | ||
| 104 | |||
| 105 | public ArrayList<String> creerUtilisateur(String adresse, String nom, String mdp) { | ||
| 106 | ArrayList<String> crea = new ArrayList<String>(); | ||
| 107 | |||
| 108 | String creationRequete = "INSERT INTO utilisateur" + " (nom_utilisateur, email_utilisateur, mdp_utilisateur)" | ||
| 109 | + "VALUES (?, ?, ?);"; | ||
| 110 | try { | ||
| 111 | if (connec == null || connec.isClosed()) { | ||
| 112 | System.err.println("La connexion à la bdd n'est pas possible."); | ||
| 113 | return crea; | ||
| 114 | } | ||
| 115 | PreparedStatement stat = connec.prepareStatement(creationRequete); | ||
| 116 | stat.setString(1, nom); | ||
| 117 | stat.setString(2, adresse); | ||
| 118 | stat.setString(3, mdp); | ||
| 119 | |||
| 120 | int rowsInserted = stat.executeUpdate(); | ||
| 121 | |||
| 122 | if (rowsInserted > 0) { | ||
| 123 | crea.add(adresse); | ||
| 124 | } | ||
| 125 | stat.close(); | ||
| 126 | } catch (SQLException e) { | ||
| 127 | System.err.println("Erreur SQL : " + e.getMessage()); | ||
| 128 | } | ||
| 129 | return crea; | ||
| 130 | } | ||
| 131 | |||
| 132 | public Connection getConnection() { | ||
| 133 | return this.connec; | ||
| 134 | } | ||
| 135 | |||
| 136 | public void close() { | ||
| 137 | try { | ||
| 138 | connec.close(); | ||
| 139 | } catch (SQLException e) { | ||
| 140 | // TODO Auto-generated catch block | ||
| 141 | e.printStackTrace(); | ||
| 142 | } | ||
| 143 | } | ||
| 144 | |||
| 145 | public ArrayList<String> select(String requete,String... param ) throws SQLException{ | ||
| 146 | ArrayList<String> rendu = new ArrayList<String>(); | ||
| 147 | try { | ||
| 148 | PreparedStatement pstat = null; | ||
| 149 | |||
| 150 | pstat = connec.prepareStatement(requete); | ||
| 151 | if(param.length>0) { | ||
| 152 | for(int i = 1;i<=param.length;i++) { | ||
| 153 | pstat.setString(i, param[i-1]); | ||
| 154 | } | ||
| 155 | } | ||
| 156 | |||
| 157 | rs.close(); | ||
| 158 | rs = pstat.executeQuery(); | ||
| 159 | ResultSetMetaData md = rs.getMetaData(); | ||
| 160 | ArrayList<String> column = new ArrayList<String>(); | ||
| 161 | |||
| 162 | |||
| 163 | for(int i =1;i<=md.getColumnCount();i++) { | ||
| 164 | column.add(md.getColumnName(i)); | ||
| 165 | } | ||
| 166 | while(rs.next()) { | ||
| 167 | for (String col : column) { | ||
| 168 | rendu.add(rs.getString(col)); | ||
| 169 | } | ||
| 170 | |||
| 171 | |||
| 172 | |||
| 173 | } | ||
| 174 | |||
| 175 | return rendu; | ||
| 176 | |||
| 177 | } catch (SQLException e) { | ||
| 178 | // TODO: handle exception | ||
| 179 | System.err.println(e.getMessage()); | ||
| 180 | |||
| 181 | |||
| 182 | } | ||
| 183 | return rendu; | ||
| 184 | } | ||
| 185 | |||
| 186 | public void updateUtilisateur(String pseudo,int id) { | ||
| 187 | try { | ||
| 188 | stat = this.getPreparedStatement("UPDATE `utilisateur` SET nom_utilisateur=? WHERE id_utilisateur=?;",pseudo,id); | ||
| 189 | stat.executeUpdate(); | ||
| 190 | |||
| 191 | } catch (SQLException e) { | ||
| 192 | // TODO: handle exception | ||
| 193 | System.err.println(e.getMessage()); | ||
| 194 | } | ||
| 195 | } | ||
| 196 | public void insertListe(ArmeeListe armee,User session) { | ||
| 197 | try { | ||
| 198 | int id; | ||
| 199 | ArrayList<String> rendu = new ArrayList<String>(); | ||
| 200 | String requete = "INSERT INTO liste VALUES(DEFAULT,?,?,?,?);"; | ||
| 201 | stat = this.getPreparedStatement(requete); | ||
| 202 | stat.setString(1, armee.getName()); | ||
| 203 | stat.setString(2, armee.getDescription()); | ||
| 204 | stat.setString(3, armee.getData()); | ||
| 205 | stat.setInt(4, session.getId()); | ||
| 206 | stat.executeUpdate(); | ||
| 207 | |||
| 208 | requete = "SELECT id_liste FROM liste WHERE nom_liste = ?;"; | ||
| 209 | |||
| 210 | rendu = this.select(requete,armee.getName()); | ||
| 211 | |||
| 212 | id = Integer.parseInt(rendu.getFirst()); | ||
| 213 | requete = "INSERT INTO contenir VALUES(?,?);"; | ||
| 214 | |||
| 215 | for(Unit unit : armee.getUnits()) { | ||
| 216 | |||
| 217 | |||
| 218 | stat = this.getPreparedStatement(requete); | ||
| 219 | stat.setInt(1, unit.getId()); | ||
| 220 | stat.setInt(2, id); | ||
| 221 | stat.executeUpdate(); | ||
| 222 | } | ||
| 223 | |||
| 224 | } catch (SQLException e) { | ||
| 225 | // TODO: handle exception | ||
| 226 | } | ||
| 227 | } | ||
| 228 | |||
| 229 | |||
| 230 | public void updateMp(String mdp,int id) { | ||
| 231 | try { | ||
| 232 | //stat = this.getPreparedStatement("UPDATE `utilisateur` SET mdp_utilisateur=? WHERE id_utilisateur=?;",mdp.hashCode(),id); | ||
| 233 | stat = this.getPreparedStatement("UPDATE `utilisateur` SET mdp_utilisateur=? WHERE id_utilisateur=?;",mdp.hashCode(),id); | ||
| 234 | stat.executeUpdate(); | ||
| 235 | |||
| 236 | } catch (SQLException e) { | ||
| 237 | // TODO: handle exception | ||
| 238 | System.err.println(e.getMessage()); | ||
| 239 | } | ||
| 240 | } | ||
| 241 | |||
| 242 | public int UtilisateurID(String nom, String mdp) { | ||
| 243 | try { | ||
| 244 | stat = this.getPreparedStatement("SELECT id_utilisateur FROM utilisateur WHERE nom_utilisateur=? AND mdp_utilisateur = ?;", | ||
| 245 | nom, mdp); | ||
| 246 | |||
| 247 | ResultSet rs = stat.executeQuery(); | ||
| 248 | rs.next(); | ||
| 249 | int id = rs.getInt("id_utilisateur"); | ||
| 250 | |||
| 251 | return id; | ||
| 252 | |||
| 253 | } catch (SQLException e) { | ||
| 254 | // TODO: handle exception | ||
| 255 | System.err.println(e.getMessage()); | ||
| 256 | |||
| 257 | return 0; | ||
| 258 | } | ||
| 259 | } | ||
| 260 | public String UtilisateurRole(String nom, String mdp) { | ||
| 261 | String role = "null"; | ||
| 262 | try { | ||
| 263 | |||
| 264 | stat = this.getPreparedStatement("SELECT role_utilisateur FROM utilisateur WHERE nom_utilisateur=? AND mdp_utilisateur = ?;", | ||
| 265 | nom, mdp); | ||
| 266 | |||
| 267 | ResultSet rs = stat.executeQuery(); | ||
| 268 | rs.next(); | ||
| 269 | role = rs.getString("role_utilisateur"); | ||
| 270 | |||
| 271 | return role; | ||
| 272 | |||
| 273 | } catch (SQLException e) { | ||
| 274 | // TODO: handle exception | ||
| 275 | System.err.println(e.getMessage()); | ||
| 276 | |||
| 277 | |||
| 278 | } | ||
| 279 | return role; | ||
| 280 | } | ||
| 281 | |||
| 282 | public String UtilisateurMdp(int id) { | ||
| 283 | String mdp = "test null"; | ||
| 284 | try { | ||
| 285 | stat = this.getPreparedStatement("SELECT mdp_utilisateur FROM utilisateur WHERE id_utilisateur=?;", | ||
| 286 | id); | ||
| 287 | |||
| 288 | ResultSet rs = stat.executeQuery(); | ||
| 289 | rs.next(); | ||
| 290 | mdp = rs.getString("mdp_utilisateur"); | ||
| 291 | |||
| 292 | return mdp; | ||
| 293 | |||
| 294 | } catch (SQLException e) { | ||
| 295 | // TODO: handle exception | ||
| 296 | System.err.println(e.getMessage()); | ||
| 297 | |||
| 298 | |||
| 299 | } | ||
| 300 | return mdp; | ||
| 301 | } | ||
| 302 | |||
| 303 | |||
| 304 | public void ajouter(Arme a) { | ||
| 305 | try { | ||
| 306 | stat.executeUpdate("INSERT INTO arme (id,prenom,login,password,statut,age) VALUES (NULL,"); | ||
| 307 | } catch (SQLException e) { | ||
| 308 | // TODO Auto-generated catch block | ||
| 309 | e.printStackTrace(); | ||
| 310 | } | ||
| 311 | } | ||
| 312 | |||
| 313 | public void supprimer(Arme a) { | ||
| 314 | try { | ||
| 315 | stat.executeUpdate("DELETE FROM acces WHERE login =''"); | ||
| 316 | } catch (SQLException e) { | ||
| 317 | // TODO Auto-generated catch block | ||
| 318 | e.printStackTrace(); | ||
| 319 | } | ||
| 320 | |||
| 321 | } | ||
| 322 | } | ||
diff --git a/src/main/java/controlleur/Connexion.java b/src/main/java/controlleur/Connexion.java new file mode 100644 index 0000000..f8c6b4f --- /dev/null +++ b/src/main/java/controlleur/Connexion.java | |||
| @@ -0,0 +1,65 @@ | |||
| 1 | package controlleur; | ||
| 2 | |||
| 3 | import java.sql.SQLException; | ||
| 4 | import java.util.ArrayList; | ||
| 5 | |||
| 6 | import javafx.stage.Stage; | ||
| 7 | import modele.Evenement; | ||
| 8 | import modele.User; | ||
| 9 | import vue.AfficheAccueil; | ||
| 10 | import vue.AfficheConnexionFailed; | ||
| 11 | |||
| 12 | public class Connexion { | ||
| 13 | public static EvenementController eventC ; | ||
| 14 | public static Evenement event ; | ||
| 15 | public static void verif(String login, String mdp,Stage primaryStage) { | ||
| 16 | |||
| 17 | login = login.trim(); | ||
| 18 | mdp = Integer.toString(mdp.hashCode()); | ||
| 19 | BDD conec = new BDD(); | ||
| 20 | |||
| 21 | eventC = new EvenementController(); | ||
| 22 | event = new Evenement(eventC.getNom_event().get(0), | ||
| 23 | eventC.getNom_image().get(0), | ||
| 24 | eventC.getDesc_event().get(0), | ||
| 25 | eventC.getDate_event().get(0)); | ||
| 26 | System.out.println(eventC.getNom_image().get(0)); | ||
| 27 | ArrayList<Object> rendu = conec.selectUtilisateur(login, mdp); | ||
| 28 | int id = conec.UtilisateurID(login, mdp); | ||
| 29 | String role = conec.UtilisateurRole(login, mdp); | ||
| 30 | //System.out.println(role); | ||
| 31 | conec.close(); | ||
| 32 | |||
| 33 | try { | ||
| 34 | if (login.equals(rendu.get(0))) { | ||
| 35 | User session = new User(login,id,role); | ||
| 36 | |||
| 37 | //primaryStage.close(); | ||
| 38 | AfficheAccueil.affiche(primaryStage,session); | ||
| 39 | } | ||
| 40 | else { | ||
| 41 | System.out.println(rendu); | ||
| 42 | } | ||
| 43 | } | ||
| 44 | catch(Exception e) { | ||
| 45 | AfficheConnexionFailed.affiche(primaryStage); | ||
| 46 | } | ||
| 47 | } | ||
| 48 | |||
| 49 | public static void updatePseudo(String pseudo,int id) throws SQLException { | ||
| 50 | BDD conec = new BDD(); | ||
| 51 | conec.updateUtilisateur(pseudo,id); | ||
| 52 | conec.close(); | ||
| 53 | } | ||
| 54 | public static void updateMdp(String mdp,int id) throws SQLException { | ||
| 55 | BDD conec = new BDD(); | ||
| 56 | conec.updateMp(mdp,id); | ||
| 57 | conec.close(); | ||
| 58 | } | ||
| 59 | public static String selectMdp(int id) throws SQLException { | ||
| 60 | BDD conec = new BDD(); | ||
| 61 | String mdp =conec.UtilisateurMdp(id); | ||
| 62 | conec.close(); | ||
| 63 | return mdp; | ||
| 64 | } | ||
| 65 | } \ No newline at end of file | ||
diff --git a/src/main/java/controlleur/ControllerAdmin.java b/src/main/java/controlleur/ControllerAdmin.java new file mode 100644 index 0000000..a12f01c --- /dev/null +++ b/src/main/java/controlleur/ControllerAdmin.java | |||
| @@ -0,0 +1,119 @@ | |||
| 1 | package controlleur; | ||
| 2 | |||
| 3 | import java.io.File; | ||
| 4 | import java.io.IOException; | ||
| 5 | import java.nio.file.Files; | ||
| 6 | import java.sql.PreparedStatement; | ||
| 7 | import java.sql.ResultSet; | ||
| 8 | import java.sql.SQLException; | ||
| 9 | import java.time.LocalDate; | ||
| 10 | import java.util.ArrayList; | ||
| 11 | import java.util.Date; | ||
| 12 | import java.util.List; | ||
| 13 | |||
| 14 | import javafx.geometry.Pos; | ||
| 15 | import javafx.scene.control.Alert; | ||
| 16 | import javafx.scene.control.Button; | ||
| 17 | import javafx.scene.control.Label; | ||
| 18 | import javafx.scene.image.Image; | ||
| 19 | import javafx.scene.image.ImageView; | ||
| 20 | import javafx.scene.layout.HBox; | ||
| 21 | import javafx.scene.layout.VBox; | ||
| 22 | import javafx.scene.text.Text; | ||
| 23 | import javafx.stage.FileChooser; | ||
| 24 | import javafx.stage.Stage; | ||
| 25 | import vue.AfficheAccueil; | ||
| 26 | import vue.AfficheAdmin; | ||
| 27 | import vue.AfficheConnexionFailed; | ||
| 28 | import modele.Evenement; | ||
| 29 | import modele.User; | ||
| 30 | |||
| 31 | public class ControllerAdmin { | ||
| 32 | private static String destinationDir; | ||
| 33 | private static File destinationFile ; | ||
| 34 | private static File file; | ||
| 35 | |||
| 36 | public static void parcourir(Stage primaryStage, ImageView imageView) { | ||
| 37 | FileChooser fileChooser = new FileChooser(); | ||
| 38 | fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Fichiers Images", "*.png", "*.jpg")); | ||
| 39 | |||
| 40 | // Ouvrir le file chooser et obtenir le fichier sélectionné | ||
| 41 | file = fileChooser.showOpenDialog(primaryStage); | ||
| 42 | |||
| 43 | boolean nomFich = true; | ||
| 44 | |||
| 45 | if (file != null) { | ||
| 46 | |||
| 47 | for (int i = 0 ; i < Connexion.eventC.getNbrEvt();i++) { | ||
| 48 | |||
| 49 | if (file.getName().equals(Connexion.eventC.getNom_image().get(i))) { | ||
| 50 | |||
| 51 | Alert alert = new Alert(Alert.AlertType.ERROR); | ||
| 52 | alert.setTitle("StatHammer : Nom d'image déjà existant"); | ||
| 53 | alert.setHeaderText(null); | ||
| 54 | alert.setContentText("Le nom de l'image est déjà prise."); | ||
| 55 | alert.showAndWait(); | ||
| 56 | nomFich = false; | ||
| 57 | |||
| 58 | } | ||
| 59 | } | ||
| 60 | if (nomFich) { | ||
| 61 | System.out.println("Fichier sélectionné : " + file.getName()); | ||
| 62 | System.out.println("Chemin du fichier : " + file.getAbsolutePath()); | ||
| 63 | |||
| 64 | // Créer une nouvelle image à partir du chemin absolu du fichier | ||
| 65 | Image image = new Image("file:" + file.getAbsolutePath()); | ||
| 66 | |||
| 67 | // Définir l'image dans l'ImageView | ||
| 68 | imageView.setImage(image); | ||
| 69 | |||
| 70 | // Destination pour sauvegarder l'image | ||
| 71 | destinationDir = "src\\images"; | ||
| 72 | File destinationFolder = new File(destinationDir); | ||
| 73 | |||
| 74 | // Créez le répertoire s'il n'existe pas | ||
| 75 | if (!destinationFolder.exists()) { | ||
| 76 | destinationFolder.mkdirs(); | ||
| 77 | } | ||
| 78 | |||
| 79 | File nouveauNom = new File(file.getName()); | ||
| 80 | destinationFile = new File(destinationFolder, nouveauNom.getName()); | ||
| 81 | |||
| 82 | } | ||
| 83 | |||
| 84 | } | ||
| 85 | } | ||
| 86 | |||
| 87 | |||
| 88 | //méthode "valider" | ||
| 89 | public static VBox valider(String nom_evt, String nom_img, String desc, String date) { | ||
| 90 | Evenement evt = new Evenement(nom_evt, nom_img, desc, date); | ||
| 91 | VBox event = new VBox(); | ||
| 92 | event.setPrefHeight(50); | ||
| 93 | event.setAlignment(Pos.CENTER); | ||
| 94 | try { | ||
| 95 | // Copier le fichier dans le dossier de destination | ||
| 96 | Files.copy(file.toPath(), destinationFile.toPath()); | ||
| 97 | System.out.println("Fichier enregistré à : " + destinationFile.getAbsolutePath()); | ||
| 98 | EvenementController.insererEvenement(evt); | ||
| 99 | event = EvenementController.EvenementVBox(); | ||
| 100 | |||
| 101 | } catch (IOException ioException) { | ||
| 102 | System.out.println("Probleme sur Valider"); | ||
| 103 | ioException.printStackTrace(); | ||
| 104 | } | ||
| 105 | return event; | ||
| 106 | } | ||
| 107 | |||
| 108 | public static File getFile() { | ||
| 109 | return file; | ||
| 110 | } | ||
| 111 | |||
| 112 | |||
| 113 | public static String getDestinationDir() { | ||
| 114 | return destinationDir; | ||
| 115 | } | ||
| 116 | |||
| 117 | |||
| 118 | |||
| 119 | } \ No newline at end of file | ||
diff --git a/src/main/java/controlleur/ControllerTopMenu.java b/src/main/java/controlleur/ControllerTopMenu.java new file mode 100644 index 0000000..baef8df --- /dev/null +++ b/src/main/java/controlleur/ControllerTopMenu.java | |||
| @@ -0,0 +1,58 @@ | |||
| 1 | package controlleur; | ||
| 2 | |||
| 3 | import application.Battle; | ||
| 4 | import javafx.stage.Stage; | ||
| 5 | import modele.Evenement; | ||
| 6 | import modele.User; | ||
| 7 | import vue.AfficheAccueil; | ||
| 8 | import vue.AfficheAdmin; | ||
| 9 | import vue.AfficheConnexion; | ||
| 10 | import vue.AfficheCreerListe; | ||
| 11 | import vue.AfficheGestionCompte; | ||
| 12 | import vue.GestionListe.AfficheGestionListe; | ||
| 13 | import vue.simulation.AfficheSimulation; | ||
| 14 | |||
| 15 | public class ControllerTopMenu { | ||
| 16 | static BDD db = new BDD(); | ||
| 17 | |||
| 18 | public static void go_accueil(Stage primaryStage,User session) { | ||
| 19 | //primaryStage.close(); pour fermer stage | ||
| 20 | AfficheAccueil.affiche(primaryStage,session); | ||
| 21 | } | ||
| 22 | public static void go_gestion_compte(Stage primaryStage,User session) { | ||
| 23 | AfficheGestionCompte.affiche(primaryStage,session); | ||
| 24 | } | ||
| 25 | public static void go_gestion_listes(Stage primaryStage,User session) { | ||
| 26 | |||
| 27 | // db.getArmyLists(session); | ||
| 28 | AfficheGestionListe.affiche(primaryStage, session); | ||
| 29 | |||
| 30 | // | ||
| 31 | |||
| 32 | } | ||
| 33 | public static void go_deco(Stage primaryStage, User session) { | ||
| 34 | AfficheSimulation.cleanWeaponsAtitudesMenu(); | ||
| 35 | Battle.clean(); // VRAIMENT ?! | ||
| 36 | session = null; | ||
| 37 | AfficheConnexion.affiche(primaryStage); | ||
| 38 | } | ||
| 39 | public static void go_simulation(Stage primaryStage, User session){ | ||
| 40 | |||
| 41 | |||
| 42 | Instanciation.getArmyLists(session); | ||
| 43 | |||
| 44 | AfficheSimulation.affiche(primaryStage, session); | ||
| 45 | } | ||
| 46 | public static void go_admin(Stage primaryStage,User session) { | ||
| 47 | AfficheAdmin.affiche(primaryStage,session); | ||
| 48 | } | ||
| 49 | public static void go_creer_liste(Stage primaryStage, User session) { | ||
| 50 | AfficheCreerListe.afficheCreerListe(primaryStage, session); | ||
| 51 | } | ||
| 52 | // public static void go_gestionliste(Stage primaryStage,User session) { | ||
| 53 | // AfficheGestionListe.affiche(primaryStage,session); | ||
| 54 | // } | ||
| 55 | } | ||
| 56 | |||
| 57 | |||
| 58 | |||
diff --git a/src/main/java/controlleur/ControlleurSimu.java b/src/main/java/controlleur/ControlleurSimu.java new file mode 100644 index 0000000..a349036 --- /dev/null +++ b/src/main/java/controlleur/ControlleurSimu.java | |||
| @@ -0,0 +1,218 @@ | |||
| 1 | package controlleur; | ||
| 2 | |||
| 3 | import java.util.ArrayList; | ||
| 4 | import java.util.HashMap; | ||
| 5 | import application.Battle; | ||
| 6 | import javafx.scene.control.Button; | ||
| 7 | import javafx.scene.control.ChoiceBox; | ||
| 8 | import javafx.scene.image.Image; | ||
| 9 | import javafx.scene.image.ImageView; | ||
| 10 | import javafx.scene.layout.FlowPane; | ||
| 11 | import javafx.scene.layout.HBox; | ||
| 12 | import javafx.scene.layout.Pane; | ||
| 13 | import modele.Aptitude; | ||
| 14 | import modele.Arme; | ||
| 15 | import modele.ArmeeListe; | ||
| 16 | import modele.Calcul; | ||
| 17 | import modele.Figurine; | ||
| 18 | import modele.Unit; | ||
| 19 | import vue.simulation.AfficheSimulation; | ||
| 20 | import vue.simulation.SimAptAndWeaponsVBox; | ||
| 21 | import vue.simulation.SimFigurinesVBox; | ||
| 22 | import vue.simulation.SimHistogramme; | ||
| 23 | import vue.simulation.SimUnitsVBox; | ||
| 24 | |||
| 25 | public class ControlleurSimu | ||
| 26 | { | ||
| 27 | // déroulement des unités d'une liste (appui sur lists_drop_down.get(i) dans AfficheSimulation) | ||
| 28 | public static void selectAList(int num_list, ArrayList<ArmeeListe> lists, String choice) | ||
| 29 | { | ||
| 30 | // choix de la liste | ||
| 31 | for(ArmeeListe one_list : lists) | ||
| 32 | { | ||
| 33 | if(one_list.getName().equals(choice)) { | ||
| 34 | // "copie profonde" d'une liste | ||
| 35 | ArmeeListe list = new ArmeeListe(one_list.getName(), one_list.getDescription(), one_list.getData()); | ||
| 36 | Battle.setSelectedList(num_list, list); | ||
| 37 | break; // choix unique | ||
| 38 | } | ||
| 39 | } | ||
| 40 | |||
| 41 | // obtenir les unités, l'armée, les figurines, armes et aptitudes | ||
| 42 | Instanciation.getUnitsOfAList(Battle.getSelectedList(num_list)); | ||
| 43 | |||
| 44 | Battle.setArmy(num_list, Battle.getSelectedList(num_list).getUnits().get(0).getArmee()); | ||
| 45 | |||
| 46 | } | ||
| 47 | |||
| 48 | // déroulement des figurines d'une unité (appui sur buttons.get(i) dans SimUnitsVBox) | ||
| 49 | public static void PullDownUnits(int num_list, HBox dropdown_menu_box, SimUnitsVBox list_box) { | ||
| 50 | ArmeeListe list = Battle.getSelectedList(num_list); | ||
| 51 | |||
| 52 | // noms des unités | ||
| 53 | String[] unit_names = new String[list.getUnits().size()]; | ||
| 54 | for(int i = 0; i < list.getUnits().size(); i++) { | ||
| 55 | unit_names[i] = list.getUnits().get(i).getName(); | ||
| 56 | } | ||
| 57 | |||
| 58 | // supprimer l'ancien logo | ||
| 59 | if(dropdown_menu_box.getChildren().size() == 2){ | ||
| 60 | dropdown_menu_box.getChildren().remove(1); | ||
| 61 | } | ||
| 62 | |||
| 63 | // logo de faction | ||
| 64 | Image logo_faction = null; | ||
| 65 | if(Battle.getArmy(num_list) != null) // possibilité d'une liste vide | ||
| 66 | { | ||
| 67 | String file_name = Battle.getArmy(num_list).getLogo(); | ||
| 68 | logo_faction = new Image("/images/armees/" + file_name); | ||
| 69 | } | ||
| 70 | ImageView logo_box = new ImageView(); | ||
| 71 | |||
| 72 | logo_box.setPreserveRatio(true); | ||
| 73 | logo_box.fitHeightProperty().bind(dropdown_menu_box.heightProperty()); | ||
| 74 | logo_box.setImage(logo_faction); | ||
| 75 | dropdown_menu_box.getChildren().add(logo_box); | ||
| 76 | |||
| 77 | // effacer la zone armes et aptitudes | ||
| 78 | AfficheSimulation.getWeaponsAtitudesMenu().setStyle("-fx-border-width: 0;"); | ||
| 79 | AfficheSimulation.getWeaponsAtitudesMenu().getChildren().clear(); | ||
| 80 | |||
| 81 | // effacer et recréer les unités | ||
| 82 | list_box.getButtons().clear(); | ||
| 83 | list_box.getFigBoxes().clear(); | ||
| 84 | list_box.getChildren().clear(); | ||
| 85 | list_box.setList(num_list); | ||
| 86 | } | ||
| 87 | |||
| 88 | // déroulement des figurines d'une unité (appui sur buttons.get(i) dans SimUnitsVBox) | ||
| 89 | public static void selectAnUnit(SimUnitsVBox lists, int col, int j) | ||
| 90 | { | ||
| 91 | ArrayList<Button> buttons = lists.getButtons(); | ||
| 92 | SimFigurinesVBox old_fig_boxes = null; | ||
| 93 | SimFigurinesVBox new_fig_boxes = lists.getFigBoxes().get(j); | ||
| 94 | |||
| 95 | // il y a déjà une unité sélectionnée | ||
| 96 | if(Battle.getSelectedUnitIndex(col) > -1) | ||
| 97 | { | ||
| 98 | buttons.get(Battle.getSelectedUnitIndex(col)).setStyle("-fx-border-width: 0;");// retirer bordure unité sélectionnée | ||
| 99 | AfficheSimulation.getWeaponsAtitudesMenu().getChildren().clear(); // supprimer fenêtre combat si existe | ||
| 100 | |||
| 101 | // bouton même unité => ferme | ||
| 102 | if(Battle.getSelectedUnitIndex(col) == j) | ||
| 103 | { | ||
| 104 | new_fig_boxes.getChildren().clear(); | ||
| 105 | Battle.setSelectedUnit(col, -1); | ||
| 106 | } | ||
| 107 | // bouton autre unité | ||
| 108 | else | ||
| 109 | { | ||
| 110 | old_fig_boxes = lists.getFigBoxes().get(Battle.getSelectedUnitIndex(col)); | ||
| 111 | if(old_fig_boxes != null) { | ||
| 112 | old_fig_boxes.getChildren().clear(); // supprimer ancienne zone de figurines | ||
| 113 | } | ||
| 114 | Battle.setSelectedUnit(col, j); | ||
| 115 | buttons.get(j).setStyle("-fx-border-width: 2; -fx-border-color: yellow; -fx-border-radius: 2;"); // bordure unité sélectionnée | ||
| 116 | new_fig_boxes.setFigurines(); // on ouvre | ||
| 117 | } | ||
| 118 | } | ||
| 119 | // pas d'unité sélectionnée => on ouvre | ||
| 120 | else | ||
| 121 | { | ||
| 122 | Battle.setSelectedUnit(col, j); | ||
| 123 | buttons.get(j).setStyle("-fx-border-width: 2; -fx-border-color: yellow; -fx-border-radius: 2;"); // bordure unité sélectionnée | ||
| 124 | new_fig_boxes.setFigurines(); | ||
| 125 | } | ||
| 126 | } | ||
| 127 | |||
| 128 | // slider des PV des figurines | ||
| 129 | public static void hpUpdate(int hp, Figurine fig, ImageView one_image_box) { | ||
| 130 | int old_hp = fig.getHP(); | ||
| 131 | fig.setHP(hp); | ||
| 132 | |||
| 133 | Image one_image; | ||
| 134 | if(old_hp == 0 && fig.getHP() > 0) { | ||
| 135 | one_image = new Image("/images/android-fill.png"); | ||
| 136 | one_image_box.setImage(one_image); | ||
| 137 | } | ||
| 138 | else if(old_hp > 0 && fig.getHP() == 0){ // utile? | ||
| 139 | one_image = new Image("/images/android-line.png"); | ||
| 140 | one_image_box.setImage(one_image); | ||
| 141 | } | ||
| 142 | } | ||
| 143 | |||
| 144 | // afficher la zone des armes et aptitudes | ||
| 145 | public static void makeWeaponsAndAptitudeZone(ArrayList<Figurine> fig_group, SimAptAndWeaponsVBox weapons_aptitudes_menu) { | ||
| 146 | ArrayList<Arme> weapon_list = fig_group.get(0).getArmes(); | ||
| 147 | ArrayList<Aptitude> aptitude_list = fig_group.get(0).getAptitudes(); | ||
| 148 | |||
| 149 | weapons_aptitudes_menu.setArmes(weapon_list); | ||
| 150 | weapons_aptitudes_menu.setAptitudes(aptitude_list); | ||
| 151 | weapons_aptitudes_menu.setAptAndWeapons(fig_group); // contenu de la vue | ||
| 152 | AfficheSimulation.refreshWeaponAndAptitude(weapons_aptitudes_menu); // insersion dans la vue principale | ||
| 153 | } | ||
| 154 | |||
| 155 | public static void selectAWeapon(SimAptAndWeaponsVBox view, String weapon_name, ArrayList<Figurine> fig_group, FlowPane weapon_stats) { | ||
| 156 | Arme weapon = fig_group.get(0).getWeaponByName(weapon_name); // recherche dans les armes de la 1ère figurine | ||
| 157 | // on équipe le groupe | ||
| 158 | for(Figurine fig : fig_group) { | ||
| 159 | fig.setWeapon(weapon); | ||
| 160 | } | ||
| 161 | weapon_stats.getChildren().clear(); | ||
| 162 | view.setWeaponStats(weapon, weapon_stats); | ||
| 163 | } | ||
| 164 | |||
| 165 | public static void AliveFigsChoice(int col, int value, String group_name) { | ||
| 166 | // on considère que ceux qui n'attaquent pas sont morts | ||
| 167 | ArrayList<Figurine> fig_group = Battle.getSelectedUnit(col).getIdenticalFigsGroups().get(group_name); | ||
| 168 | for(int i = 0; i < value; i++) { | ||
| 169 | fig_group.get(i).setHP(fig_group.get(i).getHPMax()); | ||
| 170 | } | ||
| 171 | for(int i = value; i < fig_group.size(); i++) { | ||
| 172 | fig_group.get(i).setHP(0); | ||
| 173 | } | ||
| 174 | |||
| 175 | System.out.println("weaponNumberChoice => trouver un moyen de modifier instantanément les images"); | ||
| 176 | } | ||
| 177 | |||
| 178 | public static void checkOrUncheckAnAptitude(boolean isSelected, String aptitude_name, ArrayList<Figurine> fig_group) { | ||
| 179 | for(Aptitude apti : fig_group.get(0).getAptitudes()) // recherche dans les aptitudes de la 1ère figurine | ||
| 180 | { | ||
| 181 | if(apti.getName() == aptitude_name) { | ||
| 182 | for(Figurine fig : fig_group) | ||
| 183 | { | ||
| 184 | HashMap<String, Aptitude> selectedAptitudes = fig.getSelectedAptitudes(); | ||
| 185 | if(isSelected) { | ||
| 186 | selectedAptitudes.put(aptitude_name, apti); | ||
| 187 | } | ||
| 188 | else { | ||
| 189 | if(selectedAptitudes.containsKey(aptitude_name)) { | ||
| 190 | selectedAptitudes.remove(aptitude_name); | ||
| 191 | } | ||
| 192 | } | ||
| 193 | } | ||
| 194 | break; // on ne gère pas le cas où deux aptitudes ont le même nom | ||
| 195 | } | ||
| 196 | } | ||
| 197 | } | ||
| 198 | |||
| 199 | // histogramme | ||
| 200 | public static void afficheSimu(Pane p,Unit u1,Unit u2) { | ||
| 201 | p.getChildren().clear(); | ||
| 202 | Calcul c =Calcul.bataille(u1, u2); | ||
| 203 | |||
| 204 | SimHistogramme.setHist(c.getTabdegat1(), c.getTabmort1(), c.getDegat_moyen1(), c.getMort_moyen1(),p); | ||
| 205 | } | ||
| 206 | |||
| 207 | public static void reverseArmies(ArrayList<ChoiceBox<String>> lists_drop_down) { | ||
| 208 | Battle.reverseArmies(); | ||
| 209 | AfficheSimulation.inversion = true; | ||
| 210 | for(int i = 0; i < 2; i++) | ||
| 211 | { | ||
| 212 | // déclenche la sélection d'une liste dans le menu déroulant, mais avec du code | ||
| 213 | lists_drop_down.get(i).getSelectionModel().select(Battle.getSelectedList(i + 1).getName()); | ||
| 214 | Battle.setSelectedUnit(i + 1, -1); // plus d'unité sélectionnée | ||
| 215 | } | ||
| 216 | AfficheSimulation.inversion = false; | ||
| 217 | } | ||
| 218 | } | ||
diff --git a/src/main/java/controlleur/CreationCompte.java b/src/main/java/controlleur/CreationCompte.java new file mode 100644 index 0000000..0cd78ba --- /dev/null +++ b/src/main/java/controlleur/CreationCompte.java | |||
| @@ -0,0 +1,38 @@ | |||
| 1 | package controlleur; | ||
| 2 | |||
| 3 | import java.util.ArrayList; | ||
| 4 | |||
| 5 | import javafx.stage.Stage; | ||
| 6 | import modele.User; | ||
| 7 | import vue.AfficheAccueil; | ||
| 8 | import vue.AfficheConnexion; | ||
| 9 | import vue.AfficheConnexionFailed; | ||
| 10 | |||
| 11 | public class CreationCompte { | ||
| 12 | public static void verif(String Email, String Pseudo, String Mdp, Stage primaryStage) { | ||
| 13 | |||
| 14 | Email = Email.trim(); | ||
| 15 | Pseudo = Pseudo.trim(); | ||
| 16 | Mdp = Mdp.trim(); | ||
| 17 | BDD conec = new BDD(); | ||
| 18 | ArrayList<String> crea = conec.creerUtilisateur(Email, Pseudo, Mdp); | ||
| 19 | int id = conec.UtilisateurID(Pseudo, Mdp); | ||
| 20 | String role = conec.UtilisateurRole(Pseudo, Mdp); | ||
| 21 | User session = new User(Pseudo,id,role); | ||
| 22 | conec.close(); | ||
| 23 | if (!crea.isEmpty() && Email.equals(crea.getFirst().trim())) { | ||
| 24 | |||
| 25 | System.out.println("Compté créé" + crea); | ||
| 26 | primaryStage.close(); | ||
| 27 | AfficheAccueil.affiche(primaryStage, session); | ||
| 28 | } else { | ||
| 29 | System.out.println("échec de la création de compte" + crea); | ||
| 30 | AfficheConnexionFailed.affiche(primaryStage); | ||
| 31 | } | ||
| 32 | } | ||
| 33 | |||
| 34 | public static void getBack(Stage primaryStage) { | ||
| 35 | AfficheConnexion.affiche(primaryStage); | ||
| 36 | } | ||
| 37 | |||
| 38 | } | ||
diff --git a/src/main/java/controlleur/EvenementController.java b/src/main/java/controlleur/EvenementController.java new file mode 100644 index 0000000..ad21353 --- /dev/null +++ b/src/main/java/controlleur/EvenementController.java | |||
| @@ -0,0 +1,267 @@ | |||
| 1 | package controlleur; | ||
| 2 | |||
| 3 | import java.io.IOException; | ||
| 4 | import java.nio.file.Files; | ||
| 5 | import java.nio.file.Paths; | ||
| 6 | import java.sql.PreparedStatement; | ||
| 7 | import java.sql.ResultSet; | ||
| 8 | import java.sql.SQLException; | ||
| 9 | import java.util.ArrayList; | ||
| 10 | import java.io.IOException; | ||
| 11 | import java.nio.file.Files; | ||
| 12 | import java.nio.file.Path; | ||
| 13 | import java.nio.file.Paths; | ||
| 14 | import javafx.geometry.Pos; | ||
| 15 | import javafx.scene.control.Button; | ||
| 16 | import javafx.scene.control.Label; | ||
| 17 | import javafx.scene.layout.HBox; | ||
| 18 | import javafx.scene.layout.VBox; | ||
| 19 | import modele.Evenement; | ||
| 20 | import vue.AfficheAdmin; | ||
| 21 | |||
| 22 | |||
| 23 | public class EvenementController { | ||
| 24 | private static int nbrEvt; | ||
| 25 | |||
| 26 | public void setNbrEvt(int nbrEvt) { | ||
| 27 | EvenementController.nbrEvt = nbrEvt; | ||
| 28 | } | ||
| 29 | |||
| 30 | private static ArrayList<String> nom_event; | ||
| 31 | private static ArrayList<String> nom_image; | ||
| 32 | private static ArrayList<String> desc_event; | ||
| 33 | private static ArrayList<String> date_event; | ||
| 34 | |||
| 35 | |||
| 36 | public ArrayList<String> getNom_event() { | ||
| 37 | return nom_event; | ||
| 38 | } | ||
| 39 | |||
| 40 | public ArrayList<String> getNom_image() { | ||
| 41 | return nom_image; | ||
| 42 | } | ||
| 43 | |||
| 44 | public ArrayList<String> getDesc_event() { | ||
| 45 | return desc_event; | ||
| 46 | } | ||
| 47 | |||
| 48 | public ArrayList<String> getDate_event() { | ||
| 49 | return date_event; | ||
| 50 | } | ||
| 51 | |||
| 52 | //EvenementController permet de recenser tous les évènements sous forme d'ArrayList<String> | ||
| 53 | //Le rôle de ce constructeur a changé pas mal de fois, d'où un nom peu cohérent... | ||
| 54 | public EvenementController() { | ||
| 55 | |||
| 56 | nbrEvt = 0; | ||
| 57 | |||
| 58 | nom_event= new ArrayList<String>(); | ||
| 59 | nom_image= new ArrayList<String>(); | ||
| 60 | desc_event= new ArrayList<String>(); | ||
| 61 | date_event= new ArrayList<String>(); | ||
| 62 | |||
| 63 | |||
| 64 | // Créer une instance de BDD | ||
| 65 | BDD bdd = new BDD(); | ||
| 66 | |||
| 67 | try { | ||
| 68 | // Requête SQL | ||
| 69 | String sql = "SELECT * FROM evenement"; // Requête | ||
| 70 | PreparedStatement ps = bdd.getPreparedStatement(sql); | ||
| 71 | |||
| 72 | // Exécution de la requête | ||
| 73 | ResultSet rs = ps.executeQuery(); | ||
| 74 | |||
| 75 | |||
| 76 | // Traiter les résultats | ||
| 77 | while (rs.next()) { | ||
| 78 | int i=0; | ||
| 79 | nbrEvt = getNbrEvt() + 1; | ||
| 80 | |||
| 81 | String nom_evt = rs.getString("nom_evenement"); | ||
| 82 | String nom_img = rs.getString("nom_image"); | ||
| 83 | String desc_evt = rs.getString("description_evenement"); | ||
| 84 | String date_evt = rs.getString("date_evenement"); | ||
| 85 | |||
| 86 | nom_event.add(nom_evt); | ||
| 87 | nom_image.add(nom_img); | ||
| 88 | desc_event.add(desc_evt); | ||
| 89 | date_event.add(date_evt); | ||
| 90 | |||
| 91 | // Afficher les résultats ou les ajouter à une liste/structure de données | ||
| 92 | System.out.println("Image : " + nom_img); | ||
| 93 | System.out.println("Événement : " + nom_evt); | ||
| 94 | System.out.println("Description : " + desc_evt); | ||
| 95 | System.out.println("Date : " + date_evt); | ||
| 96 | i++; | ||
| 97 | } | ||
| 98 | } catch (SQLException e) { | ||
| 99 | System.err.println("Erreur lors de l'accès à la base de données : " + e.getMessage()); | ||
| 100 | } finally { | ||
| 101 | // Être sûr de fermer la connexion à la base de données | ||
| 102 | bdd.close(); | ||
| 103 | } | ||
| 104 | } | ||
| 105 | |||
| 106 | //Méthode pour insérer un évènement dans la BDD ainsi que d'ajouter cet évènement dans EvenementController | ||
| 107 | public static void insererEvenement(Evenement evt) { | ||
| 108 | // Créer une instance de BDD | ||
| 109 | BDD bdd = new BDD(); | ||
| 110 | try { | ||
| 111 | // Requête SQL | ||
| 112 | String sql = "INSERT INTO evenement (nom_evenement, nom_image, description_evenement, date_evenement, id_utilisateur) VALUES (?, ?, ?, ?, 3)"; // Requête | ||
| 113 | PreparedStatement ps = bdd.getPreparedStatement(sql); | ||
| 114 | |||
| 115 | // Associer les valeurs aux paramètres | ||
| 116 | ps.setString(1, evt.getNom_evenement()); | ||
| 117 | ps.setString(2, evt.getNom_image()); | ||
| 118 | ps.setString(3, evt.getDescritption_evenement()); | ||
| 119 | ps.setString(4, evt.getData_evenement()); | ||
| 120 | |||
| 121 | Connexion.eventC.getNom_event().add(evt.getNom_evenement()); | ||
| 122 | Connexion.eventC.getNom_image().add(evt.getNom_image()); | ||
| 123 | Connexion.eventC.getDesc_event().add(evt.getDescritption_evenement()); | ||
| 124 | Connexion.eventC.getDate_event().add(evt.getData_evenement()); | ||
| 125 | |||
| 126 | Connexion.eventC.setNbrEvt(Connexion.eventC.getNbrEvt()+1); | ||
| 127 | |||
| 128 | // Exécution de la requête | ||
| 129 | ps.executeUpdate(); | ||
| 130 | System.out.println("Insertion réussiedans la base données"); | ||
| 131 | |||
| 132 | } catch (SQLException e) { | ||
| 133 | System.err.println("Erreur lors de l'accès à la base de données : " + e.getMessage()); | ||
| 134 | } finally { | ||
| 135 | // Être sûr de fermer la connexion à la base de données | ||
| 136 | bdd.close(); | ||
| 137 | } | ||
| 138 | } | ||
| 139 | |||
| 140 | |||
| 141 | public static VBox EvenementVBox() { | ||
| 142 | VBox event = new VBox(); | ||
| 143 | event.setPrefHeight(50); | ||
| 144 | event.setAlignment(Pos.CENTER); | ||
| 145 | |||
| 146 | for (int i = 0; i < Connexion.eventC.getNbrEvt() ; i++) { | ||
| 147 | |||
| 148 | HBox hevent = new HBox(); | ||
| 149 | hevent.setAlignment(Pos.CENTER); | ||
| 150 | hevent.setPrefHeight(50); | ||
| 151 | |||
| 152 | String num_evt = new String(i+1+". "); | ||
| 153 | Label numLabel = new Label(num_evt); | ||
| 154 | numLabel.setPrefWidth(25); | ||
| 155 | hevent.getChildren().add(numLabel); | ||
| 156 | |||
| 157 | |||
| 158 | String nom_evt = Connexion.eventC.getNom_event().get(i); | ||
| 159 | Label nomLabel = new Label(nom_evt); | ||
| 160 | nomLabel.setPrefWidth(150); | ||
| 161 | hevent.getChildren().add(nomLabel); | ||
| 162 | |||
| 163 | String nom_img = Connexion.eventC.getNom_image().get(i); | ||
| 164 | Label imgLabel = new Label(nom_img); | ||
| 165 | imgLabel.setPrefWidth(150); | ||
| 166 | hevent.getChildren().add(imgLabel); | ||
| 167 | |||
| 168 | String desc_evt = Connexion.eventC.getDesc_event().get(i); | ||
| 169 | Label descLabel = new Label(desc_evt); | ||
| 170 | descLabel.setPrefWidth(150); | ||
| 171 | hevent.getChildren().add(descLabel); | ||
| 172 | |||
| 173 | String date_evt = Connexion.eventC.getDate_event().get(i); | ||
| 174 | Label dateLabel = new Label(date_evt); | ||
| 175 | dateLabel.setPrefWidth(100); | ||
| 176 | hevent.getChildren().add(dateLabel); | ||
| 177 | |||
| 178 | Button bouton = new Button("X"); | ||
| 179 | hevent.getChildren().add(bouton); | ||
| 180 | |||
| 181 | Evenement evt = new Evenement(nom_evt,nom_img,desc_evt,date_evt); | ||
| 182 | |||
| 183 | bouton.setOnAction(e -> { | ||
| 184 | EvenementController.supprimerEvenement(evt); | ||
| 185 | |||
| 186 | }); | ||
| 187 | |||
| 188 | event.getChildren().add(hevent); | ||
| 189 | |||
| 190 | } | ||
| 191 | |||
| 192 | return event; | ||
| 193 | } | ||
| 194 | |||
| 195 | |||
| 196 | // Méthode "supprimer" modifiée pour accepter un argument | ||
| 197 | public static void supprimerEvenement(Evenement evt) { | ||
| 198 | // Créer une instance de BDD | ||
| 199 | BDD bdd = new BDD(); | ||
| 200 | try { | ||
| 201 | // Requête SQL | ||
| 202 | String sql = "DELETE FROM evenement WHERE nom_evenement = ?"; // Requête DELETE | ||
| 203 | PreparedStatement ps = bdd.getPreparedStatement(sql); | ||
| 204 | |||
| 205 | // Associer l'ID de l'événement à supprimer | ||
| 206 | ps.setString(1, evt.getNom_evenement()); | ||
| 207 | |||
| 208 | // Exécution de la requête | ||
| 209 | int rowsAffected = ps.executeUpdate(); | ||
| 210 | if (rowsAffected > 0) { | ||
| 211 | EvenementController.effacerImage(evt.getNom_image()); | ||
| 212 | |||
| 213 | Connexion.eventC.getNom_event().remove(evt.getNom_evenement()); | ||
| 214 | Connexion.eventC.getNom_image().remove(evt.getNom_image()); | ||
| 215 | Connexion.eventC.getDesc_event().remove(evt.getDescritption_evenement()); | ||
| 216 | Connexion.eventC.getDate_event().remove(evt.getData_evenement()); | ||
| 217 | |||
| 218 | Connexion.eventC.setNbrEvt(Connexion.eventC.getNbrEvt()-1); | ||
| 219 | |||
| 220 | |||
| 221 | AfficheAdmin.setEvents(EvenementController.EvenementVBox()); | ||
| 222 | Connexion.event = new Evenement(Connexion.eventC.getNom_event().get(0), | ||
| 223 | Connexion.eventC.getNom_image().get(0), | ||
| 224 | Connexion.eventC.getDesc_event().get(0), | ||
| 225 | Connexion.eventC.getDate_event().get(0)); | ||
| 226 | System.out.println(Connexion.eventC.getNom_image().get(0)); | ||
| 227 | AfficheAdmin.affiche(AfficheAdmin.getStage(), AfficheAdmin.getSess()); | ||
| 228 | |||
| 229 | |||
| 230 | System.out.println("Suppression réussie dans la base de données"); | ||
| 231 | |||
| 232 | |||
| 233 | } else { | ||
| 234 | System.out.println("Aucun événement trouvé avec cet ID."); | ||
| 235 | } | ||
| 236 | |||
| 237 | |||
| 238 | |||
| 239 | } catch (SQLException e) { | ||
| 240 | System.err.println("Erreur lors de l'accès à la base de données : " + e.getMessage()); | ||
| 241 | } finally { | ||
| 242 | // Être sûr de fermer la connexion à la base de données | ||
| 243 | bdd.close(); | ||
| 244 | } | ||
| 245 | |||
| 246 | } | ||
| 247 | |||
| 248 | public static void effacerImage(String nom_img) { | ||
| 249 | String file_name = ControllerAdmin.getDestinationDir()+"/"+nom_img; | ||
| 250 | |||
| 251 | Path path = Paths.get(file_name); | ||
| 252 | try { | ||
| 253 | boolean result = Files.deleteIfExists(path); | ||
| 254 | if (result) { | ||
| 255 | System.out.println("Image effacée !"); | ||
| 256 | } else { | ||
| 257 | System.out.println("Oups, impossible d'effacer."); | ||
| 258 | } | ||
| 259 | } catch (IOException e) { | ||
| 260 | e.printStackTrace(); | ||
| 261 | } | ||
| 262 | } | ||
| 263 | |||
| 264 | public int getNbrEvt() { | ||
| 265 | return nbrEvt; | ||
| 266 | } | ||
| 267 | } | ||
diff --git a/src/main/java/controlleur/GestionListe.java b/src/main/java/controlleur/GestionListe.java new file mode 100644 index 0000000..bd37589 --- /dev/null +++ b/src/main/java/controlleur/GestionListe.java | |||
| @@ -0,0 +1,82 @@ | |||
| 1 | package controlleur; | ||
| 2 | |||
| 3 | import java.io.File; | ||
| 4 | import java.sql.Connection; | ||
| 5 | import java.sql.PreparedStatement; | ||
| 6 | import java.sql.ResultSet; | ||
| 7 | import java.sql.SQLException; | ||
| 8 | import java.util.ArrayList; | ||
| 9 | import java.util.HashMap; | ||
| 10 | |||
| 11 | import javafx.stage.FileChooser; | ||
| 12 | import javafx.stage.Stage; | ||
| 13 | import modele.ArmeeListe; | ||
| 14 | |||
| 15 | public class GestionListe { | ||
| 16 | |||
| 17 | // Objet pour gérer la connexion à la bdd | ||
| 18 | private BDD conec; | ||
| 19 | |||
| 20 | // Constructeur de la clasee qui initialise la connexion à la bdd | ||
| 21 | public GestionListe() { | ||
| 22 | this.conec = new BDD(); | ||
| 23 | } | ||
| 24 | |||
| 25 | // récupération de l'id utilisateur et les listes d'armée | ||
| 26 | public ArrayList<ArmeeListe> getArmeeListe(int idUtilisateur) { | ||
| 27 | ArrayList<ArmeeListe> listes = new ArrayList<>(); | ||
| 28 | // Requête pour récupérer les listes d'armée avec leurs unités associées | ||
| 29 | String requete = """ | ||
| 30 | SELECT l.id_liste, l.nom_liste, l.description_liste, l.data_liste, u.nom_unite, u.id_armee | ||
| 31 | FROM liste l | ||
| 32 | LEFT JOIN contenir c ON l.id_liste = c.id_liste | ||
| 33 | LEFT JOIN unite u ON c.id_unite = u.id_unite | ||
| 34 | WHERE l.id_utilisateur = ? | ||
| 35 | """; | ||
| 36 | |||
| 37 | try (Connection conn = conec.getConnection(); | ||
| 38 | PreparedStatement stmt = conn.prepareStatement(requete)) { | ||
| 39 | |||
| 40 | stmt.setInt(1, idUtilisateur); | ||
| 41 | ResultSet recup = stmt.executeQuery(); | ||
| 42 | // Stocker les objets ArmeeListe par ID pour éviter les doublons | ||
| 43 | HashMap<Integer, ArmeeListe> mapListes = new HashMap<>(); | ||
| 44 | System.out.print(stmt + "côté controlleur"); | ||
| 45 | while (recup.next()) { | ||
| 46 | int id = recup.getInt("id_liste"); | ||
| 47 | String nom = recup.getString("nom_liste"); | ||
| 48 | String description = recup.getString("description_liste"); | ||
| 49 | String data = recup.getString("data_liste"); | ||
| 50 | String nomUnite = recup.getString("nom_unite"); | ||
| 51 | int idArmee = recup.getInt("id_armee"); | ||
| 52 | // Vérifier si la liste existe déjà dans la map | ||
| 53 | ArmeeListe liste = mapListes.get(id); | ||
| 54 | if (liste == null) { | ||
| 55 | liste = new ArmeeListe(id, idArmee, nom, description, data, idArmee); | ||
| 56 | liste.setUniteListe(new ArrayList<>()); // Initialiser la liste des unités | ||
| 57 | mapListes.put(id, liste); | ||
| 58 | } | ||
| 59 | |||
| 60 | // Ajouter l'unité si elle existe (éviter null) | ||
| 61 | if (nomUnite != null) { | ||
| 62 | liste.getUniteListe().add(nomUnite); | ||
| 63 | } | ||
| 64 | } | ||
| 65 | |||
| 66 | listes.addAll(mapListes.values()); | ||
| 67 | |||
| 68 | } catch (SQLException e) { | ||
| 69 | e.printStackTrace(); | ||
| 70 | } | ||
| 71 | |||
| 72 | return listes; | ||
| 73 | } | ||
| 74 | |||
| 75 | public static void importer(Stage primaryStage, File file) { | ||
| 76 | FileChooser fileChooser = new FileChooser(); | ||
| 77 | fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Fichier de liste d'armée", "*.*")); | ||
| 78 | file = fileChooser.showOpenDialog(primaryStage); | ||
| 79 | |||
| 80 | // parsing du fichier | ||
| 81 | } | ||
| 82 | } | ||
diff --git a/src/main/java/controlleur/Instanciation.java b/src/main/java/controlleur/Instanciation.java new file mode 100644 index 0000000..3ee39d0 --- /dev/null +++ b/src/main/java/controlleur/Instanciation.java | |||
| @@ -0,0 +1,304 @@ | |||
| 1 | package controlleur; | ||
| 2 | |||
| 3 | import java.sql.PreparedStatement; | ||
| 4 | import java.sql.ResultSet; | ||
| 5 | import java.sql.SQLException; | ||
| 6 | import java.util.ArrayList; | ||
| 7 | |||
| 8 | |||
| 9 | import application.Battle; | ||
| 10 | import modele.Aptitude; | ||
| 11 | import modele.AptitudeArme; | ||
| 12 | import modele.Arme; | ||
| 13 | import modele.ArmeDist; | ||
| 14 | import modele.ArmeMelee; | ||
| 15 | import modele.Armee; | ||
| 16 | import modele.ArmeeListe; | ||
| 17 | import modele.Faction; | ||
| 18 | import modele.Figurine; | ||
| 19 | import modele.Unit; | ||
| 20 | import modele.User; | ||
| 21 | |||
| 22 | public class Instanciation { | ||
| 23 | |||
| 24 | |||
| 25 | //classe qui fait des appel à la BDD pour instancier les classes modele | ||
| 26 | |||
| 27 | private static BDD conec; | ||
| 28 | private static Battle battle_data = new Battle(); | ||
| 29 | |||
| 30 | public static Battle getBattleData() { | ||
| 31 | return battle_data; | ||
| 32 | } | ||
| 33 | public static void resetBattle() { | ||
| 34 | battle_data = null; | ||
| 35 | battle_data = new Battle(); | ||
| 36 | } | ||
| 37 | |||
| 38 | //recupere la liste des faction de la BDD | ||
| 39 | public static ArrayList<Faction> getFaction() { | ||
| 40 | |||
| 41 | ArrayList<Faction> rendu = new ArrayList<Faction>(); | ||
| 42 | ArrayList<String> nom = new ArrayList<String>(); | ||
| 43 | try { | ||
| 44 | conec = new BDD(); | ||
| 45 | nom = conec.select("SELECT nom_faction FROM faction;" ); | ||
| 46 | |||
| 47 | for (String string : nom) { | ||
| 48 | rendu.add(new Faction(string)); | ||
| 49 | } | ||
| 50 | |||
| 51 | }catch(SQLException e) { | ||
| 52 | |||
| 53 | } | ||
| 54 | conec.close(); | ||
| 55 | return rendu; | ||
| 56 | } | ||
| 57 | |||
| 58 | //recupere la liste des armée d'une Faction précise | ||
| 59 | public static ArrayList<Armee> getArmee(Faction faction){ | ||
| 60 | ArrayList<Armee> rendu = new ArrayList<Armee>(); | ||
| 61 | ArrayList<String> nom = new ArrayList<String>(); | ||
| 62 | try { | ||
| 63 | conec = new BDD(); | ||
| 64 | |||
| 65 | nom = conec.select("SELECT a.nom_armee,a.logo_armee FROM armee a JOIN faction f USING (id_faction) WHERE f.nom_faction = ?;",faction.getNom() ); | ||
| 66 | |||
| 67 | |||
| 68 | for (int i = 0;i<nom.size();i = i+2) { | ||
| 69 | |||
| 70 | rendu.add(new Armee(nom.get(i),nom.get(i+1),faction)); | ||
| 71 | } | ||
| 72 | |||
| 73 | }catch(SQLException e) { | ||
| 74 | |||
| 75 | } | ||
| 76 | conec.close(); | ||
| 77 | return rendu; | ||
| 78 | } | ||
| 79 | |||
| 80 | //Récupere la liste des unités d'une armée précise | ||
| 81 | public static ArrayList<Unit> getUniteOfArmy(Armee armee){ | ||
| 82 | ArrayList<Unit> rendu = new ArrayList<Unit>(); | ||
| 83 | ArrayList<String> nom = new ArrayList<String>(); | ||
| 84 | try { | ||
| 85 | conec = new BDD(); | ||
| 86 | nom = conec.select("SELECT u.id_unite, u.nom_unite, u.points_unite,u.logo_unite FROM unite u JOIN armee a USING (id_armee) WHERE a.nom_armee = ? LIMIT 20;",armee.getName() ); | ||
| 87 | |||
| 88 | |||
| 89 | for (int i = 0;i<nom.size();i = i+4) { | ||
| 90 | rendu.add(new Unit(Instanciation.getFigurine(nom.get(i+1)),Integer.parseInt(nom.get(i)),nom.get(i+1), Integer.parseInt(nom.get(i+2)),nom.get(i+3),armee)); | ||
| 91 | } | ||
| 92 | |||
| 93 | |||
| 94 | |||
| 95 | |||
| 96 | }catch(SQLException e) { | ||
| 97 | |||
| 98 | } | ||
| 99 | conec.close(); | ||
| 100 | return rendu; | ||
| 101 | } | ||
| 102 | |||
| 103 | public static ArrayList<Unit> getUniteOfArmyLimited(Armee armee){ | ||
| 104 | ArrayList<Unit> rendu = new ArrayList<Unit>(); | ||
| 105 | ArrayList<String> nom = new ArrayList<String>(); | ||
| 106 | try { | ||
| 107 | conec = new BDD(); | ||
| 108 | nom = conec.select("SELECT u.id_unite, u.nom_unite, u.points_unite,u.logo_unite FROM unite u JOIN armee a USING (id_armee) WHERE a.nom_armee = ? LIMIT 20;",armee.getName() ); | ||
| 109 | |||
| 110 | |||
| 111 | for (int i = 0;i<nom.size();i = i+4) { | ||
| 112 | rendu.add(new Unit(null,Integer.parseInt(nom.get(i)),nom.get(i+1), Integer.parseInt(nom.get(i+2)),nom.get(i+3),armee)); | ||
| 113 | } | ||
| 114 | |||
| 115 | |||
| 116 | |||
| 117 | |||
| 118 | }catch(SQLException e) { | ||
| 119 | |||
| 120 | } | ||
| 121 | conec.close(); | ||
| 122 | return rendu; | ||
| 123 | } | ||
| 124 | |||
| 125 | |||
| 126 | public static void getArmyLists(User session) | ||
| 127 | { | ||
| 128 | conec = new BDD(); | ||
| 129 | String sql = "SELECT nom_liste, description_liste, data_liste FROM liste WHERE id_utilisateur = ?;"; | ||
| 130 | try { | ||
| 131 | PreparedStatement stat = conec.getPreparedStatement(sql, session.getId()); | ||
| 132 | ResultSet rs = stat.executeQuery(); | ||
| 133 | session.getListes().clear(); | ||
| 134 | while(rs.next()){ | ||
| 135 | ArmeeListe one_list = new ArmeeListe(rs.getString("nom_liste"), rs.getString("description_liste"), rs.getString("data_liste")); | ||
| 136 | session.addArmee(one_list); | ||
| 137 | } | ||
| 138 | } catch (SQLException e) { | ||
| 139 | e.printStackTrace(); | ||
| 140 | } | ||
| 141 | conec.close(); | ||
| 142 | } | ||
| 143 | |||
| 144 | public static void getUnitsOfAList(ArmeeListe list) { | ||
| 145 | conec = new BDD(); | ||
| 146 | String sql = "SELECT nom_unite, points_unite, logo_unite, nom_armee, logo_armee" | ||
| 147 | + " FROM unite JOIN contenir USING (id_unite) JOIN liste USING (id_liste) JOIN armee USING (id_armee)" | ||
| 148 | + " WHERE liste.nom_liste = ? AND unite.id_unite = contenir.id_unite AND contenir.id_liste = liste.id_liste;"; | ||
| 149 | |||
| 150 | try { | ||
| 151 | PreparedStatement stat = conec.getPreparedStatement(sql, list.getName()); | ||
| 152 | ResultSet rs = stat.executeQuery(); | ||
| 153 | |||
| 154 | while(rs.next()) { | ||
| 155 | list.addUnit(new Unit(Instanciation.getFigurine(rs.getString(1)), | ||
| 156 | rs.getString(1), rs.getInt(2), rs.getString(3), | ||
| 157 | new Armee(rs.getString(4), rs.getString(5)))); | ||
| 158 | } | ||
| 159 | } | ||
| 160 | catch (SQLException e) { | ||
| 161 | // TODO Auto-generated catch block | ||
| 162 | e.printStackTrace(); | ||
| 163 | } | ||
| 164 | conec.close(); | ||
| 165 | } | ||
| 166 | |||
| 167 | //Récupere les Figurine présente dans une unité précise | ||
| 168 | public static ArrayList<Figurine> getFigurine(String unitName){ | ||
| 169 | ArrayList<Figurine> rendu = new ArrayList<Figurine>(); | ||
| 170 | ArrayList<String> temp = new ArrayList<String>(); | ||
| 171 | try { | ||
| 172 | |||
| 173 | temp = conec.select("SELECT f.nom_figurine,f.M,f.E,f.SV,f.PV,f.CD,f.CO,r.nb_figurine FROM figurine f " | ||
| 174 | + "JOIN remplir r USING (id_figurine) JOIN unite u USING(id_unite) WHERE u.nom_unite = ?;",unitName ); | ||
| 175 | |||
| 176 | |||
| 177 | for (int i = 0;i<temp.size();i = i+8) { | ||
| 178 | for (int j =0;j< Integer.parseInt(temp.get(7));j++) { | ||
| 179 | rendu.add(new Figurine(Instanciation.getArme(temp.get(i)),Instanciation.getAptitude(temp.get(i)),temp.get(i),"",temp.get(i+1),Integer.parseInt(temp.get(i+2)),Integer.parseInt(temp.get(i+3)),Integer.parseInt(temp.get(i+4)),Integer.parseInt(temp.get(i+5)),Integer.parseInt(temp.get(i+6)))); | ||
| 180 | |||
| 181 | } | ||
| 182 | } | ||
| 183 | |||
| 184 | |||
| 185 | |||
| 186 | |||
| 187 | }catch(SQLException e) { | ||
| 188 | |||
| 189 | } | ||
| 190 | |||
| 191 | return rendu; | ||
| 192 | } | ||
| 193 | |||
| 194 | public static ArrayList<Figurine> getFigurine2(String unitName){ | ||
| 195 | ArrayList<Figurine> rendu = new ArrayList<Figurine>(); | ||
| 196 | ArrayList<String> temp = new ArrayList<String>(); | ||
| 197 | try { | ||
| 198 | conec = new BDD(); | ||
| 199 | temp = conec.select("SELECT f.nom_figurine,f.M,f.E,f.SV,f.PV,f.CD,f.CO,r.nb_figurine FROM figurine f " | ||
| 200 | + "JOIN remplir r USING (id_figurine) JOIN unite u USING(id_unite) WHERE u.nom_unite = ?;",unitName ); | ||
| 201 | |||
| 202 | |||
| 203 | for (int i = 0;i<temp.size();i = i+8) { | ||
| 204 | for (int j =0;j< Integer.parseInt(temp.get(7));j++) { | ||
| 205 | rendu.add(new Figurine(Instanciation.getArme(temp.get(i)),Instanciation.getAptitude(temp.get(i)),temp.get(i),"",temp.get(i+1),Integer.parseInt(temp.get(i+2)),Integer.parseInt(temp.get(i+3)),Integer.parseInt(temp.get(i+4)),Integer.parseInt(temp.get(i+5)),Integer.parseInt(temp.get(i+6)))); | ||
| 206 | |||
| 207 | } | ||
| 208 | } | ||
| 209 | |||
| 210 | |||
| 211 | |||
| 212 | |||
| 213 | }catch(SQLException e) { | ||
| 214 | |||
| 215 | } | ||
| 216 | conec.close(); | ||
| 217 | return rendu; | ||
| 218 | } | ||
| 219 | |||
| 220 | //Récupère les armes d'une figurine donnée | ||
| 221 | public static ArrayList<Arme> getArme(String figNom){ | ||
| 222 | ArrayList<Arme> rendu = new ArrayList<Arme>(); | ||
| 223 | ArrayList<String> nom = new ArrayList<String>(); | ||
| 224 | try { | ||
| 225 | |||
| 226 | nom = conec.select("SELECT a.nom_arme,a.PORTEE,a.A,a.F,a.PA,a.D,t.CT,m.CC FROM figurine f JOIN equiper e USING(id_figurine) JOIN arme a USING (id_arme) LEFT JOIN tir t USING (id_tir) LEFT JOIN melee m USING(id_melee) WHERE f.nom_figurine = ?;",figNom ); | ||
| 227 | |||
| 228 | |||
| 229 | for (int i = 0;i<nom.size();i = i+8) { | ||
| 230 | if (nom.get(i+7) == null) { | ||
| 231 | rendu.add(new ArmeDist(nom.get(i),Instanciation.getAptitudeArme(nom.get(i)),nom.get(i+1),nom.get(i+2),Integer.parseInt(nom.get(i+3)),Integer.parseInt(nom.get(i+4)),nom.get(i+5),Integer.parseInt(nom.get(i+6)))); | ||
| 232 | }else { | ||
| 233 | rendu.add(new ArmeMelee(nom.get(i),Instanciation.getAptitudeArme(nom.get(i)),nom.get(i+1),nom.get(i+2),Integer.parseInt(nom.get(i+3)),Integer.parseInt(nom.get(i+4)),nom.get(i+5),Integer.parseInt(nom.get(i+7)))); | ||
| 234 | } | ||
| 235 | } | ||
| 236 | |||
| 237 | |||
| 238 | |||
| 239 | |||
| 240 | |||
| 241 | }catch(SQLException e) { | ||
| 242 | |||
| 243 | } | ||
| 244 | |||
| 245 | return rendu; | ||
| 246 | } | ||
| 247 | |||
| 248 | //Récupère les Aptitude d'une figurine donnée | ||
| 249 | public static ArrayList<Aptitude> getAptitude(String figNom){ | ||
| 250 | ArrayList<Aptitude> rendu = new ArrayList<Aptitude>(); | ||
| 251 | ArrayList<String> nom = new ArrayList<String>(); | ||
| 252 | try { | ||
| 253 | |||
| 254 | nom = conec.select("SELECT a.nom_aptitude FROM aptitude a JOIN permettre USING (id_aptitude) JOIN figurine f USING(id_figurine) WHERE f.nom_figurine = ?;",figNom ); | ||
| 255 | |||
| 256 | |||
| 257 | for (int i = 0;i<nom.size(); i++) { | ||
| 258 | rendu.add(new Aptitude(nom.get(i))); | ||
| 259 | } | ||
| 260 | |||
| 261 | |||
| 262 | |||
| 263 | |||
| 264 | |||
| 265 | |||
| 266 | }catch(SQLException e) { | ||
| 267 | |||
| 268 | } | ||
| 269 | |||
| 270 | return rendu; | ||
| 271 | } | ||
| 272 | |||
| 273 | //Récupère les Aptitude d'une arme donnée | ||
| 274 | public static ArrayList<AptitudeArme> getAptitudeArme(String armeNom){ | ||
| 275 | ArrayList<AptitudeArme> rendu = new ArrayList<AptitudeArme>(); | ||
| 276 | ArrayList<String> nom = new ArrayList<String>(); | ||
| 277 | try { | ||
| 278 | |||
| 279 | nom = conec.select("SELECT a.nom_aptitude_arme FROM aptitude_arme a JOIN posseder USING (id_aptitude_arme) JOIN arme ar USING(id_arme) WHERE ar.nom_arme = ?;",armeNom ); | ||
| 280 | |||
| 281 | |||
| 282 | for (int i = 0;i<nom.size();i = i++) { | ||
| 283 | rendu.add(new AptitudeArme(nom.get(i))); | ||
| 284 | } | ||
| 285 | |||
| 286 | |||
| 287 | |||
| 288 | |||
| 289 | |||
| 290 | }catch(SQLException e) { | ||
| 291 | |||
| 292 | } | ||
| 293 | |||
| 294 | return rendu; | ||
| 295 | } | ||
| 296 | |||
| 297 | //Insert une Armée crée dans l'application dans la base de donée en la liant à un utilisateur | ||
| 298 | public static void insertListe(ArmeeListe armee,User session) { | ||
| 299 | conec = new BDD(); | ||
| 300 | conec.insertListe(armee, session); | ||
| 301 | conec.close(); | ||
| 302 | } | ||
| 303 | |||
| 304 | } | ||
diff --git a/src/main/java/controlleur/ModificationListe.java b/src/main/java/controlleur/ModificationListe.java new file mode 100644 index 0000000..7de1b59 --- /dev/null +++ b/src/main/java/controlleur/ModificationListe.java | |||
| @@ -0,0 +1,214 @@ | |||
| 1 | package controlleur; | ||
| 2 | |||
| 3 | import java.sql.Connection; | ||
| 4 | import java.sql.PreparedStatement; | ||
| 5 | import java.sql.ResultSet; | ||
| 6 | import java.sql.SQLException; | ||
| 7 | import java.util.ArrayList; | ||
| 8 | import java.util.HashMap; | ||
| 9 | |||
| 10 | import modele.ArmeeListe; | ||
| 11 | import modele.Figurine; | ||
| 12 | |||
| 13 | public class ModificationListe { | ||
| 14 | |||
| 15 | private BDD conec; // Instance de la classe BDD qui gère la connexion à la bdd | ||
| 16 | |||
| 17 | public ModificationListe() { | ||
| 18 | this.conec = new BDD(); | ||
| 19 | } | ||
| 20 | |||
| 21 | // Récupère la liste des armées en fonction de l'id de la liste choisie | ||
| 22 | public ArrayList<ArmeeListe> getArmeeListe(int idListe) { | ||
| 23 | ArrayList<ArmeeListe> listes = new ArrayList<>(); | ||
| 24 | String requete = """ | ||
| 25 | SELECT l.id_liste, l.nom_liste, l.description_liste, l.data_liste, u.nom_unite | ||
| 26 | FROM liste l | ||
| 27 | LEFT JOIN contenir c ON l.id_liste = c.id_liste | ||
| 28 | LEFT JOIN unite u ON c.id_unite = u.id_unite | ||
| 29 | WHERE l.id_liste = ?; | ||
| 30 | """; | ||
| 31 | |||
| 32 | try (Connection conn = reopenConnection(); | ||
| 33 | PreparedStatement stmt = conn.prepareStatement(requete)) { | ||
| 34 | |||
| 35 | stmt.setInt(1, idListe); | ||
| 36 | ResultSet recup = stmt.executeQuery(); | ||
| 37 | HashMap<Integer, ArmeeListe> mapListes = new HashMap<>(); | ||
| 38 | |||
| 39 | while (recup.next()) { | ||
| 40 | int id = recup.getInt("id_liste"); | ||
| 41 | String nom = recup.getString("nom_liste"); | ||
| 42 | String description = recup.getString("description_liste"); | ||
| 43 | String data = recup.getString("data_liste"); | ||
| 44 | String nomUnite = recup.getString("nom_unite"); | ||
| 45 | |||
| 46 | ArmeeListe liste = mapListes.get(id); | ||
| 47 | if (liste == null) { | ||
| 48 | liste = new ArmeeListe(id, id, nom, description, data, id); | ||
| 49 | liste.setUniteListe(new ArrayList<>()); | ||
| 50 | mapListes.put(id, liste); | ||
| 51 | } | ||
| 52 | |||
| 53 | if (nomUnite != null) { | ||
| 54 | liste.getUniteListe().add(nomUnite); | ||
| 55 | } | ||
| 56 | } | ||
| 57 | listes.addAll(mapListes.values()); | ||
| 58 | |||
| 59 | } catch (SQLException e) { | ||
| 60 | e.printStackTrace(); | ||
| 61 | } | ||
| 62 | return listes; | ||
| 63 | } | ||
| 64 | |||
| 65 | public ArrayList<Figurine> getFigurineListe(int idListe, String nomUnit) { | ||
| 66 | ArrayList<Figurine> listesFigurine = new ArrayList<>(); | ||
| 67 | String requete = """ | ||
| 68 | SELECT f.nom_figurine, f.M, f.E, f.SV, f.PV, f.CD, f.CO | ||
| 69 | FROM liste l | ||
| 70 | JOIN contenir c ON l.id_liste = c.id_liste | ||
| 71 | JOIN unite u ON c.id_unite = u.id_unite | ||
| 72 | JOIN remplir r ON u.id_unite = r.id_unite | ||
| 73 | JOIN figurine f ON r.id_figurine = f.id_figurine | ||
| 74 | WHERE l.id_liste = ? AND u.nom_unite = ?; | ||
| 75 | """; | ||
| 76 | |||
| 77 | try (Connection conn = reopenConnection(); | ||
| 78 | PreparedStatement stmt = conn.prepareStatement(requete)) { | ||
| 79 | |||
| 80 | stmt.setInt(1, idListe); | ||
| 81 | stmt.setString(2, nomUnit); | ||
| 82 | ResultSet recup = stmt.executeQuery(); | ||
| 83 | |||
| 84 | while (recup.next()) { // récupère toutes les info de la figurine | ||
| 85 | String nomFigurine = recup.getString("nom_figurine"); | ||
| 86 | String M = recup.getString("M"); | ||
| 87 | int E = recup.getInt("E"); | ||
| 88 | int SV = recup.getInt("SV"); | ||
| 89 | int PV = recup.getInt("PV"); | ||
| 90 | int CD = recup.getInt("CD"); | ||
| 91 | int CO = recup.getInt("CO"); | ||
| 92 | |||
| 93 | Figurine figurine = new Figurine(new ArrayList<>(), new ArrayList<>(), nomFigurine, "", M, E, SV, PV, CD, CO); | ||
| 94 | listesFigurine.add(figurine); | ||
| 95 | } | ||
| 96 | } catch (SQLException e) { | ||
| 97 | e.printStackTrace(); | ||
| 98 | } | ||
| 99 | return listesFigurine; | ||
| 100 | } | ||
| 101 | |||
| 102 | public ArrayList<ArmeeListe> getAllUnites(int idArmee, int idListe) { | ||
| 103 | ArrayList<ArmeeListe> toutesUnites = new ArrayList<>(); | ||
| 104 | String requete = "SELECT u.nom_unite\r\n" | ||
| 105 | + "FROM unite u\r\n" | ||
| 106 | + "WHERE u.id_armee = ?\r\n" | ||
| 107 | + "AND u.nom_unite NOT IN (\r\n" | ||
| 108 | + " SELECT un.nom_unite\r\n" | ||
| 109 | + " FROM unite un\r\n" | ||
| 110 | + " JOIN contenir c ON un.id_unite = c.id_unite\r\n" | ||
| 111 | + " WHERE c.id_liste = ?\r\n" | ||
| 112 | + ");"; | ||
| 113 | |||
| 114 | try (Connection conn = reopenConnection(); | ||
| 115 | PreparedStatement stmt = conn.prepareStatement(requete)) { | ||
| 116 | |||
| 117 | stmt.setInt(1, idArmee); | ||
| 118 | stmt.setInt(2, idListe); | ||
| 119 | ResultSet recup = stmt.executeQuery(); | ||
| 120 | |||
| 121 | while (recup.next()) { | ||
| 122 | String nomUnite = recup.getString("nom_unite"); | ||
| 123 | ArmeeListe armee = new ArmeeListe(idArmee, idArmee, nomUnite, nomUnite, nomUnite, idListe); | ||
| 124 | armee.setUniteListe(new ArrayList<>()); | ||
| 125 | armee.getUniteListe().add(nomUnite); | ||
| 126 | toutesUnites.add(armee); | ||
| 127 | } | ||
| 128 | } catch (SQLException e) { | ||
| 129 | e.printStackTrace(); | ||
| 130 | } | ||
| 131 | return toutesUnites; | ||
| 132 | } | ||
| 133 | |||
| 134 | public ArrayList<Figurine> getAllFigurineListe(int idArmee, String unit) { | ||
| 135 | ArrayList<Figurine> listesAllFigurine = new ArrayList<>(); | ||
| 136 | String requete = """ | ||
| 137 | SELECT DISTINCT f.nom_figurine, f.M, f.E, f.SV, f.PV, f.CD, f.CO | ||
| 138 | FROM unite u | ||
| 139 | JOIN remplir r ON u.id_unite = r.id_unite | ||
| 140 | JOIN figurine f ON r.id_figurine = f.id_figurine | ||
| 141 | WHERE u.id_armee = ? AND u.nom_unite = ?; | ||
| 142 | """; | ||
| 143 | |||
| 144 | try (Connection conn = reopenConnection(); | ||
| 145 | PreparedStatement stmt = conn.prepareStatement(requete)) { | ||
| 146 | |||
| 147 | stmt.setInt(1, idArmee); | ||
| 148 | stmt.setString(2, unit); | ||
| 149 | ResultSet recup = stmt.executeQuery(); | ||
| 150 | |||
| 151 | while (recup.next()) { // récupère toutes les info de la figurine | ||
| 152 | String nomFigurine = recup.getString("nom_figurine"); | ||
| 153 | String M = recup.getString("M"); | ||
| 154 | int E = recup.getInt("E"); | ||
| 155 | int SV = recup.getInt("SV"); | ||
| 156 | int PV = recup.getInt("PV"); | ||
| 157 | int CD = recup.getInt("CD"); | ||
| 158 | int CO = recup.getInt("CO"); | ||
| 159 | |||
| 160 | Figurine figurine = new Figurine(new ArrayList<>(), new ArrayList<>(), nomFigurine, "", M, E, SV, PV, CD, CO); | ||
| 161 | listesAllFigurine.add(figurine); | ||
| 162 | } | ||
| 163 | } catch (SQLException e) { | ||
| 164 | e.printStackTrace(); | ||
| 165 | } | ||
| 166 | return listesAllFigurine; | ||
| 167 | } | ||
| 168 | |||
| 169 | private Connection reopenConnection() throws SQLException { | ||
| 170 | if (conec.getConnection().isClosed()) { | ||
| 171 | conec = new BDD(); | ||
| 172 | } | ||
| 173 | return conec.getConnection(); | ||
| 174 | } | ||
| 175 | |||
| 176 | public void ajouterUnites(int idListe, ArrayList<String> unites) { | ||
| 177 | String query = """ | ||
| 178 | INSERT INTO contenir (id_unite, id_liste) | ||
| 179 | SELECT id_unite, ? FROM unite WHERE nom_unite = ? LIMIT 1 | ||
| 180 | """; | ||
| 181 | try (Connection conn = reopenConnection(); | ||
| 182 | PreparedStatement pstmt = conn.prepareStatement(query)) { | ||
| 183 | |||
| 184 | for (String unite : unites) { | ||
| 185 | pstmt.setInt(1, idListe); | ||
| 186 | pstmt.setString(2, unite); | ||
| 187 | System.out.println("Requête: " + pstmt); | ||
| 188 | pstmt.addBatch(); | ||
| 189 | } | ||
| 190 | pstmt.executeBatch(); | ||
| 191 | |||
| 192 | } catch (SQLException e) { | ||
| 193 | e.printStackTrace(); | ||
| 194 | } | ||
| 195 | } | ||
| 196 | |||
| 197 | public void supprimerUnites(int idListe, ArrayList<String> unites) { | ||
| 198 | String query = "DELETE FROM contenir WHERE id_liste = ? AND id_unite = (SELECT id_unite FROM unite WHERE nom_unite = ? LIMIT 1)"; | ||
| 199 | try (Connection conn = reopenConnection(); | ||
| 200 | PreparedStatement pstmt = conn.prepareStatement(query)) { | ||
| 201 | |||
| 202 | for (String unite : unites) { | ||
| 203 | pstmt.setInt(1, idListe); | ||
| 204 | pstmt.setString(2, unite); | ||
| 205 | System.out.println("Requête: " + pstmt); | ||
| 206 | pstmt.addBatch(); | ||
| 207 | } | ||
| 208 | pstmt.executeBatch(); | ||
| 209 | |||
| 210 | } catch (SQLException e) { | ||
| 211 | e.printStackTrace(); | ||
| 212 | } | ||
| 213 | } | ||
| 214 | } | ||
diff --git a/src/main/java/controlleur/StockageCreerListe.java b/src/main/java/controlleur/StockageCreerListe.java new file mode 100644 index 0000000..82f4448 --- /dev/null +++ b/src/main/java/controlleur/StockageCreerListe.java | |||
| @@ -0,0 +1,75 @@ | |||
| 1 | package controlleur; | ||
| 2 | |||
| 3 | import java.util.ArrayList; | ||
| 4 | import java.util.HashMap; | ||
| 5 | |||
| 6 | import modele.Armee; | ||
| 7 | import modele.ArmeeListe; | ||
| 8 | import modele.Faction; | ||
| 9 | import modele.Unit; | ||
| 10 | |||
| 11 | public class StockageCreerListe { | ||
| 12 | |||
| 13 | //sauvegarde les nom des armée, des unités et des factions pour ne pas refaire appel à la BDD en boucle | ||
| 14 | |||
| 15 | private static final HashMap<String,Faction> faction = new HashMap<String, Faction>(); | ||
| 16 | private static final HashMap<String,Armee> armee = new HashMap<String, Armee>(); | ||
| 17 | private static final HashMap<String,Unit> unit = new HashMap<String, Unit>(); | ||
| 18 | private static ArmeeListe armeeListe; | ||
| 19 | |||
| 20 | |||
| 21 | public static void initFaction() { | ||
| 22 | faction.clear(); | ||
| 23 | for(Faction fac : Instanciation.getFaction()) { | ||
| 24 | faction.put(fac.getNom(), fac); | ||
| 25 | } | ||
| 26 | } | ||
| 27 | |||
| 28 | public static ArrayList<String> getNomFac(){ | ||
| 29 | ArrayList<String> rendu = new ArrayList<String>(); | ||
| 30 | for(Faction fac :faction.values() ) { | ||
| 31 | rendu.add(fac.getNom()); | ||
| 32 | } | ||
| 33 | return rendu; | ||
| 34 | } | ||
| 35 | |||
| 36 | public static void initArmee(String nomFaction) { | ||
| 37 | armee.clear(); | ||
| 38 | for(Armee arm:Instanciation.getArmee(faction.get(nomFaction))) { | ||
| 39 | armee.put(arm.getName(), arm); | ||
| 40 | } | ||
| 41 | } | ||
| 42 | |||
| 43 | public static ArrayList<String> getNomArmee() { | ||
| 44 | ArrayList<String> rendu = new ArrayList<String>(); | ||
| 45 | |||
| 46 | for(String arm : armee.keySet()) { | ||
| 47 | rendu.add(arm); | ||
| 48 | } | ||
| 49 | //rendu.add(rendu.removeFirst()); | ||
| 50 | return rendu; | ||
| 51 | } | ||
| 52 | public static void initUnit(String nomArmee) { | ||
| 53 | unit.clear(); | ||
| 54 | for(Unit uni:Instanciation.getUniteOfArmyLimited(armee.get(nomArmee))) { | ||
| 55 | unit.put(uni.getName(), uni); | ||
| 56 | } | ||
| 57 | } | ||
| 58 | public static ArrayList<String> getNomUnit() { | ||
| 59 | ArrayList<String> rendu = new ArrayList<String>(); | ||
| 60 | for(Unit uni : unit.values()) { | ||
| 61 | rendu.add(uni.getName()); | ||
| 62 | } | ||
| 63 | |||
| 64 | return rendu; | ||
| 65 | } | ||
| 66 | public static void initArmeeListe() { | ||
| 67 | armeeListe = new ArmeeListe(new ArrayList<Unit>(),"nom_temp","desc","data"); | ||
| 68 | } | ||
| 69 | public static ArmeeListe getArmeeListe() { | ||
| 70 | return armeeListe; | ||
| 71 | } | ||
| 72 | public static Unit getUnit(String nomUnit) { | ||
| 73 | return unit.get(nomUnit); | ||
| 74 | } | ||
| 75 | } | ||
diff --git a/src/main/java/controlleur/SupprListe.java b/src/main/java/controlleur/SupprListe.java new file mode 100644 index 0000000..6e2f488 --- /dev/null +++ b/src/main/java/controlleur/SupprListe.java | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | package controlleur; | ||
| 2 | |||
| 3 | import java.sql.Connection; | ||
| 4 | import java.sql.PreparedStatement; | ||
| 5 | import java.sql.SQLException; | ||
| 6 | |||
| 7 | public class SupprListe { | ||
| 8 | private BDD conec; | ||
| 9 | |||
| 10 | public SupprListe() { | ||
| 11 | this.conec = new BDD(); | ||
| 12 | } | ||
| 13 | |||
| 14 | public void Suppression(int idListe) { | ||
| 15 | |||
| 16 | String requeteSuppr = "DELETE FROM liste WHERE id_liste=?;"; | ||
| 17 | |||
| 18 | try (Connection conn = conec.getConnection(); PreparedStatement stmt = conn.prepareStatement(requeteSuppr)) { | ||
| 19 | |||
| 20 | stmt.setInt(1, idListe); | ||
| 21 | stmt.executeUpdate(); | ||
| 22 | } catch (SQLException e) { | ||
| 23 | e.printStackTrace(); | ||
| 24 | } | ||
| 25 | } | ||
| 26 | |||
| 27 | } | ||
diff --git a/src/main/java/images/accueil.jpg b/src/main/java/images/accueil.jpg new file mode 100644 index 0000000..bc59db0 --- /dev/null +++ b/src/main/java/images/accueil.jpg | |||
| Binary files differ | |||
diff --git a/src/main/java/images/android-fill.png b/src/main/java/images/android-fill.png new file mode 100644 index 0000000..ac7e1fa --- /dev/null +++ b/src/main/java/images/android-fill.png | |||
| Binary files differ | |||
diff --git a/src/main/java/images/android-line.png b/src/main/java/images/android-line.png new file mode 100644 index 0000000..80952c9 --- /dev/null +++ b/src/main/java/images/android-line.png | |||
| Binary files differ | |||
diff --git a/src/main/java/images/armees/BlackTemplars.png b/src/main/java/images/armees/BlackTemplars.png new file mode 100644 index 0000000..7f02866 --- /dev/null +++ b/src/main/java/images/armees/BlackTemplars.png | |||
| Binary files differ | |||
diff --git a/src/main/java/images/armees/android-fill.png b/src/main/java/images/armees/android-fill.png new file mode 100644 index 0000000..ac7e1fa --- /dev/null +++ b/src/main/java/images/armees/android-fill.png | |||
| Binary files differ | |||
diff --git a/src/main/java/images/deco.png b/src/main/java/images/deco.png new file mode 100644 index 0000000..50e5e72 --- /dev/null +++ b/src/main/java/images/deco.png | |||
| Binary files differ | |||
diff --git a/src/main/java/images/inversion_icons.png b/src/main/java/images/inversion_icons.png new file mode 100644 index 0000000..f8cf209 --- /dev/null +++ b/src/main/java/images/inversion_icons.png | |||
| Binary files differ | |||
diff --git a/src/main/java/images/tournoi1.jpg b/src/main/java/images/tournoi1.jpg new file mode 100644 index 0000000..70b0f8c --- /dev/null +++ b/src/main/java/images/tournoi1.jpg | |||
| Binary files differ | |||
diff --git a/src/main/java/images/tournoi2.jpg b/src/main/java/images/tournoi2.jpg new file mode 100644 index 0000000..9a3a662 --- /dev/null +++ b/src/main/java/images/tournoi2.jpg | |||
| Binary files differ | |||
diff --git a/src/main/java/images/tournoi3.jpg b/src/main/java/images/tournoi3.jpg new file mode 100644 index 0000000..77fe608 --- /dev/null +++ b/src/main/java/images/tournoi3.jpg | |||
| Binary files differ | |||
diff --git a/src/main/java/images/wip.jpg b/src/main/java/images/wip.jpg new file mode 100644 index 0000000..771e8fd --- /dev/null +++ b/src/main/java/images/wip.jpg | |||
| Binary files differ | |||
diff --git a/src/main/java/modele/Aptitude.java b/src/main/java/modele/Aptitude.java new file mode 100644 index 0000000..4ea1a9f --- /dev/null +++ b/src/main/java/modele/Aptitude.java | |||
| @@ -0,0 +1,14 @@ | |||
| 1 | package modele; | ||
| 2 | |||
| 3 | public class Aptitude { | ||
| 4 | |||
| 5 | private String nom; | ||
| 6 | |||
| 7 | public Aptitude(String nom) { | ||
| 8 | this.nom = nom; | ||
| 9 | } | ||
| 10 | |||
| 11 | public String getName() { | ||
| 12 | return nom; | ||
| 13 | } | ||
| 14 | } | ||
diff --git a/src/main/java/modele/AptitudeArme.java b/src/main/java/modele/AptitudeArme.java new file mode 100644 index 0000000..28e82dd --- /dev/null +++ b/src/main/java/modele/AptitudeArme.java | |||
| @@ -0,0 +1,20 @@ | |||
| 1 | package modele; | ||
| 2 | |||
| 3 | public class AptitudeArme { | ||
| 4 | |||
| 5 | private String nomArme; | ||
| 6 | private int val; | ||
| 7 | |||
| 8 | public AptitudeArme(String nomArme, int val) { | ||
| 9 | this.nomArme = nomArme; | ||
| 10 | this.val = val; | ||
| 11 | } | ||
| 12 | public AptitudeArme(String nomArme) { | ||
| 13 | this.nomArme = nomArme; | ||
| 14 | } | ||
| 15 | |||
| 16 | public void ArmeAptitude() { | ||
| 17 | |||
| 18 | } | ||
| 19 | |||
| 20 | } | ||
diff --git a/src/main/java/modele/Arme.java b/src/main/java/modele/Arme.java new file mode 100644 index 0000000..53db538 --- /dev/null +++ b/src/main/java/modele/Arme.java | |||
| @@ -0,0 +1,91 @@ | |||
| 1 | package modele; | ||
| 2 | |||
| 3 | import java.util.ArrayList; | ||
| 4 | |||
| 5 | public abstract class Arme { | ||
| 6 | |||
| 7 | private String nom; | ||
| 8 | private ArrayList<AptitudeArme> aptitudes; | ||
| 9 | private String portee; | ||
| 10 | private String A; | ||
| 11 | private int F; | ||
| 12 | private int PA; | ||
| 13 | private String D; | ||
| 14 | public Arme(String nom, ArrayList<AptitudeArme> aptitudes,String portee, String a, int f, int pA, String d) | ||
| 15 | { | ||
| 16 | this.nom = nom; | ||
| 17 | this.aptitudes = aptitudes; | ||
| 18 | this.portee=portee; | ||
| 19 | this.setAptitudes(aptitudes); | ||
| 20 | |||
| 21 | A = a; | ||
| 22 | F = f; | ||
| 23 | PA = pA; | ||
| 24 | D = d; | ||
| 25 | } | ||
| 26 | public Arme(String nom, int F, int PA, String A, String D) { | ||
| 27 | this.nom = nom; | ||
| 28 | this.F = F; | ||
| 29 | this.PA = PA; | ||
| 30 | this.A=A; | ||
| 31 | this.D=D; | ||
| 32 | } | ||
| 33 | public ArrayList<Integer> statsAtk(){ | ||
| 34 | ArrayList<Integer> liste = new ArrayList<Integer>(); | ||
| 35 | |||
| 36 | liste.add(F); | ||
| 37 | liste.add(PA); | ||
| 38 | |||
| 39 | return liste; | ||
| 40 | } | ||
| 41 | |||
| 42 | //v2 | ||
| 43 | public String getD() { | ||
| 44 | return D; | ||
| 45 | } | ||
| 46 | public void setD(String d) { | ||
| 47 | D = d; | ||
| 48 | } | ||
| 49 | |||
| 50 | public String getNom() { | ||
| 51 | return nom; | ||
| 52 | } | ||
| 53 | public void setNom(String nom) { | ||
| 54 | this.nom = nom; | ||
| 55 | } | ||
| 56 | |||
| 57 | public String getPortee() { | ||
| 58 | return portee; | ||
| 59 | } | ||
| 60 | public void setPortee(String portee) { | ||
| 61 | this.portee = portee; | ||
| 62 | } | ||
| 63 | public String getA() { | ||
| 64 | return A; | ||
| 65 | } | ||
| 66 | public void setA(String a) { | ||
| 67 | A = a; | ||
| 68 | } | ||
| 69 | public int getF() { | ||
| 70 | return F; | ||
| 71 | } | ||
| 72 | public void setF(int f) { | ||
| 73 | F = f; | ||
| 74 | } | ||
| 75 | |||
| 76 | public int getPA() { | ||
| 77 | return PA; | ||
| 78 | } | ||
| 79 | public void setPA(int pA) { | ||
| 80 | PA = pA; | ||
| 81 | } | ||
| 82 | |||
| 83 | public abstract int getC(); | ||
| 84 | |||
| 85 | public ArrayList<AptitudeArme> getAptitudes() { | ||
| 86 | return aptitudes; | ||
| 87 | } | ||
| 88 | public void setAptitudes(ArrayList<AptitudeArme> aptitudes) { | ||
| 89 | this.aptitudes = aptitudes; | ||
| 90 | } | ||
| 91 | } \ No newline at end of file | ||
diff --git a/src/main/java/modele/ArmeDist.java b/src/main/java/modele/ArmeDist.java new file mode 100644 index 0000000..1a43ad0 --- /dev/null +++ b/src/main/java/modele/ArmeDist.java | |||
| @@ -0,0 +1,31 @@ | |||
| 1 | package modele; | ||
| 2 | |||
| 3 | import java.util.ArrayList; | ||
| 4 | |||
| 5 | public class ArmeDist extends Arme { | ||
| 6 | private int CT; | ||
| 7 | public ArmeDist(String nom, ArrayList<AptitudeArme> aptitudes,String portee, String a, int f, int pA, String d,int ct) { | ||
| 8 | super(nom, aptitudes,portee, a, f, pA, d); | ||
| 9 | this.CT=ct; | ||
| 10 | // TODO Auto-generated constructor stub | ||
| 11 | } | ||
| 12 | @Override | ||
| 13 | public ArrayList<Integer> statsAtk() { | ||
| 14 | // TODO Auto-generated method stub | ||
| 15 | ArrayList<Integer> liste = super.statsAtk(); | ||
| 16 | liste.add(CT); | ||
| 17 | return liste; | ||
| 18 | } | ||
| 19 | public int getCT() { | ||
| 20 | return CT; | ||
| 21 | } | ||
| 22 | |||
| 23 | public void setCT(int cT) { | ||
| 24 | CT = cT; | ||
| 25 | } | ||
| 26 | public int getC() { | ||
| 27 | return CT; | ||
| 28 | } | ||
| 29 | } | ||
| 30 | |||
| 31 | |||
diff --git a/src/main/java/modele/ArmeMelee.java b/src/main/java/modele/ArmeMelee.java new file mode 100644 index 0000000..6061c58 --- /dev/null +++ b/src/main/java/modele/ArmeMelee.java | |||
| @@ -0,0 +1,39 @@ | |||
| 1 | package modele; | ||
| 2 | |||
| 3 | import java.util.ArrayList; | ||
| 4 | |||
| 5 | public class ArmeMelee extends Arme { | ||
| 6 | private int CC; | ||
| 7 | |||
| 8 | public ArmeMelee(String nom, ArrayList<AptitudeArme> aptitudes,String portee, String a, int f, int pA, String d,int cc) { | ||
| 9 | super(nom, aptitudes,portee, a, f, pA, d); | ||
| 10 | this.CC=cc; | ||
| 11 | // TODO Auto-generated constructor stub | ||
| 12 | } | ||
| 13 | |||
| 14 | public ArmeMelee(String nom,int F,int PA,String A,String D,int cc) { | ||
| 15 | super(nom,F,PA,A,D); | ||
| 16 | this.CC = cc; | ||
| 17 | } | ||
| 18 | |||
| 19 | @Override | ||
| 20 | public ArrayList<Integer> statsAtk() { | ||
| 21 | ArrayList<Integer> liste = super.statsAtk(); | ||
| 22 | liste.add(CC); | ||
| 23 | return null; | ||
| 24 | } | ||
| 25 | |||
| 26 | public int getCC() { | ||
| 27 | return CC; | ||
| 28 | } | ||
| 29 | |||
| 30 | public void setCC(int cC) { | ||
| 31 | CC = cC; | ||
| 32 | } | ||
| 33 | |||
| 34 | @Override | ||
| 35 | public int getC() { | ||
| 36 | return CC; | ||
| 37 | } | ||
| 38 | } | ||
| 39 | |||
diff --git a/src/main/java/modele/Armee.java b/src/main/java/modele/Armee.java new file mode 100644 index 0000000..132418b --- /dev/null +++ b/src/main/java/modele/Armee.java | |||
| @@ -0,0 +1,36 @@ | |||
| 1 | package modele; | ||
| 2 | |||
| 3 | public class Armee { | ||
| 4 | |||
| 5 | private String nom; | ||
| 6 | private String logo; | ||
| 7 | private Faction faction; | ||
| 8 | |||
| 9 | public Armee(String nom, String logo) { | ||
| 10 | this.nom = nom; | ||
| 11 | this.logo = logo; | ||
| 12 | } | ||
| 13 | |||
| 14 | public Armee(String nom, String logo, Faction fact) { | ||
| 15 | this.nom = nom; | ||
| 16 | this.logo = logo; | ||
| 17 | this.faction = fact; | ||
| 18 | } | ||
| 19 | |||
| 20 | public String getName() { | ||
| 21 | return nom; | ||
| 22 | } | ||
| 23 | |||
| 24 | @Override | ||
| 25 | public String toString() { | ||
| 26 | return "" + nom + ""; | ||
| 27 | } | ||
| 28 | |||
| 29 | public String getLogo() { | ||
| 30 | return logo; | ||
| 31 | } | ||
| 32 | |||
| 33 | public Faction getFaction() { | ||
| 34 | return faction; | ||
| 35 | } | ||
| 36 | } | ||
diff --git a/src/main/java/modele/ArmeeListe.java b/src/main/java/modele/ArmeeListe.java new file mode 100644 index 0000000..7d3f866 --- /dev/null +++ b/src/main/java/modele/ArmeeListe.java | |||
| @@ -0,0 +1,104 @@ | |||
| 1 | package modele; | ||
| 2 | |||
| 3 | import java.util.ArrayList; | ||
| 4 | |||
| 5 | public class ArmeeListe { | ||
| 6 | private int id; | ||
| 7 | private int idArmee; | ||
| 8 | private String nom; | ||
| 9 | private String description; | ||
| 10 | private String data; | ||
| 11 | private ArrayList<Unit> unites = new ArrayList<Unit>(); | ||
| 12 | private ArrayList<String> unit_names = new ArrayList<String>(); | ||
| 13 | |||
| 14 | private int idUtilisateur; | ||
| 15 | |||
| 16 | |||
| 17 | |||
| 18 | public ArmeeListe(String nom, String description, String data) { | ||
| 19 | this.nom = nom; | ||
| 20 | this.description = description; | ||
| 21 | this.data = data; | ||
| 22 | } | ||
| 23 | public ArmeeListe(ArrayList<Unit> unit_list, String nom, String description, String data) { | ||
| 24 | this.unites = unit_list; | ||
| 25 | this.nom = nom; | ||
| 26 | this.description = description; | ||
| 27 | this.data = data; | ||
| 28 | } | ||
| 29 | |||
| 30 | public ArmeeListe(int id, int idArmee, String nom, String description, String data, int idUtilisateur) { | ||
| 31 | this.id = id; | ||
| 32 | this.nom = nom; | ||
| 33 | this.description = description; | ||
| 34 | this.data= data; | ||
| 35 | this.idArmee = idArmee; | ||
| 36 | this.idUtilisateur = idUtilisateur; | ||
| 37 | } | ||
| 38 | |||
| 39 | |||
| 40 | public int getIdListe() { return id; } | ||
| 41 | public int getIdArmee() { return idArmee;} | ||
| 42 | public String getNomListe() { return nom; } | ||
| 43 | public String getDescriptionListe() { return description; } | ||
| 44 | public String getDataListe() { return data; } | ||
| 45 | public ArrayList<String> getUniteListe() { return unit_names; } | ||
| 46 | |||
| 47 | public void setUniteListe(ArrayList<String> unite) { | ||
| 48 | this.unit_names = unite; | ||
| 49 | } | ||
| 50 | |||
| 51 | // getters | ||
| 52 | public int getId() { | ||
| 53 | return id; | ||
| 54 | } | ||
| 55 | public String getName() { | ||
| 56 | return nom; | ||
| 57 | } | ||
| 58 | public void setName(String name) { | ||
| 59 | nom = name; | ||
| 60 | } | ||
| 61 | public String getDescription() { | ||
| 62 | return description; | ||
| 63 | } | ||
| 64 | public void setDescription(String desc) { | ||
| 65 | description = desc; | ||
| 66 | } | ||
| 67 | public String getData() { | ||
| 68 | return data; | ||
| 69 | } | ||
| 70 | public void setData(String data) { | ||
| 71 | this.data = data; | ||
| 72 | } | ||
| 73 | public int getIdUtilisateur() { | ||
| 74 | return idUtilisateur; | ||
| 75 | } | ||
| 76 | |||
| 77 | public ArrayList<Unit> getUnits() { | ||
| 78 | return unites; | ||
| 79 | } | ||
| 80 | public void setUnits(ArrayList<Unit> units) { | ||
| 81 | unites = units; | ||
| 82 | } | ||
| 83 | public String[] getUnitNames() { | ||
| 84 | String[] unit_names = new String[unites.size()]; | ||
| 85 | for(int i = 0; i < unites.size(); i++) { | ||
| 86 | unit_names[i] = unites.get(i).getName(); | ||
| 87 | } | ||
| 88 | return unit_names; | ||
| 89 | } | ||
| 90 | public void addUnit(Unit unit) { | ||
| 91 | unites.add(unit); | ||
| 92 | } | ||
| 93 | public void removeUnit(Unit unit) { | ||
| 94 | unites.remove(unit); | ||
| 95 | } | ||
| 96 | public void setNom(String nom) { | ||
| 97 | this.nom = nom; | ||
| 98 | } | ||
| 99 | |||
| 100 | public String toString() { | ||
| 101 | return "Liste ID: " + id + ", Nom: " + nom + ", Description: " + description + | ||
| 102 | ", Data: " + data + ", unite: " + unit_names; | ||
| 103 | } | ||
| 104 | } \ No newline at end of file | ||
diff --git a/src/main/java/modele/Bouton.java b/src/main/java/modele/Bouton.java new file mode 100644 index 0000000..4d5c911 --- /dev/null +++ b/src/main/java/modele/Bouton.java | |||
| @@ -0,0 +1,31 @@ | |||
| 1 | package modele; | ||
| 2 | |||
| 3 | import javafx.event.ActionEvent; | ||
| 4 | import javafx.event.EventHandler; | ||
| 5 | import javafx.scene.Node; | ||
| 6 | import javafx.scene.control.Button; | ||
| 7 | |||
| 8 | public class Bouton extends Button{ | ||
| 9 | |||
| 10 | public Bouton() { | ||
| 11 | super(); | ||
| 12 | // TODO Auto-generated constructor stub | ||
| 13 | } | ||
| 14 | |||
| 15 | public Bouton(String text, Node graphic) { | ||
| 16 | super(text, graphic); | ||
| 17 | // TODO Auto-generated constructor stub | ||
| 18 | } | ||
| 19 | |||
| 20 | public Bouton(String text) { | ||
| 21 | super(text); | ||
| 22 | // TODO Auto-generated constructor stub | ||
| 23 | } | ||
| 24 | |||
| 25 | |||
| 26 | public Bouton setOnAction2(EventHandler<ActionEvent> value) { | ||
| 27 | super.setOnAction(value); | ||
| 28 | return this; | ||
| 29 | |||
| 30 | } | ||
| 31 | } | ||
diff --git a/src/main/java/modele/Calcul.java b/src/main/java/modele/Calcul.java new file mode 100644 index 0000000..0ae1832 --- /dev/null +++ b/src/main/java/modele/Calcul.java | |||
| @@ -0,0 +1,302 @@ | |||
| 1 | package modele; | ||
| 2 | |||
| 3 | public class Calcul { | ||
| 4 | private int[] tabdegat1; | ||
| 5 | private float degat_moyen1; | ||
| 6 | private float mort_moyen1; | ||
| 7 | private int[] tabmort1; | ||
| 8 | |||
| 9 | |||
| 10 | public Calcul(int[] tabdegat1, float degat_moyen1, float mort_moyen1,int[] tabmort1) { | ||
| 11 | super(); | ||
| 12 | this.tabdegat1 = tabdegat1; | ||
| 13 | this.degat_moyen1 = degat_moyen1; | ||
| 14 | this.mort_moyen1 = mort_moyen1; | ||
| 15 | this.tabmort1 = tabmort1; | ||
| 16 | } | ||
| 17 | |||
| 18 | // getter set setter | ||
| 19 | public int[] getTabdegat1() { | ||
| 20 | return tabdegat1; | ||
| 21 | } | ||
| 22 | public void setTabdegat1(int[] tabdegat1) { | ||
| 23 | this.tabdegat1 = tabdegat1; | ||
| 24 | } | ||
| 25 | public float getDegat_moyen1() { | ||
| 26 | return degat_moyen1; | ||
| 27 | } | ||
| 28 | public void setDegat_moyen1(float degat_moyen1) { | ||
| 29 | this.degat_moyen1 = degat_moyen1; | ||
| 30 | } | ||
| 31 | public float getMort_moyen1() { | ||
| 32 | return mort_moyen1; | ||
| 33 | } | ||
| 34 | public void setMort_moyen1(float mort_moyen1) { | ||
| 35 | this.mort_moyen1 = mort_moyen1; | ||
| 36 | } | ||
| 37 | public int[] getTabmort1() { | ||
| 38 | return tabmort1; | ||
| 39 | } | ||
| 40 | public void setTabmort1(int[] tabmort1) { | ||
| 41 | this.tabmort1 = tabmort1; | ||
| 42 | } | ||
| 43 | |||
| 44 | // 1er jet de dé : jet pour toucher une figurine , résultat en fonction de CC ou CT | ||
| 45 | public static boolean jet_de_touche(boolean jet,int C){ | ||
| 46 | // simulation lancer de dé | ||
| 47 | int d1 = (int) ((Math.random() * (7 - 1)) + 1); | ||
| 48 | switch(d1){ | ||
| 49 | // si 1 echec critique | ||
| 50 | case 1 : | ||
| 51 | jet=false; | ||
| 52 | break; | ||
| 53 | // si 6 reussite critique | ||
| 54 | case 6 : | ||
| 55 | jet=true; | ||
| 56 | break; | ||
| 57 | // comparaison du dé avec CC ou CT | ||
| 58 | default : | ||
| 59 | if( d1 >= C){ | ||
| 60 | jet=true; | ||
| 61 | } | ||
| 62 | } | ||
| 63 | // return booléen pour continuer ou non attaque | ||
| 64 | return jet; | ||
| 65 | } | ||
| 66 | |||
| 67 | // 2eme jet de dé : jet pour blesser une figurine , résultat en fonction de force de fig attaquante et de endurance de figurine attaquée | ||
| 68 | public static boolean jet_de_blessure (boolean jet,int fo,int end){ | ||
| 69 | // simulation lancer de dé | ||
| 70 | int d2 = (int) ((Math.random() * (7 - 1)) + 1); | ||
| 71 | |||
| 72 | switch(d2){ | ||
| 73 | // si 1 echec critique | ||
| 74 | case 1 : | ||
| 75 | jet=false; | ||
| 76 | break; | ||
| 77 | // si 6 reussite critique | ||
| 78 | case 6 : | ||
| 79 | jet=true; | ||
| 80 | break; | ||
| 81 | default : | ||
| 82 | //Comparaison entre force et endurance pour savoir si attaque blesse | ||
| 83 | if(fo >2*end) { | ||
| 84 | if(d2>=2) { | ||
| 85 | jet = true; | ||
| 86 | } | ||
| 87 | } | ||
| 88 | if(fo>end && fo<2*end) { | ||
| 89 | if(d2>=3) { | ||
| 90 | jet = true; | ||
| 91 | } | ||
| 92 | } | ||
| 93 | if(fo==end) { | ||
| 94 | if(d2>=4) { | ||
| 95 | jet = true; | ||
| 96 | } | ||
| 97 | } | ||
| 98 | if(fo>0.5*end && fo<end) { | ||
| 99 | if(d2>=5) { | ||
| 100 | jet = true; | ||
| 101 | } | ||
| 102 | } | ||
| 103 | if(fo <=0.5*(float)end) { | ||
| 104 | if(d2>=6) { | ||
| 105 | jet = true; | ||
| 106 | } | ||
| 107 | } | ||
| 108 | |||
| 109 | } | ||
| 110 | // return booléen pour continuer ou non attaque | ||
| 111 | return jet; | ||
| 112 | } | ||
| 113 | |||
| 114 | // fonction pour determiner le nbr d'attaque d'une arme | ||
| 115 | public static int chgt_a (String a){ | ||
| 116 | int attaque =0; | ||
| 117 | int d1 = (int) ((Math.random() * (7 - 1)) + 1); | ||
| 118 | int d2 = (int) ((Math.random() * (4 - 1)) + 1); | ||
| 119 | switch(a) { | ||
| 120 | case "D6": | ||
| 121 | attaque = d1; | ||
| 122 | break; | ||
| 123 | case "D6+1": | ||
| 124 | attaque = d1+1; | ||
| 125 | //System.out.println("test"); | ||
| 126 | break; | ||
| 127 | case "D6+2": | ||
| 128 | attaque = d1+2; | ||
| 129 | break; | ||
| 130 | case "D6+3": | ||
| 131 | attaque = d1+3; | ||
| 132 | break; | ||
| 133 | case "D6+4": | ||
| 134 | attaque = d1+4; | ||
| 135 | break; | ||
| 136 | case "D3": | ||
| 137 | attaque = d2; | ||
| 138 | break; | ||
| 139 | default : | ||
| 140 | attaque = Integer.parseInt(a); | ||
| 141 | } | ||
| 142 | return attaque; | ||
| 143 | } | ||
| 144 | |||
| 145 | // fonction pour determiner le nbr de dégats d'une arme | ||
| 146 | public static int chgt_d (String d){ | ||
| 147 | int degat =0; | ||
| 148 | int d1 = (int) ((Math.random() * (7 - 1)) + 1); | ||
| 149 | int d2 = (int) ((Math.random() * (4 - 1)) + 1); | ||
| 150 | int d3 = (int) ((Math.random() * (9 - 1)) + 1); | ||
| 151 | switch(d) { | ||
| 152 | case "D8": | ||
| 153 | degat = d3; | ||
| 154 | break; | ||
| 155 | case "D6": | ||
| 156 | degat = d1; | ||
| 157 | break; | ||
| 158 | case "D6+1": | ||
| 159 | degat = d1+1; | ||
| 160 | break; | ||
| 161 | case "D6+2": | ||
| 162 | degat = d1+2; | ||
| 163 | break; | ||
| 164 | case "D6+3": | ||
| 165 | degat = d1+3; | ||
| 166 | break; | ||
| 167 | case "D6+4": | ||
| 168 | degat = d1+4; | ||
| 169 | break; | ||
| 170 | case "D3": | ||
| 171 | degat = d2; | ||
| 172 | break; | ||
| 173 | default : | ||
| 174 | degat = Integer.parseInt(d); | ||
| 175 | } | ||
| 176 | return degat; | ||
| 177 | } | ||
| 178 | |||
| 179 | // 2eme jet de dé : jet de sauvegarde , pour savoir si l'armure d'une figurine la protège d'une blessure | ||
| 180 | public static boolean jet_de_sauvegarde (boolean block,int pa,int sv){ | ||
| 181 | // simulation du jet de dé | ||
| 182 | int d3 = (int) ((Math.random() * (7 - 1)) + 1); | ||
| 183 | switch(d3) { | ||
| 184 | //echec critique la figurine adverse n'a pas réussie à se protéger | ||
| 185 | case 1: | ||
| 186 | block = false; | ||
| 187 | default : | ||
| 188 | //comparaison entre pénétration d'armure et sauvegarde | ||
| 189 | if ( d3 + pa < sv ){ | ||
| 190 | block = false; | ||
| 191 | } | ||
| 192 | } | ||
| 193 | //// return booléen pour finaliser ou non attaque | ||
| 194 | return block; | ||
| 195 | } | ||
| 196 | |||
| 197 | // fonction simulant des battailes entre 2 unités | ||
| 198 | public static Calcul bataille(modele.Unit u1, modele.Unit u2){ | ||
| 199 | |||
| 200 | // Déclaration des variables | ||
| 201 | |||
| 202 | int complet_degat = 0; | ||
| 203 | float degat_moyen; | ||
| 204 | float mort_moyen = 0; | ||
| 205 | boolean dflag = false; | ||
| 206 | int[] tabdegat = new int[50]; | ||
| 207 | int[] tabmort = new int[50]; | ||
| 208 | |||
| 209 | // boucle simulant 10 000 batailles | ||
| 210 | for (int k=0;k<10000;k++){ | ||
| 211 | |||
| 212 | int sum_degat = 0; | ||
| 213 | int adv = 0; | ||
| 214 | int pvE=u2.getFigurines().get(adv).getHP(); | ||
| 215 | int mort = 0; | ||
| 216 | |||
| 217 | // boucle parcourant les figurines d'une unité | ||
| 218 | for (int j=0; j<u1.getFigurines().size();j++){ | ||
| 219 | // si figurine non morte | ||
| 220 | if(u1.getFigurines().get(j).getHP()>0) { | ||
| 221 | int attaque = chgt_a(u1.getFigurines().get(j).getSelectedWeapon().getA()); | ||
| 222 | |||
| 223 | // Condition permettant d'attaquer une nouvelle figurine | ||
| 224 | while(pvE <=0 && adv+1<u2.getFigurines().size()) { | ||
| 225 | adv=adv+1; | ||
| 226 | pvE=u2.getFigurines().get(adv).getHP(); | ||
| 227 | |||
| 228 | } | ||
| 229 | |||
| 230 | // boucle correspondant au nbr d'attaques par armes | ||
| 231 | for(int i=0 ;i<attaque;i++ ){ | ||
| 232 | dflag = false; | ||
| 233 | boolean jet1=false; | ||
| 234 | boolean jet2=false; | ||
| 235 | boolean block=true; | ||
| 236 | |||
| 237 | // fonction pour jet de touche | ||
| 238 | jet1=jet_de_touche(jet1,(u1.getFigurines().get(j).getSelectedWeapon().getC())); | ||
| 239 | |||
| 240 | // si attaque touche | ||
| 241 | if(jet1==true){ | ||
| 242 | // fonction pour jet de blessure | ||
| 243 | jet2=jet_de_blessure(jet2,u1.getFigurines().get(j).getSelectedWeapon().getF(),u2.getFigurines().get(adv).getE()); | ||
| 244 | } | ||
| 245 | |||
| 246 | // si blessure | ||
| 247 | if(jet2==true){ | ||
| 248 | block=jet_de_sauvegarde(block,u1.getFigurines().get(j).getSelectedWeapon().getPA(),u2.getFigurines().get(adv).getSV()); | ||
| 249 | |||
| 250 | // si jet de sauvegarde echec et fig adverse à des HP | ||
| 251 | if(block==false && pvE >0){ | ||
| 252 | |||
| 253 | int degat= chgt_d((u1.getFigurines().get(j).getSelectedWeapon().getD())); | ||
| 254 | pvE=pvE - degat ; | ||
| 255 | |||
| 256 | // Calcul des dégats effectués par une attaque | ||
| 257 | if(pvE<0) { | ||
| 258 | sum_degat = sum_degat + degat + pvE; | ||
| 259 | complet_degat = complet_degat +degat +pvE; | ||
| 260 | } | ||
| 261 | else { | ||
| 262 | sum_degat = sum_degat + degat; | ||
| 263 | complet_degat = degat+complet_degat; | ||
| 264 | } | ||
| 265 | |||
| 266 | // booléen pour indiquer une mort possible | ||
| 267 | dflag = true; | ||
| 268 | } | ||
| 269 | |||
| 270 | // compteur du nbr de mort | ||
| 271 | if(pvE <=0 && dflag == true ) { | ||
| 272 | mort = mort+1; | ||
| 273 | mort_moyen = mort_moyen+1; | ||
| 274 | } | ||
| 275 | } | ||
| 276 | } | ||
| 277 | } | ||
| 278 | // si fig mort changement de prochaine cible | ||
| 279 | if(pvE <=0 ) { | ||
| 280 | if (adv+1<u2.getFigurines().size()){ | ||
| 281 | adv=adv+1; | ||
| 282 | pvE=u2.getFigurines().get(adv).getHP(); | ||
| 283 | |||
| 284 | } | ||
| 285 | } | ||
| 286 | } | ||
| 287 | // compteurs des sommes des dégats et du nbr de mort par bataille | ||
| 288 | tabdegat[sum_degat] ++; | ||
| 289 | tabmort[mort] ++; | ||
| 290 | } | ||
| 291 | |||
| 292 | //calcul des degat et mort moyen | ||
| 293 | degat_moyen =(float)complet_degat/10000; | ||
| 294 | mort_moyen = (float)mort_moyen/10000; | ||
| 295 | |||
| 296 | // Instanciation de Calucl (données pour histogramme ) | ||
| 297 | Calcul c1 = new Calcul(tabdegat,degat_moyen,mort_moyen,tabmort); | ||
| 298 | return c1; | ||
| 299 | } | ||
| 300 | |||
| 301 | } | ||
| 302 | |||
diff --git a/src/main/java/modele/Evenement.java b/src/main/java/modele/Evenement.java new file mode 100644 index 0000000..a3dd8bd --- /dev/null +++ b/src/main/java/modele/Evenement.java | |||
| @@ -0,0 +1,48 @@ | |||
| 1 | package modele; | ||
| 2 | |||
| 3 | public class Evenement{ | ||
| 4 | |||
| 5 | private String nom_evenement; | ||
| 6 | private String nom_image; | ||
| 7 | private String descritption_evenement; | ||
| 8 | private String date_evenement; | ||
| 9 | |||
| 10 | public Evenement(String nom_evt, String nom_img,String desc, String date) { | ||
| 11 | this.nom_evenement = nom_evt; | ||
| 12 | this.nom_image = nom_img; | ||
| 13 | this.descritption_evenement = desc; | ||
| 14 | this.date_evenement = date; | ||
| 15 | } | ||
| 16 | |||
| 17 | public String getNom_evenement() { | ||
| 18 | return nom_evenement; | ||
| 19 | } | ||
| 20 | |||
| 21 | public String getNom_image() { | ||
| 22 | return nom_image; | ||
| 23 | } | ||
| 24 | |||
| 25 | public String getData_evenement() { | ||
| 26 | return date_evenement; | ||
| 27 | } | ||
| 28 | |||
| 29 | public void setNom_evenement(String nom_evenement) { | ||
| 30 | this.nom_evenement = nom_evenement; | ||
| 31 | } | ||
| 32 | |||
| 33 | public void setNom_image(String nom_image) { | ||
| 34 | this.nom_image = nom_image; | ||
| 35 | } | ||
| 36 | |||
| 37 | public void setDescritption_evenement(String descritption_evenement) { | ||
| 38 | this.descritption_evenement = descritption_evenement; | ||
| 39 | } | ||
| 40 | |||
| 41 | public void setDate_evenement(String date_evenement) { | ||
| 42 | this.date_evenement = date_evenement; | ||
| 43 | } | ||
| 44 | |||
| 45 | public String getDescritption_evenement() { | ||
| 46 | return descritption_evenement; | ||
| 47 | } | ||
| 48 | } \ No newline at end of file | ||
diff --git a/src/main/java/modele/Faction.java b/src/main/java/modele/Faction.java new file mode 100644 index 0000000..04e2af8 --- /dev/null +++ b/src/main/java/modele/Faction.java | |||
| @@ -0,0 +1,19 @@ | |||
| 1 | package modele; | ||
| 2 | |||
| 3 | public class Faction { | ||
| 4 | |||
| 5 | private String nom; | ||
| 6 | |||
| 7 | public Faction(String nom) { | ||
| 8 | this.nom = nom; | ||
| 9 | } | ||
| 10 | |||
| 11 | public String getNom() { | ||
| 12 | return nom; | ||
| 13 | } | ||
| 14 | |||
| 15 | @Override | ||
| 16 | public String toString() { | ||
| 17 | return "" + nom + ""; | ||
| 18 | } | ||
| 19 | } | ||
diff --git a/src/main/java/modele/Figurine.java b/src/main/java/modele/Figurine.java new file mode 100644 index 0000000..1e517b8 --- /dev/null +++ b/src/main/java/modele/Figurine.java | |||
| @@ -0,0 +1,158 @@ | |||
| 1 | package modele; | ||
| 2 | |||
| 3 | import java.util.ArrayList; | ||
| 4 | import java.util.HashMap; | ||
| 5 | |||
| 6 | public class Figurine { | ||
| 7 | ArrayList<Arme> armes; | ||
| 8 | Arme selected_weapon; | ||
| 9 | |||
| 10 | ArrayList<Aptitude> aptitudes; | ||
| 11 | HashMap<String, Aptitude> selectedAptitudes = new HashMap<String, Aptitude>(); | ||
| 12 | |||
| 13 | String nom; | ||
| 14 | String logoChemin; | ||
| 15 | String M; | ||
| 16 | int E; | ||
| 17 | int SV; | ||
| 18 | int HP; | ||
| 19 | int HP_max; | ||
| 20 | int CD; | ||
| 21 | int CO; | ||
| 22 | |||
| 23 | public Figurine(ArrayList<Arme> armes, ArrayList<Aptitude> aptitudes, String nom, String logoChemin, String m, int e, int sV, int hP, int cD, int cO) { | ||
| 24 | //super(); // inutile, Figurine n'a pas de parent | ||
| 25 | |||
| 26 | this.armes = armes; | ||
| 27 | if(armes.size() > 0) { | ||
| 28 | selected_weapon = armes.get(0); // arme par défaut | ||
| 29 | } | ||
| 30 | this.aptitudes = aptitudes; | ||
| 31 | |||
| 32 | this.nom = nom; | ||
| 33 | this.logoChemin = logoChemin; | ||
| 34 | M = m; | ||
| 35 | E = e; | ||
| 36 | SV = sV; | ||
| 37 | HP = hP; | ||
| 38 | HP_max = hP; | ||
| 39 | CD = cD; | ||
| 40 | CO = cO; | ||
| 41 | } | ||
| 42 | |||
| 43 | public Figurine(String nom_figurine, int E, int SV, int HP,ArrayList<Arme> l1) { | ||
| 44 | this.nom = nom_figurine; | ||
| 45 | this.E = E; | ||
| 46 | this.SV = SV; | ||
| 47 | this.HP = HP; | ||
| 48 | this.armes = l1; | ||
| 49 | } | ||
| 50 | |||
| 51 | //renvoi un dico avec en clé les noms des stats des armes et en valeurs une liste de valeur de toute les armes | ||
| 52 | public HashMap<String,ArrayList<Integer>> statAtk(){ | ||
| 53 | HashMap<String,ArrayList<Integer>> liste = new HashMap<String, ArrayList<Integer>>(); | ||
| 54 | ArrayList<Integer> stats = new ArrayList<Integer>(); | ||
| 55 | |||
| 56 | ArrayList<Integer> A = new ArrayList<Integer>(); | ||
| 57 | ArrayList<Integer> F = new ArrayList<Integer>(); | ||
| 58 | ArrayList<Integer> PA = new ArrayList<Integer>(); | ||
| 59 | ArrayList<Integer> D = new ArrayList<Integer>(); | ||
| 60 | |||
| 61 | for (Arme arme : armes) { | ||
| 62 | stats = arme.statsAtk(); | ||
| 63 | A.add(stats.get(0)); | ||
| 64 | F.add(stats.get(1)); | ||
| 65 | PA.add(stats.get(2)); | ||
| 66 | D.add(stats.get(3)); | ||
| 67 | } | ||
| 68 | liste.put("A", A); | ||
| 69 | liste.put("F", F); | ||
| 70 | liste.put("PA", PA); | ||
| 71 | liste.put("D", D); | ||
| 72 | |||
| 73 | return liste; | ||
| 74 | } | ||
| 75 | // public void updateHP(int dommage) { | ||
| 76 | // this.HP +=dommage; | ||
| 77 | // } | ||
| 78 | public HashMap<String,Integer> defense(){ | ||
| 79 | HashMap<String,Integer> liste = new HashMap<String,Integer>(); | ||
| 80 | liste.put("E", E); | ||
| 81 | liste.put("SV", SV); | ||
| 82 | return liste; | ||
| 83 | } | ||
| 84 | |||
| 85 | |||
| 86 | public ArrayList<Arme> getArmes() { | ||
| 87 | return armes; | ||
| 88 | } | ||
| 89 | public Arme getWeaponByName(String name) { | ||
| 90 | for(Arme weapon : armes) { | ||
| 91 | if(weapon.getNom() == name) { | ||
| 92 | return weapon; | ||
| 93 | } | ||
| 94 | } | ||
| 95 | return armes.get(0); // arme par défaut si aucune ne correspond | ||
| 96 | } | ||
| 97 | public Arme getSelectedWeapon() { | ||
| 98 | return selected_weapon; | ||
| 99 | } | ||
| 100 | public void setWeapon(Arme weapon) { | ||
| 101 | selected_weapon = weapon; | ||
| 102 | } | ||
| 103 | |||
| 104 | public ArrayList<Aptitude> getAptitudes() { | ||
| 105 | return aptitudes; | ||
| 106 | } | ||
| 107 | public HashMap<String, Aptitude> getSelectedAptitudes() { | ||
| 108 | return selectedAptitudes; | ||
| 109 | } | ||
| 110 | // public void setSelectedAptitudes(HashMap<String, Aptitude> aptitudes) { | ||
| 111 | // selectedAptitudes = aptitudes; | ||
| 112 | // } | ||
| 113 | |||
| 114 | public String getNom() { | ||
| 115 | return nom; | ||
| 116 | } | ||
| 117 | |||
| 118 | public String getLogoChemin() { | ||
| 119 | return logoChemin; | ||
| 120 | } | ||
| 121 | |||
| 122 | public String getM() { | ||
| 123 | return M; | ||
| 124 | } | ||
| 125 | |||
| 126 | public int getE() { | ||
| 127 | return E; | ||
| 128 | } | ||
| 129 | |||
| 130 | public int getSV() { | ||
| 131 | return SV; | ||
| 132 | } | ||
| 133 | |||
| 134 | public int getHP() { | ||
| 135 | return HP; | ||
| 136 | } | ||
| 137 | public int getHPMax() { | ||
| 138 | return HP_max; | ||
| 139 | } | ||
| 140 | |||
| 141 | public int getCD() { | ||
| 142 | return CD; | ||
| 143 | } | ||
| 144 | |||
| 145 | public int getCO() { | ||
| 146 | return CO; | ||
| 147 | } | ||
| 148 | |||
| 149 | |||
| 150 | public void setHP(int hP) { | ||
| 151 | HP = hP; | ||
| 152 | } | ||
| 153 | |||
| 154 | @Override | ||
| 155 | public String toString() { | ||
| 156 | return "" + nom + ""; | ||
| 157 | } | ||
| 158 | } | ||
diff --git a/src/main/java/modele/Unit.java b/src/main/java/modele/Unit.java new file mode 100644 index 0000000..11b51d9 --- /dev/null +++ b/src/main/java/modele/Unit.java | |||
| @@ -0,0 +1,96 @@ | |||
| 1 | package modele; | ||
| 2 | |||
| 3 | import java.util.ArrayList; | ||
| 4 | import java.util.HashMap; | ||
| 5 | |||
| 6 | |||
| 7 | |||
| 8 | public class Unit { | ||
| 9 | |||
| 10 | private ArrayList<Figurine> figurines; | ||
| 11 | private HashMap<String, ArrayList<Figurine>> identical_figs = new HashMap<String, ArrayList<Figurine>>(); | ||
| 12 | private int id; | ||
| 13 | private String nom; | ||
| 14 | private int points; | ||
| 15 | private String logo; | ||
| 16 | private Armee armee; | ||
| 17 | |||
| 18 | public Unit(ArrayList<Figurine> figurines, String nom, int points, String logo, Armee armee) { | ||
| 19 | this.figurines = figurines; | ||
| 20 | this.makeIdenticalFigsGroups(); | ||
| 21 | this.nom = nom; | ||
| 22 | this.points = points; | ||
| 23 | this.logo = logo; | ||
| 24 | this.armee = armee; | ||
| 25 | } | ||
| 26 | public Unit(ArrayList<Figurine> figurines,int id, String nom, int points,String logo, Armee armee) { | ||
| 27 | this.id = id; | ||
| 28 | this.figurines = figurines; | ||
| 29 | this.nom = nom; | ||
| 30 | this.logo = logo; | ||
| 31 | this.points = points; | ||
| 32 | this.armee = armee; | ||
| 33 | } | ||
| 34 | |||
| 35 | // bientôt inutile | ||
| 36 | public Unit(String nom_unit,ArrayList<Figurine> list_unit) { | ||
| 37 | this.nom = nom_unit; | ||
| 38 | this.figurines = list_unit; | ||
| 39 | } | ||
| 40 | |||
| 41 | // getters | ||
| 42 | public ArrayList<Figurine> getFigurines() { | ||
| 43 | return figurines; | ||
| 44 | } | ||
| 45 | public HashMap<String, ArrayList<Figurine>> getIdenticalFigsGroups(){ | ||
| 46 | return identical_figs; | ||
| 47 | } | ||
| 48 | |||
| 49 | // est exécuté dès qu'on touche au slider | ||
| 50 | public int getAliveFigsOfAGroup(String group_name) { | ||
| 51 | int nb = 0; | ||
| 52 | for(Figurine fig : identical_figs.get(group_name)) | ||
| 53 | { | ||
| 54 | if(fig.getHP() > 0) { | ||
| 55 | nb++; | ||
| 56 | } | ||
| 57 | } | ||
| 58 | return nb; | ||
| 59 | } | ||
| 60 | |||
| 61 | public int getId() { | ||
| 62 | return id; | ||
| 63 | } | ||
| 64 | public String getName() { | ||
| 65 | return nom; | ||
| 66 | } | ||
| 67 | public int getPoints() { | ||
| 68 | return points; | ||
| 69 | } | ||
| 70 | public String getLogo() { | ||
| 71 | return nom; | ||
| 72 | } | ||
| 73 | public Armee getArmee() { | ||
| 74 | return armee; | ||
| 75 | } | ||
| 76 | |||
| 77 | public void setFigurine(ArrayList<Figurine> liste) { | ||
| 78 | figurines = liste; | ||
| 79 | } | ||
| 80 | |||
| 81 | private void makeIdenticalFigsGroups() { | ||
| 82 | for(Figurine fig : figurines) | ||
| 83 | { | ||
| 84 | if(!identical_figs.containsKey(fig.getNom())) // si nouveau type de figurines | ||
| 85 | { | ||
| 86 | identical_figs.put(fig.getNom(), new ArrayList<Figurine>()); // création d'uné paire clé/liste dans la hashmap | ||
| 87 | } | ||
| 88 | identical_figs.get(fig.getNom()).add(fig); // récupérer la liste correspondante à la clé et ajouter la figurine | ||
| 89 | } | ||
| 90 | } | ||
| 91 | |||
| 92 | @Override | ||
| 93 | public String toString() { | ||
| 94 | return "" + nom + ""; | ||
| 95 | } | ||
| 96 | } | ||
diff --git a/src/main/java/modele/User.java b/src/main/java/modele/User.java new file mode 100644 index 0000000..a9a155d --- /dev/null +++ b/src/main/java/modele/User.java | |||
| @@ -0,0 +1,83 @@ | |||
| 1 | package modele; | ||
| 2 | |||
| 3 | import java.util.ArrayList; | ||
| 4 | |||
| 5 | public class User { | ||
| 6 | |||
| 7 | private ArrayList<ArmeeListe> listes = new ArrayList<ArmeeListe>(); | ||
| 8 | private String nom; | ||
| 9 | private String mdp; | ||
| 10 | private String email; | ||
| 11 | private int id; | ||
| 12 | private String role; | ||
| 13 | |||
| 14 | public User( String nom, int id2, String role2) { | ||
| 15 | this.nom = nom; | ||
| 16 | this.id=id2; | ||
| 17 | this.role=role2; | ||
| 18 | } | ||
| 19 | |||
| 20 | public User(ArrayList<ArmeeListe> listes, String nom, String mdp, String email, int id,String role) { | ||
| 21 | this.listes = listes; | ||
| 22 | this.nom = nom; | ||
| 23 | this.mdp = mdp; | ||
| 24 | this.email = email; | ||
| 25 | this.id = id; | ||
| 26 | this.role=role; | ||
| 27 | } | ||
| 28 | |||
| 29 | public int getId() { | ||
| 30 | return id; | ||
| 31 | } | ||
| 32 | public void setId(int id) { | ||
| 33 | this.id = id; | ||
| 34 | } | ||
| 35 | |||
| 36 | public String getRole() { | ||
| 37 | return role; | ||
| 38 | } | ||
| 39 | public void setRole(String role) { | ||
| 40 | this.role = role; | ||
| 41 | } | ||
| 42 | |||
| 43 | public ArrayList<ArmeeListe> getListes() { | ||
| 44 | return listes; | ||
| 45 | } | ||
| 46 | public void setListes(ArrayList<ArmeeListe> listes) { | ||
| 47 | this.listes = listes; | ||
| 48 | } | ||
| 49 | public String[] getListNames() { | ||
| 50 | String[] list_names = new String[listes.size()]; | ||
| 51 | for(int i = 0; i < listes.size(); i++) | ||
| 52 | { | ||
| 53 | list_names[i] = listes.get(i).getName(); | ||
| 54 | } | ||
| 55 | return list_names; | ||
| 56 | } | ||
| 57 | |||
| 58 | public String getNom() { | ||
| 59 | return nom; | ||
| 60 | } | ||
| 61 | public void setNom(String nom) { | ||
| 62 | this.nom = nom; | ||
| 63 | } | ||
| 64 | public String getMdp() { | ||
| 65 | return mdp; | ||
| 66 | } | ||
| 67 | public void setMdp(String mdp) { | ||
| 68 | this.mdp = mdp; | ||
| 69 | } | ||
| 70 | public String getEmail() { | ||
| 71 | return email; | ||
| 72 | } | ||
| 73 | public void setEmail(String email) { | ||
| 74 | this.email = email; | ||
| 75 | } | ||
| 76 | |||
| 77 | public void addArmee(ArmeeListe armee) { | ||
| 78 | listes.add(armee); | ||
| 79 | } | ||
| 80 | public void removeArmee(ArmeeListe armee) { | ||
| 81 | listes.remove(armee); | ||
| 82 | } | ||
| 83 | } | ||
diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java new file mode 100644 index 0000000..f429622 --- /dev/null +++ b/src/main/java/module-info.java | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | module ppe_javafx { | ||
| 2 | requires javafx.controls; | ||
| 3 | requires java.sql; | ||
| 4 | requires org.mariadb.jdbc; | ||
| 5 | exports application; | ||
| 6 | } | ||
diff --git a/src/main/java/vue/AfficheAccueil.java b/src/main/java/vue/AfficheAccueil.java new file mode 100644 index 0000000..957a249 --- /dev/null +++ b/src/main/java/vue/AfficheAccueil.java | |||
| @@ -0,0 +1,108 @@ | |||
| 1 | package vue; | ||
| 2 | |||
| 3 | import java.util.ArrayList; | ||
| 4 | |||
| 5 | import controlleur.Connexion; | ||
| 6 | import controlleur.EvenementController; | ||
| 7 | import javafx.geometry.Pos; | ||
| 8 | import javafx.scene.Scene; | ||
| 9 | import javafx.scene.control.Button; | ||
| 10 | import javafx.scene.control.Label; | ||
| 11 | import javafx.scene.image.Image; | ||
| 12 | import javafx.scene.image.ImageView; | ||
| 13 | import javafx.scene.layout.HBox; | ||
| 14 | import javafx.scene.layout.Priority; | ||
| 15 | import javafx.scene.layout.VBox; | ||
| 16 | import javafx.scene.text.Font; | ||
| 17 | import javafx.stage.Stage; | ||
| 18 | import modele.Evenement; | ||
| 19 | import modele.User; | ||
| 20 | |||
| 21 | public class AfficheAccueil { | ||
| 22 | |||
| 23 | private static VBox vEvt; | ||
| 24 | |||
| 25 | public static void affiche(Stage primaryStage,User session) { | ||
| 26 | |||
| 27 | |||
| 28 | VBox root = new VBox(); | ||
| 29 | Scene scene = new Scene(root,800,600); | ||
| 30 | |||
| 31 | AfficheTopMenu menu = new AfficheTopMenu(primaryStage,session); | ||
| 32 | //AfficheTopMenu.setHgrow(root, Priority.ALWAYS); | ||
| 33 | |||
| 34 | |||
| 35 | vEvt = AfficheEvenement.NewAfficheEvenement(primaryStage, session); | ||
| 36 | |||
| 37 | root.getChildren().add(menu); | ||
| 38 | |||
| 39 | |||
| 40 | |||
| 41 | Label titre = new Label("StatHammer"); | ||
| 42 | VBox cadre = new VBox(); | ||
| 43 | VBox cadreImage = new VBox(); | ||
| 44 | HBox capsule = new HBox(); | ||
| 45 | |||
| 46 | Button simulation = new Button("SIMULATION"); | ||
| 47 | Button creeListe = new Button("CREER LISTE"); | ||
| 48 | Button gererListe = new Button("GERER LISTE"); | ||
| 49 | /* | ||
| 50 | Image accueil = new Image("images/accueil.jpg"); | ||
| 51 | ImageView iv1 = new ImageView(); | ||
| 52 | iv1.setImage(accueil); | ||
| 53 | iv1.setFitWidth(700); | ||
| 54 | iv1.setPreserveRatio(true); | ||
| 55 | iv1.setSmooth(true); | ||
| 56 | iv1.setCache(true); | ||
| 57 | */ | ||
| 58 | |||
| 59 | |||
| 60 | |||
| 61 | titre.setFont(Font.font(32)); | ||
| 62 | titre.setPrefHeight(150); | ||
| 63 | |||
| 64 | creeListe.setPrefWidth(200); | ||
| 65 | creeListe.setPrefHeight(50); | ||
| 66 | |||
| 67 | simulation.setPrefWidth(200); | ||
| 68 | simulation.setPrefHeight(50); | ||
| 69 | |||
| 70 | gererListe.setPrefWidth(200); | ||
| 71 | gererListe.setPrefHeight(50); | ||
| 72 | |||
| 73 | root.getChildren().add(titre); | ||
| 74 | root.getChildren().add(vEvt); | ||
| 75 | root.getChildren().add(capsule); | ||
| 76 | |||
| 77 | |||
| 78 | capsule.getChildren().add(cadreImage); | ||
| 79 | capsule.getChildren().add(cadre); | ||
| 80 | |||
| 81 | |||
| 82 | cadre.setPrefSize(300, 800); | ||
| 83 | cadre.setAlignment(Pos.CENTER); | ||
| 84 | |||
| 85 | /* | ||
| 86 | cadreImage.setPrefSize(900, 800); | ||
| 87 | cadreImage.setAlignment(Pos.CENTER); | ||
| 88 | |||
| 89 | cadreImage.getChildren().add(iv1);*/ | ||
| 90 | /*cadre.getChildren().add(simulation); | ||
| 91 | cadre.getChildren().add(creeListe); | ||
| 92 | cadre.getChildren().add(gererListe); | ||
| 93 | |||
| 94 | |||
| 95 | |||
| 96 | |||
| 97 | |||
| 98 | simulation.setOnAction(e -> { | ||
| 99 | primaryStage.close(); | ||
| 100 | AfficheSimulation.affiche(primaryStage); | ||
| 101 | |||
| 102 | }); | ||
| 103 | */ | ||
| 104 | root.setAlignment(Pos.TOP_CENTER); | ||
| 105 | primaryStage.setScene(scene); | ||
| 106 | primaryStage.show(); | ||
| 107 | } | ||
| 108 | } \ No newline at end of file | ||
diff --git a/src/main/java/vue/AfficheAdmin.java b/src/main/java/vue/AfficheAdmin.java new file mode 100644 index 0000000..565a18a --- /dev/null +++ b/src/main/java/vue/AfficheAdmin.java | |||
| @@ -0,0 +1,151 @@ | |||
| 1 | package vue; | ||
| 2 | |||
| 3 | import javafx.geometry.Pos; | ||
| 4 | import javafx.scene.Scene; | ||
| 5 | import javafx.scene.control.Alert; | ||
| 6 | import javafx.scene.control.Button; | ||
| 7 | import javafx.scene.control.DatePicker; | ||
| 8 | import javafx.scene.image.Image; | ||
| 9 | import javafx.scene.image.ImageView; | ||
| 10 | import javafx.scene.layout.HBox; | ||
| 11 | import javafx.scene.layout.VBox; | ||
| 12 | import javafx.scene.paint.Color; | ||
| 13 | import javafx.scene.text.Font; | ||
| 14 | import javafx.scene.text.Text; | ||
| 15 | import javafx.stage.FileChooser; | ||
| 16 | import javafx.stage.Stage; | ||
| 17 | import modele.Evenement; | ||
| 18 | import modele.User; | ||
| 19 | import javafx.scene.control.TextField; | ||
| 20 | //import java.awt.TextArea; | ||
| 21 | import java.io.File; | ||
| 22 | import java.io.IOException; | ||
| 23 | import java.nio.file.Files; | ||
| 24 | import java.nio.file.Paths; | ||
| 25 | import java.time.LocalDate; | ||
| 26 | import java.time.ZoneId; | ||
| 27 | import java.time.format.DateTimeFormatter; | ||
| 28 | import java.util.Date; | ||
| 29 | |||
| 30 | import controlleur.BDD; | ||
| 31 | import controlleur.ControllerAdmin; | ||
| 32 | import controlleur.EvenementController; | ||
| 33 | |||
| 34 | public class AfficheAdmin { | ||
| 35 | private static VBox events; | ||
| 36 | private static Stage stage; | ||
| 37 | private static User sess; | ||
| 38 | |||
| 39 | public static Stage getStage() { | ||
| 40 | return stage; | ||
| 41 | } | ||
| 42 | |||
| 43 | public static void setStage(Stage stage) { | ||
| 44 | AfficheAdmin.stage = stage; | ||
| 45 | } | ||
| 46 | |||
| 47 | public static User getSess() { | ||
| 48 | return sess; | ||
| 49 | } | ||
| 50 | |||
| 51 | public static void setSess(User sess) { | ||
| 52 | AfficheAdmin.sess = sess; | ||
| 53 | } | ||
| 54 | |||
| 55 | public static VBox getEvents() { | ||
| 56 | return events; | ||
| 57 | } | ||
| 58 | |||
| 59 | public static void affiche(Stage primaryStage, User session) { | ||
| 60 | stage = primaryStage; | ||
| 61 | sess = session; | ||
| 62 | events = EvenementController.EvenementVBox(); | ||
| 63 | AfficheTopMenu menu = new AfficheTopMenu(stage,sess); | ||
| 64 | Text titre = new Text("Mes évènements"); | ||
| 65 | titre.setFont(Font.font("Arial", 30)); | ||
| 66 | titre.setFill(Color.web("#2C3E50")); | ||
| 67 | titre.setStroke(Color.web("#34495E")); | ||
| 68 | titre.setStrokeWidth(1); | ||
| 69 | |||
| 70 | |||
| 71 | // Création du DatePicker | ||
| 72 | DatePicker date = new DatePicker(); | ||
| 73 | date.setMaxWidth(60); | ||
| 74 | |||
| 75 | VBox vTitre = new VBox(titre); | ||
| 76 | Button parcourir = new Button("Parcourir"); | ||
| 77 | Button valider = new Button("Valider"); | ||
| 78 | TextField nom = new TextField(""); | ||
| 79 | nom.setPromptText("Nom de l'évènement"); | ||
| 80 | TextField descEvent = new TextField(); | ||
| 81 | descEvent.setPromptText("Quelques mots pour votre évènement ?"); | ||
| 82 | descEvent.setPrefWidth(250); | ||
| 83 | |||
| 84 | // Création d'un ImageView pour afficher l'image | ||
| 85 | ImageView imageView = new ImageView(); | ||
| 86 | imageView.setPreserveRatio(true); | ||
| 87 | imageView.setFitWidth(80); | ||
| 88 | |||
| 89 | // Action des boutons | ||
| 90 | parcourir.setOnAction(e -> { | ||
| 91 | ControllerAdmin.parcourir(stage, imageView); | ||
| 92 | }); | ||
| 93 | |||
| 94 | valider.setOnAction(e -> { | ||
| 95 | if (nom.getText().isEmpty() || descEvent.getText().isEmpty()||ControllerAdmin.getFile() == null){ | ||
| 96 | |||
| 97 | // Affichage du message d'erreur si n champ est vide | ||
| 98 | showErrorMessage("Tous les champs doivent être remplis."); | ||
| 99 | } | ||
| 100 | else { | ||
| 101 | // Récupération de la date sélectionnée | ||
| 102 | LocalDate localDate = date.getValue(); | ||
| 103 | |||
| 104 | if (localDate != null) { | ||
| 105 | // Formater la date en chaîne de caractères au format "yyyy-MM-dd" | ||
| 106 | String dateString = localDate.format(DateTimeFormatter.ISO_LOCAL_DATE); | ||
| 107 | System.out.println("Date sélectionnée : " + dateString); | ||
| 108 | System.out.println(dateString); | ||
| 109 | System.out.println("Date sélectionnée (java.util.Date) : " + dateString); | ||
| 110 | events = ControllerAdmin.valider(nom.getText(),ControllerAdmin.getFile().getName(),descEvent.getText(), dateString); | ||
| 111 | AfficheAdmin.affiche(stage, sess); | ||
| 112 | } | ||
| 113 | else { | ||
| 114 | |||
| 115 | // Affichage du message d'erreur si n champ est vide | ||
| 116 | showErrorMessage("Tous les champs doivent être remplis."); | ||
| 117 | } | ||
| 118 | } | ||
| 119 | }); | ||
| 120 | |||
| 121 | // VBox principal | ||
| 122 | HBox hbox = new HBox(20); | ||
| 123 | hbox.getChildren().addAll(nom, imageView, descEvent, date, parcourir, valider); | ||
| 124 | hbox.setAlignment(Pos.CENTER); | ||
| 125 | |||
| 126 | VBox root = new VBox(); | ||
| 127 | root.getChildren().addAll(menu,vTitre,hbox,events); | ||
| 128 | |||
| 129 | // Ajout du VBox à la scène | ||
| 130 | Scene scene = new Scene(root, 800, 600); | ||
| 131 | |||
| 132 | // Ajout d'un titre à la fenêtre | ||
| 133 | primaryStage.setTitle("StatHammer : Admin"); | ||
| 134 | primaryStage.setScene(scene); | ||
| 135 | primaryStage.show(); | ||
| 136 | } | ||
| 137 | |||
| 138 | public static void setEvents(VBox events) { | ||
| 139 | AfficheAdmin.events = events; | ||
| 140 | } | ||
| 141 | |||
| 142 | // Méthode pour afficher une erreur | ||
| 143 | private static void showErrorMessage(String message) { | ||
| 144 | Alert alert = new Alert(Alert.AlertType.ERROR); | ||
| 145 | alert.setTitle("StatHammer : Erreur dans le formulaire"); | ||
| 146 | alert.setHeaderText(null); | ||
| 147 | alert.setContentText(message); | ||
| 148 | alert.showAndWait(); | ||
| 149 | } | ||
| 150 | |||
| 151 | } | ||
diff --git a/src/main/java/vue/AfficheConnexion.java b/src/main/java/vue/AfficheConnexion.java new file mode 100644 index 0000000..5608ab7 --- /dev/null +++ b/src/main/java/vue/AfficheConnexion.java | |||
| @@ -0,0 +1,54 @@ | |||
| 1 | package vue; | ||
| 2 | |||
| 3 | import controlleur.BDD; | ||
| 4 | import controlleur.Connexion; | ||
| 5 | import javafx.geometry.Pos; | ||
| 6 | import javafx.scene.Scene; | ||
| 7 | import javafx.scene.control.Button; | ||
| 8 | import javafx.scene.control.Label; | ||
| 9 | import javafx.scene.control.PasswordField; | ||
| 10 | import javafx.scene.control.TextField; | ||
| 11 | import javafx.scene.layout.VBox; | ||
| 12 | import javafx.stage.Stage; | ||
| 13 | |||
| 14 | public class AfficheConnexion { | ||
| 15 | public static void affiche(Stage primaryStage) { | ||
| 16 | VBox root = new VBox(); | ||
| 17 | Scene scene = new Scene(root, 800, 600); | ||
| 18 | TextField pseudo = new TextField(); | ||
| 19 | PasswordField mdp = new PasswordField(); | ||
| 20 | Label nomPseudo = new Label("Pseudo"); | ||
| 21 | Label nomMdp = new Label("Mot de passe"); | ||
| 22 | Button envoi = new Button("Connexion"); | ||
| 23 | Button creaCompte = new Button("Créer un compte"); | ||
| 24 | |||
| 25 | root.getChildren().add(nomPseudo); | ||
| 26 | root.getChildren().add(pseudo); | ||
| 27 | root.getChildren().add(nomMdp); | ||
| 28 | root.getChildren().add(mdp); | ||
| 29 | root.getChildren().add(envoi); | ||
| 30 | root.getChildren().add(creaCompte); | ||
| 31 | |||
| 32 | mdp.setMaxWidth(200); | ||
| 33 | pseudo.setMaxWidth(200); | ||
| 34 | |||
| 35 | pseudo.setAlignment(Pos.CENTER); | ||
| 36 | mdp.setAlignment(Pos.CENTER); | ||
| 37 | root.setAlignment(Pos.CENTER); | ||
| 38 | |||
| 39 | //BDD.setInfos("400129","stathammer_greta_admin","stathammer_v1"); | ||
| 40 | BDD.setInfos("root","qsdfgh","stathammer"); | ||
| 41 | |||
| 42 | creaCompte.setOnAction(e -> { | ||
| 43 | AfficheCreationCompte.affiche(primaryStage); | ||
| 44 | }); | ||
| 45 | |||
| 46 | envoi.setOnAction(e -> { | ||
| 47 | |||
| 48 | Connexion.verif(pseudo.getText(), mdp.getText(), primaryStage); | ||
| 49 | }); | ||
| 50 | |||
| 51 | primaryStage.setScene(scene); | ||
| 52 | primaryStage.show(); | ||
| 53 | } | ||
| 54 | } | ||
diff --git a/src/main/java/vue/AfficheConnexionFailed.java b/src/main/java/vue/AfficheConnexionFailed.java new file mode 100644 index 0000000..0f6ab38 --- /dev/null +++ b/src/main/java/vue/AfficheConnexionFailed.java | |||
| @@ -0,0 +1,56 @@ | |||
| 1 | package vue; | ||
| 2 | |||
| 3 | import controlleur.Connexion; | ||
| 4 | import javafx.geometry.Pos; | ||
| 5 | import javafx.scene.Scene; | ||
| 6 | import javafx.scene.control.Button; | ||
| 7 | import javafx.scene.control.Label; | ||
| 8 | import javafx.scene.control.PasswordField; | ||
| 9 | import javafx.scene.control.TextField; | ||
| 10 | import javafx.scene.layout.VBox; | ||
| 11 | import javafx.scene.paint.Color; | ||
| 12 | import javafx.stage.Stage; | ||
| 13 | |||
| 14 | public class AfficheConnexionFailed { | ||
| 15 | public static void affiche(Stage primaryStage) { | ||
| 16 | VBox root = new VBox(); | ||
| 17 | Scene scene = new Scene(root, 800, 600); | ||
| 18 | TextField pseudo = new TextField(); | ||
| 19 | PasswordField mdp = new PasswordField(); | ||
| 20 | Label nomPseudo = new Label("Pseudo"); | ||
| 21 | Label nomMdp = new Label("Mot de passe"); | ||
| 22 | Button envoi = new Button("Connexion"); | ||
| 23 | Button creaCompte = new Button("Créer un compte"); | ||
| 24 | Label erreur = new Label("Mauvais Login et/ou MDP"); | ||
| 25 | |||
| 26 | erreur.setTextFill(Color.RED); | ||
| 27 | erreur.setAlignment(Pos.CENTER); | ||
| 28 | |||
| 29 | root.getChildren().add(nomPseudo); | ||
| 30 | root.getChildren().add(pseudo); | ||
| 31 | root.getChildren().add(nomMdp); | ||
| 32 | root.getChildren().add(mdp); | ||
| 33 | root.getChildren().add(envoi); | ||
| 34 | root.getChildren().add(creaCompte); | ||
| 35 | root.getChildren().add(erreur); | ||
| 36 | |||
| 37 | mdp.setMaxWidth(200); | ||
| 38 | pseudo.setMaxWidth(200); | ||
| 39 | |||
| 40 | pseudo.setAlignment(Pos.CENTER); | ||
| 41 | mdp.setAlignment(Pos.CENTER); | ||
| 42 | root.setAlignment(Pos.CENTER); | ||
| 43 | |||
| 44 | envoi.setOnAction(e -> { | ||
| 45 | |||
| 46 | Connexion.verif(pseudo.getText(), mdp.getText(), primaryStage); | ||
| 47 | }); | ||
| 48 | creaCompte.setOnAction(e -> { | ||
| 49 | AfficheCreationCompte.affiche(primaryStage); | ||
| 50 | }); | ||
| 51 | |||
| 52 | primaryStage.setScene(scene); | ||
| 53 | primaryStage.show(); | ||
| 54 | } | ||
| 55 | |||
| 56 | } | ||
diff --git a/src/main/java/vue/AfficheCreationCompte.java b/src/main/java/vue/AfficheCreationCompte.java new file mode 100644 index 0000000..0714103 --- /dev/null +++ b/src/main/java/vue/AfficheCreationCompte.java | |||
| @@ -0,0 +1,56 @@ | |||
| 1 | package vue; | ||
| 2 | |||
| 3 | import controlleur.CreationCompte; | ||
| 4 | import javafx.geometry.Pos; | ||
| 5 | import javafx.scene.Scene; | ||
| 6 | import javafx.scene.control.Button; | ||
| 7 | import javafx.scene.control.Label; | ||
| 8 | import javafx.scene.control.PasswordField; | ||
| 9 | import javafx.scene.control.TextField; | ||
| 10 | import javafx.scene.layout.VBox; | ||
| 11 | import javafx.stage.Stage; | ||
| 12 | |||
| 13 | public class AfficheCreationCompte { | ||
| 14 | public static void affiche(Stage primaryStage) { | ||
| 15 | VBox root = new VBox(); | ||
| 16 | Scene scene = new Scene(root, 800, 600); | ||
| 17 | TextField Email = new TextField(); | ||
| 18 | TextField Pseudo = new TextField(); | ||
| 19 | PasswordField Mdp = new PasswordField(); | ||
| 20 | Label nomEmail = new Label("Email"); | ||
| 21 | Label nomPseudo = new Label("Pseudonyme"); | ||
| 22 | Label nomMdp = new Label("Mot de passe"); | ||
| 23 | Button envoi = new Button("Créer un compte"); | ||
| 24 | Button getback = new Button("Retour page de connexion"); | ||
| 25 | |||
| 26 | root.getChildren().add(nomEmail); | ||
| 27 | root.getChildren().add(Email); | ||
| 28 | root.getChildren().add(nomPseudo); | ||
| 29 | root.getChildren().add(Pseudo); | ||
| 30 | root.getChildren().add(nomMdp); | ||
| 31 | root.getChildren().add(Mdp); | ||
| 32 | root.getChildren().add(envoi); | ||
| 33 | root.getChildren().add(getback); | ||
| 34 | |||
| 35 | Email.setMaxWidth(200); | ||
| 36 | Pseudo.setMaxWidth(200); | ||
| 37 | Mdp.setMaxWidth(200); | ||
| 38 | |||
| 39 | Email.setAlignment(Pos.CENTER); | ||
| 40 | Pseudo.setAlignment(Pos.CENTER); | ||
| 41 | Mdp.setAlignment(Pos.CENTER); | ||
| 42 | root.setAlignment(Pos.CENTER); | ||
| 43 | |||
| 44 | envoi.setOnAction(e -> { | ||
| 45 | |||
| 46 | CreationCompte.verif(Email.getText(), Pseudo.getText(), String.valueOf(Mdp.getText().hashCode()), primaryStage); | ||
| 47 | }); | ||
| 48 | getback.setOnAction(e -> { | ||
| 49 | |||
| 50 | CreationCompte.getBack(primaryStage); | ||
| 51 | }); | ||
| 52 | |||
| 53 | primaryStage.setScene(scene); | ||
| 54 | primaryStage.show(); | ||
| 55 | } | ||
| 56 | } | ||
diff --git a/src/main/java/vue/AfficheCreerListe.java b/src/main/java/vue/AfficheCreerListe.java new file mode 100644 index 0000000..4c5bd70 --- /dev/null +++ b/src/main/java/vue/AfficheCreerListe.java | |||
| @@ -0,0 +1,248 @@ | |||
| 1 | package vue; | ||
| 2 | |||
| 3 | import java.awt.Dimension; | ||
| 4 | import controlleur.Instanciation; | ||
| 5 | import controlleur.StockageCreerListe; | ||
| 6 | import javafx.geometry.Pos; | ||
| 7 | import javafx.scene.Scene; | ||
| 8 | import javafx.scene.control.Button; | ||
| 9 | import javafx.scene.control.ChoiceBox; | ||
| 10 | import javafx.scene.control.Label; | ||
| 11 | import javafx.scene.control.ScrollPane; | ||
| 12 | import javafx.scene.control.TextField; | ||
| 13 | import javafx.scene.image.Image; | ||
| 14 | import javafx.scene.image.ImageView; | ||
| 15 | import javafx.scene.layout.HBox; | ||
| 16 | import javafx.scene.layout.VBox; | ||
| 17 | import javafx.scene.text.Font; | ||
| 18 | import javafx.stage.Stage; | ||
| 19 | import modele.Bouton; | ||
| 20 | import modele.User; | ||
| 21 | |||
| 22 | public class AfficheCreerListe { | ||
| 23 | public static void afficheCreerListe(Stage primaryStage,User session) { | ||
| 24 | |||
| 25 | //Definission hauteur largeur pour afficher un peu responsive | ||
| 26 | Dimension tailleEcran = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); | ||
| 27 | double hauteur = tailleEcran.getHeight()/2; | ||
| 28 | double largeur = tailleEcran.getWidth()/2; | ||
| 29 | |||
| 30 | |||
| 31 | |||
| 32 | |||
| 33 | |||
| 34 | AfficheTopMenu menu = new AfficheTopMenu(primaryStage, session); | ||
| 35 | //initialisation de toute les variables pour l'affichage | ||
| 36 | VBox root = new VBox(); | ||
| 37 | HBox boite = new HBox(); | ||
| 38 | VBox gauche = new VBox(); | ||
| 39 | VBox droite = new VBox(); | ||
| 40 | HBox entete = new HBox(); | ||
| 41 | VBox gaucheCorps = new VBox(); | ||
| 42 | HBox corpTete = new HBox(); | ||
| 43 | VBox droiteCorps= new VBox(); | ||
| 44 | Scene scene = new Scene(root,largeur,hauteur); | ||
| 45 | Label titre = new Label("StatHammer"); | ||
| 46 | Image logoFaction = new Image("images/wip.jpg"); | ||
| 47 | ImageView iv1 = new ImageView(logoFaction); | ||
| 48 | ImageView iv2 = new ImageView(logoFaction); | ||
| 49 | Button creation = new Button("Créer et sauvegarder une Armée"); | ||
| 50 | TextField nomArmee = new TextField(); | ||
| 51 | ScrollPane toutUnit = new ScrollPane(); | ||
| 52 | ScrollPane unitSauv = new ScrollPane(); | ||
| 53 | VBox gaucheUnit = new VBox(); | ||
| 54 | ChoiceBox<String> faction = new ChoiceBox<>(); | ||
| 55 | ChoiceBox<String> groupe = new ChoiceBox<>(); | ||
| 56 | StockageCreerListe.initArmeeListe(); | ||
| 57 | |||
| 58 | //remplissage de la liste des factions disponibles dans une variable static | ||
| 59 | StockageCreerListe.initFaction(); | ||
| 60 | |||
| 61 | //Affichage des noms des faction récuperer dans le stockage static | ||
| 62 | for(String fac:StockageCreerListe.getNomFac()) { | ||
| 63 | faction.getItems().add(fac); | ||
| 64 | } | ||
| 65 | faction.setValue(faction.getItems().getFirst()); | ||
| 66 | |||
| 67 | |||
| 68 | |||
| 69 | |||
| 70 | //remplissage de la liste des Armée disponibles dans une variable static | ||
| 71 | StockageCreerListe.initArmee(faction.getValue()); | ||
| 72 | |||
| 73 | //affichage des Armée disponible dans un faction séléctionnée | ||
| 74 | for(String armee:StockageCreerListe.getNomArmee()) { | ||
| 75 | groupe.getItems().add(armee); | ||
| 76 | } | ||
| 77 | groupe.setValue(groupe.getItems().getFirst()); | ||
| 78 | |||
| 79 | |||
| 80 | //action liste déroulante pour changer de faction et les armée afficher en conséquence | ||
| 81 | faction.setOnAction(e->{ | ||
| 82 | groupe.getItems().clear(); | ||
| 83 | |||
| 84 | StockageCreerListe.initArmee(faction.getValue()); | ||
| 85 | for(String armee:StockageCreerListe.getNomArmee()) { | ||
| 86 | groupe.getItems().add(armee); | ||
| 87 | } | ||
| 88 | groupe.setValue(groupe.getItems().getFirst()); | ||
| 89 | }); | ||
| 90 | |||
| 91 | //remplissage des unitéd d'une armée séléctionnée dans une variable static | ||
| 92 | StockageCreerListe.initUnit(groupe.getValue()); | ||
| 93 | |||
| 94 | //affichage de la liste des unité présente dans l'armée séléctionnée | ||
| 95 | for(String unit : StockageCreerListe.getNomUnit()) { | ||
| 96 | |||
| 97 | //action sur le bouton + permettant d'ajouter l'unité à la liste de l'armée en création | ||
| 98 | droiteCorps.getChildren().add(new HBox(new Label(unit.toString() ),new Bouton("+").setOnAction2(e->{ | ||
| 99 | gaucheUnit.getChildren().clear(); | ||
| 100 | //verification que l'unité ne fait pas déjà parti de l'armée en cours de création | ||
| 101 | if(!StockageCreerListe.getArmeeListe().getUnits().contains(StockageCreerListe.getUnit(unit))) { | ||
| 102 | StockageCreerListe.getUnit(unit).setFigurine(Instanciation.getFigurine2(unit)) ; | ||
| 103 | StockageCreerListe.getArmeeListe().addUnit(StockageCreerListe.getUnit(unit)); | ||
| 104 | } | ||
| 105 | |||
| 106 | //affichage des unité de l'armée en cours de création | ||
| 107 | for(String unit2:StockageCreerListe.getArmeeListe().getUnitNames()) { | ||
| 108 | //action du bouton - permettant de retirer une unité de l'armée en cours de création | ||
| 109 | gaucheUnit.getChildren().add(new HBox(new Label(unit2.toString() ),new Bouton("-").setOnAction2(z->{ | ||
| 110 | gaucheUnit.getChildren().remove( | ||
| 111 | StockageCreerListe.getArmeeListe().getUnits().indexOf(StockageCreerListe.getUnit(unit2))); | ||
| 112 | StockageCreerListe.getArmeeListe().removeUnit(StockageCreerListe.getUnit(unit2)); | ||
| 113 | |||
| 114 | |||
| 115 | }))); | ||
| 116 | } | ||
| 117 | |||
| 118 | }))); | ||
| 119 | |||
| 120 | } | ||
| 121 | |||
| 122 | //Meme action que plus haut à faire au moment du changement de choix d'une armée | ||
| 123 | groupe.setOnAction(e->{ | ||
| 124 | |||
| 125 | StockageCreerListe.initUnit(groupe.getValue()); | ||
| 126 | droiteCorps.getChildren().clear(); | ||
| 127 | StockageCreerListe.getArmeeListe().getUnits().clear(); | ||
| 128 | for(String unit : StockageCreerListe.getNomUnit()) { | ||
| 129 | |||
| 130 | droiteCorps.getChildren().add(new HBox(new Label(unit.toString() ),new Bouton("+").setOnAction2(y->{ | ||
| 131 | gaucheUnit.getChildren().clear(); | ||
| 132 | |||
| 133 | if(!StockageCreerListe.getArmeeListe().getUnits().contains(StockageCreerListe.getUnit(unit))) { | ||
| 134 | StockageCreerListe.getUnit(unit).setFigurine(Instanciation.getFigurine2(unit)) ; | ||
| 135 | StockageCreerListe.getArmeeListe().addUnit(StockageCreerListe.getUnit(unit)); | ||
| 136 | } | ||
| 137 | for(String unit2:StockageCreerListe.getArmeeListe().getUnitNames()) { | ||
| 138 | gaucheUnit.getChildren().add(new HBox(new Label(unit2.toString() ),new Bouton("-").setOnAction2(z->{ | ||
| 139 | gaucheUnit.getChildren().remove( | ||
| 140 | StockageCreerListe.getArmeeListe().getUnits().indexOf(StockageCreerListe.getUnit(unit2))); | ||
| 141 | StockageCreerListe.getArmeeListe().removeUnit(StockageCreerListe.getUnit(unit2)); | ||
| 142 | |||
| 143 | }))); | ||
| 144 | } | ||
| 145 | }))); | ||
| 146 | |||
| 147 | } | ||
| 148 | }); | ||
| 149 | |||
| 150 | //assemblage des éléments visuels | ||
| 151 | iv1.setFitHeight(hauteur/15); | ||
| 152 | iv1.setPreserveRatio(true); | ||
| 153 | iv1.setSmooth(true); | ||
| 154 | iv1.setCache(true); | ||
| 155 | |||
| 156 | iv2.setFitHeight(hauteur/15); | ||
| 157 | iv2.setPreserveRatio(true); | ||
| 158 | iv2.setSmooth(true); | ||
| 159 | iv2.setCache(true); | ||
| 160 | |||
| 161 | titre.setFont(Font.font(32)); | ||
| 162 | titre.setPrefHeight(50); | ||
| 163 | titre.setAlignment(Pos.CENTER); | ||
| 164 | |||
| 165 | boite.getChildren().addAll(gauche,droite); | ||
| 166 | boite.setAlignment(Pos.CENTER); | ||
| 167 | |||
| 168 | gauche.getChildren().add(entete); | ||
| 169 | gauche.getChildren().add(gaucheCorps); | ||
| 170 | gauche.setPrefWidth(largeur/2); | ||
| 171 | gauche.setPrefHeight(hauteur); | ||
| 172 | gauche.setMaxWidth(largeur/2); | ||
| 173 | gauche.setMaxHeight(hauteur); | ||
| 174 | |||
| 175 | |||
| 176 | droite.getChildren().add(toutUnit); | ||
| 177 | droite.setPrefWidth(largeur/2); | ||
| 178 | droite.setPrefHeight(hauteur); | ||
| 179 | droite.setMaxWidth(largeur/2); | ||
| 180 | droite.setMaxHeight(hauteur); | ||
| 181 | |||
| 182 | |||
| 183 | toutUnit.setFitToHeight(true); | ||
| 184 | toutUnit.setContent(droiteCorps); | ||
| 185 | |||
| 186 | entete.getChildren().addAll(creation,nomArmee,faction,iv1); | ||
| 187 | entete.setAlignment(Pos.CENTER); | ||
| 188 | entete.setMaxHeight(hauteur/15); | ||
| 189 | |||
| 190 | //Bouton de validation de création d'une armée pour sauvegarder l'armée en base de donnée | ||
| 191 | creation.setOnAction(e->{ | ||
| 192 | //verification que l'armée soit nommé et NON VIDE | ||
| 193 | if(nomArmee.getText().trim().equals("") || StockageCreerListe.getArmeeListe().getUnits().size()==0) { | ||
| 194 | //affichage d'une boite d'erreur si nom vide ou armée sans unité | ||
| 195 | Stage secondaryStage = new Stage(); | ||
| 196 | HBox boitesecondaire = new HBox(); | ||
| 197 | Scene secondScene = new Scene(boitesecondaire,200,100); | ||
| 198 | Label error = new Label("ERREUR Armee vide ET/OU sans nom"); | ||
| 199 | boitesecondaire.getChildren().add(error); | ||
| 200 | boitesecondaire.setAlignment(Pos.CENTER); | ||
| 201 | secondaryStage.setScene(secondScene); | ||
| 202 | secondaryStage.setTitle("Error"); | ||
| 203 | secondaryStage.show(); | ||
| 204 | }else { | ||
| 205 | //sauvegarde de l'armée dans la variable de session ainsi que dans la BDD | ||
| 206 | StockageCreerListe.getArmeeListe().setNom(nomArmee.getText()); | ||
| 207 | session.getListes().add(StockageCreerListe.getArmeeListe()); | ||
| 208 | try { | ||
| 209 | |||
| 210 | Instanciation.insertListe(StockageCreerListe.getArmeeListe(), session); | ||
| 211 | |||
| 212 | AfficheAccueil.affiche(primaryStage, session); | ||
| 213 | |||
| 214 | } catch (Exception e2) { | ||
| 215 | // TODO: handle exception | ||
| 216 | } | ||
| 217 | } | ||
| 218 | |||
| 219 | }); | ||
| 220 | |||
| 221 | |||
| 222 | gaucheCorps.getChildren().add(corpTete); | ||
| 223 | gaucheCorps.getChildren().add(unitSauv); | ||
| 224 | |||
| 225 | unitSauv.setContent(gaucheUnit); | ||
| 226 | unitSauv.setFitToHeight(true); | ||
| 227 | |||
| 228 | |||
| 229 | |||
| 230 | corpTete.getChildren().addAll(groupe,iv2); | ||
| 231 | corpTete.setAlignment(Pos.CENTER); | ||
| 232 | corpTete.setMaxHeight(hauteur/15); | ||
| 233 | |||
| 234 | root.getChildren().add(menu); | ||
| 235 | root.setAlignment(Pos.CENTER); | ||
| 236 | root.getChildren().add(titre); | ||
| 237 | root.getChildren().add(boite); | ||
| 238 | |||
| 239 | |||
| 240 | |||
| 241 | |||
| 242 | |||
| 243 | primaryStage.setScene(scene); | ||
| 244 | primaryStage.setTitle("Création de l'armée"); | ||
| 245 | primaryStage.show(); | ||
| 246 | } | ||
| 247 | } | ||
| 248 | |||
diff --git a/src/main/java/vue/AfficheEvenement.java b/src/main/java/vue/AfficheEvenement.java new file mode 100644 index 0000000..9188476 --- /dev/null +++ b/src/main/java/vue/AfficheEvenement.java | |||
| @@ -0,0 +1,88 @@ | |||
| 1 | package vue; | ||
| 2 | |||
| 3 | import controlleur.Connexion; | ||
| 4 | import controlleur.EvenementController; | ||
| 5 | import javafx.scene.control.Button; | ||
| 6 | import javafx.scene.control.Label; | ||
| 7 | import javafx.scene.image.Image; | ||
| 8 | import javafx.scene.image.ImageView; | ||
| 9 | import javafx.scene.layout.HBox; | ||
| 10 | import javafx.scene.layout.VBox; | ||
| 11 | import javafx.stage.Stage; | ||
| 12 | import modele.Evenement; | ||
| 13 | import modele.User; | ||
| 14 | |||
| 15 | public class AfficheEvenement { | ||
| 16 | //private static Evenement event; | ||
| 17 | |||
| 18 | public static VBox NewAfficheEvenement(Stage primaryStage, User session) { | ||
| 19 | |||
| 20 | VBox main = new VBox(); | ||
| 21 | main.setSpacing(20); // Espacement entre les éléments | ||
| 22 | main.setStyle("-fx-padding: 20; -fx-alignment: center;"); // Ajout de marges autour et centrage du VBox | ||
| 23 | |||
| 24 | HBox hBouton = new HBox(); | ||
| 25 | hBouton.setSpacing(10); // Espacement entre les boutons | ||
| 26 | hBouton.setStyle("-fx-alignment: center;"); // Alignement des boutons au centre | ||
| 27 | |||
| 28 | // Style gothique pour le nom de l'événement | ||
| 29 | Label nomEvt = new Label(Connexion.event.getNom_evenement()); | ||
| 30 | nomEvt.setStyle("-fx-font-size: 32px; -fx-font-family: 'Times New Roman'; -fx-font-weight: bold; -fx-text-fill: #2F4F4F; -fx-effect: dropshadow(gaussian, rgba(0, 0, 0, 0.5), 10, 5, 2, 2);"); | ||
| 31 | nomEvt.setStyle("-fx-font-size: 32px; -fx-font-family: 'Garamond'; -fx-font-weight: bold; -fx-text-fill: #2F4F4F; -fx-effect: dropshadow(gaussian, rgba(0, 0, 0, 0.6), 15, 0.5, 0, 3);"); | ||
| 32 | |||
| 33 | // Style de la date et de la description | ||
| 34 | Label dateEvt = new Label(Connexion.event.getData_evenement()); | ||
| 35 | dateEvt.setStyle("-fx-font-size: 16px; -fx-text-fill: #555555;"); // Style de la date de l'événement | ||
| 36 | |||
| 37 | Label descEvt = new Label(Connexion.event.getDescritption_evenement()); | ||
| 38 | descEvt.setStyle("-fx-font-size: 14px; -fx-text-fill: #777777; -fx-wrap-text: true;"); | ||
| 39 | descEvt.setMaxWidth(400); // Limite la largeur de la description | ||
| 40 | |||
| 41 | HBox hLabel = new HBox(); | ||
| 42 | hLabel.setSpacing(10); | ||
| 43 | hLabel.getChildren().add(dateEvt); | ||
| 44 | hLabel.getChildren().add(descEvt); | ||
| 45 | hLabel.setStyle("-fx-alignment: center;"); // Alignement des labels au centre | ||
| 46 | |||
| 47 | // Ajout des boutons dans le HBox avec style "dark fantasy" modeste | ||
| 48 | for (int i = 0; i < Connexion.eventC.getNbrEvt(); i++) { | ||
| 49 | int j = i; | ||
| 50 | Button btn = new Button(Connexion.eventC.getNom_event().get(i)); | ||
| 51 | btn.setStyle("-fx-background-color: #1a1a1a; -fx-text-fill: #e6e6e6; -fx-font-size: 14px; -fx-padding: 10px 15px; -fx-border-radius: 5px; -fx-border-color: #444444; -fx-border-width: 1px;"); | ||
| 52 | btn.setOnAction(e -> { | ||
| 53 | Connexion.event = new Evenement(Connexion.eventC.getNom_event().get(j), | ||
| 54 | Connexion.eventC.getNom_image().get(j), | ||
| 55 | Connexion.eventC.getDesc_event().get(j), | ||
| 56 | Connexion.eventC.getDate_event().get(j)); | ||
| 57 | |||
| 58 | AfficheAccueil.affiche(primaryStage, session); | ||
| 59 | }); | ||
| 60 | hBouton.getChildren().add(btn); | ||
| 61 | } | ||
| 62 | |||
| 63 | // Image avec centrage et un peu plus de style sombre | ||
| 64 | Image imageAccueil = new Image("images/" + Connexion.event.getNom_image()); | ||
| 65 | ImageView iv1 = new ImageView(); | ||
| 66 | iv1.setImage(imageAccueil); | ||
| 67 | iv1.setFitWidth(500); | ||
| 68 | iv1.setPreserveRatio(true); | ||
| 69 | iv1.setSmooth(true); | ||
| 70 | iv1.setCache(true); | ||
| 71 | iv1.setStyle("-fx-border-radius: 10px; -fx-effect: dropshadow(gaussian, rgba(0, 0, 0, 0.7), 15, 3, 2, 2);"); | ||
| 72 | |||
| 73 | // Centrer le nom et l'image dans un VBox intermédiaire | ||
| 74 | VBox centeredContent = new VBox(); | ||
| 75 | centeredContent.setSpacing(10); | ||
| 76 | centeredContent.setStyle("-fx-alignment: center;"); | ||
| 77 | centeredContent.getChildren().add(nomEvt); | ||
| 78 | centeredContent.getChildren().add(iv1); | ||
| 79 | |||
| 80 | // Ajout des éléments dans le VBox principal | ||
| 81 | main.getChildren().add(centeredContent); // Ajout du nom et de l'image centrés | ||
| 82 | main.getChildren().add(hBouton); // Ajout des boutons | ||
| 83 | main.getChildren().add(hLabel); // Ajout de la date et description | ||
| 84 | |||
| 85 | // Retourne le VBox stylisé | ||
| 86 | return main; | ||
| 87 | } | ||
| 88 | } | ||
diff --git a/src/main/java/vue/AfficheGestionCompte.java b/src/main/java/vue/AfficheGestionCompte.java new file mode 100644 index 0000000..829ec99 --- /dev/null +++ b/src/main/java/vue/AfficheGestionCompte.java | |||
| @@ -0,0 +1,131 @@ | |||
| 1 | package vue; | ||
| 2 | |||
| 3 | import java.sql.SQLException; | ||
| 4 | |||
| 5 | import controlleur.Connexion; | ||
| 6 | import javafx.geometry.Insets; | ||
| 7 | import javafx.geometry.Pos; | ||
| 8 | import javafx.scene.Scene; | ||
| 9 | import javafx.scene.control.Alert; | ||
| 10 | import javafx.scene.control.Button; | ||
| 11 | import javafx.scene.control.Label; | ||
| 12 | import javafx.scene.control.PasswordField; | ||
| 13 | import javafx.scene.control.TextField; | ||
| 14 | import javafx.scene.control.Alert.AlertType; | ||
| 15 | import javafx.scene.layout.VBox; | ||
| 16 | import javafx.scene.text.Font; | ||
| 17 | import javafx.stage.Stage; | ||
| 18 | import modele.Evenement; | ||
| 19 | import modele.User; | ||
| 20 | |||
| 21 | public class AfficheGestionCompte { | ||
| 22 | |||
| 23 | public static void affiche(Stage primaryStage,User session) { | ||
| 24 | |||
| 25 | |||
| 26 | |||
| 27 | Label etiquetteM = new Label("Gestion du compte utilisateur"); | ||
| 28 | etiquetteM.setFont(new Font("Arial", 24)); | ||
| 29 | Button bouton1 = new Button("Envoyer"); | ||
| 30 | Button bouton2 = new Button("Envoyer"); | ||
| 31 | Label etiquette = new Label("Modifier le pseudonyme : "); | ||
| 32 | TextField texte = new TextField(); | ||
| 33 | Label etiquette2 = new Label("Modifier le mot de passe : "); | ||
| 34 | PasswordField texte2 = new PasswordField(); | ||
| 35 | Label etiquette3 = new Label("Confirmer avec mot de passe actuel : "); | ||
| 36 | PasswordField texte3 = new PasswordField(); | ||
| 37 | VBox vbox = new VBox(); | ||
| 38 | VBox vboxT = new VBox(); | ||
| 39 | vboxT.getChildren().add(etiquetteM); | ||
| 40 | //VBox vboxL = new VBox(); | ||
| 41 | //etiquette.setText("test"); | ||
| 42 | |||
| 43 | AfficheTopMenu menu = new AfficheTopMenu(primaryStage,session); | ||
| 44 | |||
| 45 | VBox vbox1 = new VBox(); | ||
| 46 | vbox1.getChildren().add(etiquette); | ||
| 47 | vbox1.getChildren().add(texte); | ||
| 48 | vbox1.getChildren().add(bouton1); | ||
| 49 | |||
| 50 | VBox vbox2 = new VBox(); | ||
| 51 | |||
| 52 | VBox vboxL = new VBox(); | ||
| 53 | |||
| 54 | vbox2.getChildren().add(etiquette2); | ||
| 55 | vbox2.getChildren().add(texte2); | ||
| 56 | vbox2.getChildren().add(etiquette3); | ||
| 57 | vbox2.getChildren().add(texte3); | ||
| 58 | VBox vboxb = new VBox(); | ||
| 59 | vboxb.getChildren().add(bouton2); | ||
| 60 | vbox2.getChildren().add(vboxb); | ||
| 61 | |||
| 62 | |||
| 63 | |||
| 64 | Scene scene = new Scene(vbox, 800, 600); | ||
| 65 | vbox.getChildren().add(menu); | ||
| 66 | |||
| 67 | vbox.getChildren().add(vboxT); | ||
| 68 | vbox.getChildren().add(vbox1); | ||
| 69 | vbox.getChildren().add(vbox2); | ||
| 70 | |||
| 71 | vboxT.setAlignment(Pos.CENTER); | ||
| 72 | vboxb.setAlignment(Pos.CENTER); | ||
| 73 | vbox.setSpacing(10); | ||
| 74 | vbox1.setSpacing(10);// Ajoute un espace de 10 pixels entre les composants | ||
| 75 | vbox1.setPadding(new Insets(20, 20, 20, 20)); // Ajoute des marges autour du conteneur | ||
| 76 | |||
| 77 | vbox2.setSpacing(10);// Ajoute un espace de 10 pixels entre les composants | ||
| 78 | vbox2.setPadding(new Insets(20, 20, 20, 20)); // Ajoute des marges autour du conteneur | ||
| 79 | vbox1.setAlignment(Pos.CENTER); | ||
| 80 | bouton2.setAlignment(Pos.CENTER); | ||
| 81 | etiquette.setMaxWidth(Double.MAX_VALUE); | ||
| 82 | texte.setMaxWidth(Double.MAX_VALUE); | ||
| 83 | texte2.setMaxWidth(Double.MAX_VALUE); | ||
| 84 | texte3.setMaxWidth(Double.MAX_VALUE); | ||
| 85 | |||
| 86 | bouton1.setOnAction(e -> { | ||
| 87 | if(texte.getText() != null && !texte.getText().trim().isEmpty() && texte.getText().trim().contains(" ")==false) | ||
| 88 | try { | ||
| 89 | Connexion.updatePseudo(texte.getText().trim(),session.getId()); // bdd | ||
| 90 | session.setNom(texte.getText().trim()); // instance de l'utilisateur | ||
| 91 | menu.setLogin(session.getNom()); // barre de menu | ||
| 92 | Alert alert = new Alert(AlertType.INFORMATION); | ||
| 93 | alert.setTitle("Information"); | ||
| 94 | alert.setHeaderText(null); | ||
| 95 | alert.setContentText("Le pseudo a été changé !"); | ||
| 96 | alert.showAndWait(); | ||
| 97 | } catch (SQLException e1) { | ||
| 98 | e1.printStackTrace(); | ||
| 99 | } | ||
| 100 | }); | ||
| 101 | |||
| 102 | bouton2.setOnAction(e -> { | ||
| 103 | |||
| 104 | try { | ||
| 105 | String mdp =Connexion.selectMdp(session.getId()); | ||
| 106 | if (Integer.toString(texte3.getText().trim().hashCode()).equals(mdp)==true) { | ||
| 107 | |||
| 108 | if(texte2.getText() != null && !texte2.getText().trim().isEmpty() && texte2.getText().trim().contains(" ")==false) | ||
| 109 | try { | ||
| 110 | Connexion.updateMdp(texte2.getText().trim(), session.getId()); | ||
| 111 | Alert alert2 = new Alert(AlertType.INFORMATION); | ||
| 112 | alert2.setTitle("Information"); | ||
| 113 | alert2.setHeaderText(null); | ||
| 114 | alert2.setContentText("Le mot de passe !"); | ||
| 115 | alert2.showAndWait(); | ||
| 116 | |||
| 117 | } catch (SQLException e1) { | ||
| 118 | e1.printStackTrace(); | ||
| 119 | } | ||
| 120 | } | ||
| 121 | } | ||
| 122 | catch (SQLException e1) { | ||
| 123 | e1.printStackTrace(); | ||
| 124 | } | ||
| 125 | }); | ||
| 126 | |||
| 127 | primaryStage.setScene(scene); | ||
| 128 | primaryStage.show(); | ||
| 129 | } | ||
| 130 | } | ||
| 131 | |||
diff --git a/src/main/java/vue/AfficheTopMenu.java b/src/main/java/vue/AfficheTopMenu.java new file mode 100644 index 0000000..f0449aa --- /dev/null +++ b/src/main/java/vue/AfficheTopMenu.java | |||
| @@ -0,0 +1,116 @@ | |||
| 1 | package vue; | ||
| 2 | |||
| 3 | import controlleur.ControllerTopMenu; | ||
| 4 | import javafx.scene.control.Button; | ||
| 5 | import javafx.scene.control.Label; | ||
| 6 | import javafx.scene.image.Image; | ||
| 7 | import javafx.scene.image.ImageView; | ||
| 8 | import javafx.scene.layout.HBox; | ||
| 9 | import javafx.scene.layout.Pane; | ||
| 10 | import javafx.scene.layout.Priority; | ||
| 11 | import javafx.scene.paint.Color; | ||
| 12 | import javafx.stage.Stage; | ||
| 13 | import modele.Evenement; | ||
| 14 | import modele.User; | ||
| 15 | |||
| 16 | public class AfficheTopMenu extends HBox | ||
| 17 | { | ||
| 18 | private Label pseudo; | ||
| 19 | |||
| 20 | public AfficheTopMenu(Stage primaryStage, User session) | ||
| 21 | { | ||
| 22 | this.setStyle("-fx-background-color: gray; -fx-padding: 5px;"); | ||
| 23 | //-fx-spacing: 10px; | ||
| 24 | //Label title = new Label("Simulation"); // moche, à améliorer ou retirer | ||
| 25 | Button btn_account = new Button("Mon compte"); | ||
| 26 | Button btn_logout = new Button(); | ||
| 27 | Button btn_home = new Button("Accueil"); | ||
| 28 | Button btn_gerer_liste = new Button("Gerer liste"); | ||
| 29 | Button btn_creer_liste = new Button("Création liste"); | ||
| 30 | Button btn_admin = new Button("Admin"); | ||
| 31 | Button btn_simu = new Button("Simulation"); | ||
| 32 | |||
| 33 | |||
| 34 | HBox h1 = new HBox(); | ||
| 35 | h1.getChildren().addAll(btn_home, btn_account,btn_gerer_liste,btn_creer_liste,btn_simu); | ||
| 36 | |||
| 37 | |||
| 38 | |||
| 39 | Image icons_deco = new Image("/images/deco.png"); | ||
| 40 | ImageView icons_deco_box = new ImageView(icons_deco); | ||
| 41 | btn_logout.setGraphic(icons_deco_box); | ||
| 42 | icons_deco_box.setPreserveRatio(true); | ||
| 43 | icons_deco_box.fitHeightProperty().bind(btn_account.heightProperty()); | ||
| 44 | //this.getChildren().add(h1); | ||
| 45 | //this.setAlignment(javafx.geometry.Pos.CENTER_RIGHT); | ||
| 46 | //h1.setLeft(null); | ||
| 47 | //h2.setAlignment(javafx.geometry.Pos.TOP_RIGHT); | ||
| 48 | //this.setSpacing(getMaxWidth()); | ||
| 49 | //h1.setSpacing(10);// Ajoute un espace de 10 pixels entre les composants | ||
| 50 | //h2.setPadding(new Insets(1, 1, 20, 1)); | ||
| 51 | |||
| 52 | |||
| 53 | |||
| 54 | if(session.getRole().equals("Admin") ) { | ||
| 55 | h1.getChildren().add(btn_admin); | ||
| 56 | } | ||
| 57 | pseudo = new Label(session.getNom()); | ||
| 58 | //pseudo.setStyle("-fx-text-fill: white"); | ||
| 59 | pseudo.setTextFill(Color.WHITE); | ||
| 60 | pseudo.setStyle("-fx-font-weight: bold;"); | ||
| 61 | //barre.getChildren().addAll( pseudo, btn_logout); | ||
| 62 | |||
| 63 | |||
| 64 | //this.setAlignment(javafx.geometry.Pos.CENTER_RIGHT); | ||
| 65 | HBox h2 = new HBox(); | ||
| 66 | h2.getChildren().addAll( pseudo, btn_logout); | ||
| 67 | |||
| 68 | h1.setSpacing(10); | ||
| 69 | h2.setSpacing(10); | ||
| 70 | Pane p = new Pane(); | ||
| 71 | HBox.setHgrow(p, Priority.ALWAYS); | ||
| 72 | this.getChildren().addAll( h1,p, h2); | ||
| 73 | this.setAlignment(javafx.geometry.Pos.TOP_CENTER); | ||
| 74 | h1.setAlignment(javafx.geometry.Pos.CENTER_LEFT); | ||
| 75 | h2.setAlignment(javafx.geometry.Pos.CENTER_RIGHT); | ||
| 76 | |||
| 77 | |||
| 78 | // menu principal | ||
| 79 | btn_home.setOnAction(e -> { | ||
| 80 | ControllerTopMenu.go_accueil(primaryStage,session); | ||
| 81 | }); | ||
| 82 | // gestion de son compte | ||
| 83 | btn_account.setOnAction(e -> { | ||
| 84 | ControllerTopMenu.go_gestion_compte(primaryStage,session); | ||
| 85 | }); | ||
| 86 | // gestion des listes | ||
| 87 | btn_gerer_liste.setOnAction(e -> { | ||
| 88 | ControllerTopMenu.go_gestion_listes(primaryStage,session); | ||
| 89 | }); | ||
| 90 | // page de connexion | ||
| 91 | btn_logout.setOnAction(e -> { | ||
| 92 | ControllerTopMenu.go_deco(primaryStage, session); | ||
| 93 | }); | ||
| 94 | // simulation | ||
| 95 | btn_simu.setOnAction(e -> { | ||
| 96 | ControllerTopMenu.go_simulation(primaryStage,session); | ||
| 97 | }); | ||
| 98 | |||
| 99 | // options réservées à l'admin | ||
| 100 | btn_admin.setOnAction(e -> { | ||
| 101 | ControllerTopMenu.go_admin(primaryStage, session); | ||
| 102 | }); | ||
| 103 | |||
| 104 | //vers creer liste | ||
| 105 | btn_creer_liste.setOnAction(e->{ | ||
| 106 | ControllerTopMenu.go_creer_liste(primaryStage,session); | ||
| 107 | }); | ||
| 108 | |||
| 109 | } | ||
| 110 | |||
| 111 | public void setLogin(String login) | ||
| 112 | { | ||
| 113 | pseudo.setText(login); | ||
| 114 | } | ||
| 115 | |||
| 116 | } | ||
diff --git a/src/main/java/vue/GestionListe/AfficheGestionListe.java b/src/main/java/vue/GestionListe/AfficheGestionListe.java new file mode 100644 index 0000000..743eff4 --- /dev/null +++ b/src/main/java/vue/GestionListe/AfficheGestionListe.java | |||
| @@ -0,0 +1,126 @@ | |||
| 1 | package vue.GestionListe; | ||
| 2 | |||
| 3 | import controlleur.GestionListe; | ||
| 4 | import javafx.geometry.Insets; | ||
| 5 | import javafx.geometry.Pos; | ||
| 6 | import javafx.scene.Scene; | ||
| 7 | import javafx.scene.control.Alert; | ||
| 8 | import javafx.scene.control.Button; | ||
| 9 | import javafx.scene.control.ButtonType; | ||
| 10 | import javafx.scene.control.Label; | ||
| 11 | import javafx.scene.layout.*; | ||
| 12 | import javafx.scene.paint.Color; | ||
| 13 | import javafx.stage.Stage; | ||
| 14 | import modele.ArmeeListe; | ||
| 15 | import modele.User; | ||
| 16 | import vue.AfficheAccueil; | ||
| 17 | import vue.AfficheTopMenu; | ||
| 18 | import controlleur.SupprListe; | ||
| 19 | |||
| 20 | import java.io.File; | ||
| 21 | import java.util.ArrayList; | ||
| 22 | |||
| 23 | public class AfficheGestionListe { | ||
| 24 | public static void affiche(Stage primaryStage, User session) { | ||
| 25 | // Liste des conteneurs principaux structurant l'interface | ||
| 26 | VBox root = new VBox(); // page principa | ||
| 27 | HBox boite = new HBox(); // Box contenant les parties bouton et liste | ||
| 28 | VBox selectBouton = new VBox(); // Partie bouton | ||
| 29 | VBox liste = new VBox(); // Partie Liste | ||
| 30 | Scene scene = new Scene(root, 1000, 800); // taille de la scène | ||
| 31 | File file = null; | ||
| 32 | |||
| 33 | AfficheTopMenu menu = new AfficheTopMenu(primaryStage,session); | ||
| 34 | |||
| 35 | root.getChildren().add(menu); | ||
| 36 | |||
| 37 | // _______________ BOX BOITE _______________ | ||
| 38 | // Partie bouton | ||
| 39 | Button Retour = new Button("Retour"); | ||
| 40 | Button Import = new Button("Importer une liste"); | ||
| 41 | // dimension des boutons | ||
| 42 | Retour.setPrefSize(200, 50); | ||
| 43 | Import.setPrefSize(200, 50); | ||
| 44 | // configuration des boutons | ||
| 45 | selectBouton.setPadding(new Insets(50, 0, 0, 0)); | ||
| 46 | selectBouton.setAlignment(Pos.TOP_CENTER); | ||
| 47 | selectBouton.getChildren().addAll(Retour, Import); | ||
| 48 | selectBouton.setPrefWidth(400); | ||
| 49 | selectBouton.setBackground(Background.fill(Color.LIGHTGRAY)); | ||
| 50 | |||
| 51 | // Conteneur des listes | ||
| 52 | liste.setPrefWidth(800); | ||
| 53 | liste.setBackground(Background.fill(Color.LIGHTGREY)); | ||
| 54 | liste.setSpacing(10); | ||
| 55 | liste.setStyle("-fx-border-color: black; -fx-border-width: 1px;"); // bordure du conteneur | ||
| 56 | |||
| 57 | // Charger les listes de l'utilisateur | ||
| 58 | GestionListe gestionListe = new GestionListe(); | ||
| 59 | ArrayList<ArmeeListe> listes = gestionListe.getArmeeListe(session.getId()); // récupération des listes avec l'id | ||
| 60 | // utilisateur | ||
| 61 | // Boucle pour afficher les listes | ||
| 62 | for (ArmeeListe armee : listes) { | ||
| 63 | VBox listeBox = new VBox(); | ||
| 64 | listeBox.setPadding(new Insets(10)); | ||
| 65 | listeBox.setSpacing(5); | ||
| 66 | listeBox.setStyle("-fx-border-color: black; -fx-border-width: 1px;"); | ||
| 67 | |||
| 68 | Label nomListe = new Label(armee.getNomListe()); | ||
| 69 | Label descriptionListe = new Label(armee.getDescription()); | ||
| 70 | VBox uniteBox = new VBox(); | ||
| 71 | for (String unit_name : armee.getUniteListe()) { | ||
| 72 | Label nomUnite = new Label("- " + unit_name); | ||
| 73 | uniteBox.getChildren().add(nomUnite); | ||
| 74 | } | ||
| 75 | |||
| 76 | // Ajout des boutons (Partage, Modification, Suppression) | ||
| 77 | HBox actions = new HBox(); | ||
| 78 | actions.setSpacing(10); | ||
| 79 | Button partageBtn = new Button("Exporter"); | ||
| 80 | Button modifBtn = new Button("Modifier"); | ||
| 81 | Button supprBtn = new Button("Supprimer"); | ||
| 82 | |||
| 83 | actions.getChildren().addAll(partageBtn, modifBtn, supprBtn); | ||
| 84 | actions.setAlignment(Pos.CENTER_RIGHT); | ||
| 85 | |||
| 86 | listeBox.getChildren().addAll(nomListe, descriptionListe, uniteBox, actions); | ||
| 87 | liste.getChildren().add(listeBox); | ||
| 88 | |||
| 89 | modifBtn.setOnAction(e ->{ | ||
| 90 | //primaryStage.close(); | ||
| 91 | AfficheModificationListe.affiche(primaryStage, session, armee.getIdListe(), armee.getIdArmee()); | ||
| 92 | }); | ||
| 93 | |||
| 94 | supprBtn.setOnAction(e -> { | ||
| 95 | Alert alert = new Alert(Alert.AlertType.CONFIRMATION, | ||
| 96 | "Voulez-vous vraiment supprimer la liste :" + armee.getName() + "?", ButtonType.YES, | ||
| 97 | ButtonType.NO); | ||
| 98 | alert.showAndWait().ifPresent(response -> { | ||
| 99 | if (response == ButtonType.YES) { | ||
| 100 | int idListe = armee.getId(); | ||
| 101 | SupprListe suppr = new SupprListe(); | ||
| 102 | suppr.Suppression(idListe); | ||
| 103 | |||
| 104 | liste.getChildren().remove(listeBox); | ||
| 105 | } | ||
| 106 | }); | ||
| 107 | }); | ||
| 108 | } | ||
| 109 | // ajout des conteneurs principaux à la scène | ||
| 110 | boite.getChildren().addAll(selectBouton, liste); | ||
| 111 | root.getChildren().addAll(boite); | ||
| 112 | |||
| 113 | // Bouton Retour | ||
| 114 | Retour.setOnAction(e -> { | ||
| 115 | AfficheAccueil.affiche(primaryStage, session); | ||
| 116 | }); | ||
| 117 | |||
| 118 | Import.setOnAction(e -> { | ||
| 119 | GestionListe.importer(primaryStage, file); | ||
| 120 | }); | ||
| 121 | |||
| 122 | primaryStage.setScene(scene); | ||
| 123 | primaryStage.show(); | ||
| 124 | } | ||
| 125 | |||
| 126 | } | ||
diff --git a/src/main/java/vue/GestionListe/AfficheModificationListe.java b/src/main/java/vue/GestionListe/AfficheModificationListe.java new file mode 100644 index 0000000..e8e6a8f --- /dev/null +++ b/src/main/java/vue/GestionListe/AfficheModificationListe.java | |||
| @@ -0,0 +1,165 @@ | |||
| 1 | package vue.GestionListe; | ||
| 2 | |||
| 3 | import javafx.scene.layout.VBox; | ||
| 4 | import javafx.scene.paint.Color; | ||
| 5 | import javafx.stage.Stage; | ||
| 6 | import modele.ArmeeListe; | ||
| 7 | import modele.Evenement; | ||
| 8 | import modele.Figurine; | ||
| 9 | import modele.User; | ||
| 10 | import vue.AfficheTopMenu; | ||
| 11 | |||
| 12 | import java.util.ArrayList; | ||
| 13 | |||
| 14 | import controlleur.ModificationListe; | ||
| 15 | import javafx.geometry.Insets; | ||
| 16 | import javafx.scene.Scene; | ||
| 17 | import javafx.scene.control.Button; | ||
| 18 | import javafx.scene.control.Label; | ||
| 19 | import javafx.scene.control.ScrollPane; | ||
| 20 | import javafx.scene.layout.Background; | ||
| 21 | import javafx.scene.layout.HBox; | ||
| 22 | |||
| 23 | public class AfficheModificationListe { | ||
| 24 | public static void affiche(Stage primaryStage, User session, int idListe, int idArmee) { | ||
| 25 | VBox root = new VBox(); | ||
| 26 | HBox boite = new HBox(); | ||
| 27 | VBox afficheListe = new VBox(); | ||
| 28 | |||
| 29 | ScrollPane scrollModifListe = new ScrollPane(); | ||
| 30 | ScrollPane scrollAfficheListe = new ScrollPane(); | ||
| 31 | VBox unitDispo = new VBox(); | ||
| 32 | Scene scene = new Scene(root, 1200, 600); | ||
| 33 | |||
| 34 | AfficheTopMenu menu = new AfficheTopMenu(primaryStage, session); | ||
| 35 | |||
| 36 | root.getChildren().add(menu); | ||
| 37 | |||
| 38 | ModificationListe modificationListe = new ModificationListe(); | ||
| 39 | ArrayList<ArmeeListe> listes = modificationListe.getArmeeListe(idListe); | ||
| 40 | |||
| 41 | // Listes temporaires pour les unités ajoutées et supprimées | ||
| 42 | ArrayList<String> unitesAjoutees = new ArrayList<>(); | ||
| 43 | ArrayList<String> unitesSupprimees = new ArrayList<>(); | ||
| 44 | |||
| 45 | // Colonne Affichage de la liste principale | ||
| 46 | for (ArmeeListe armee : listes) { | ||
| 47 | VBox listeBox = new VBox(); | ||
| 48 | listeBox.setPadding(new Insets(10)); | ||
| 49 | listeBox.setSpacing(5); | ||
| 50 | listeBox.setStyle("-fx-border-color: black; -fx-border-width: 1px;"); | ||
| 51 | |||
| 52 | Label nomListe = new Label(armee.getNomListe()); | ||
| 53 | VBox uniteBox = new VBox(); | ||
| 54 | for (String unite : armee.getUniteListe()) { | ||
| 55 | VBox uniteContainer = new VBox(); | ||
| 56 | |||
| 57 | Button retirerUnit = new Button("retirer"); | ||
| 58 | uniteContainer.getChildren().add(retirerUnit); | ||
| 59 | retirerUnit.setOnAction(e -> { | ||
| 60 | if (!unitesSupprimees.contains(unite)) { | ||
| 61 | unitesSupprimees.add(unite); | ||
| 62 | uniteBox.getChildren().remove(uniteContainer); | ||
| 63 | System.out.println("Unité retirée : " + unite); | ||
| 64 | } | ||
| 65 | }); | ||
| 66 | |||
| 67 | Label nomUnite = new Label("| " + unite); | ||
| 68 | uniteContainer.getChildren().add(nomUnite); | ||
| 69 | |||
| 70 | // Récupérer et afficher les figurines pour cette unité | ||
| 71 | ArrayList<Figurine> figurines = modificationListe.getFigurineListe(idListe, unite); | ||
| 72 | for (Figurine figurine : figurines) { | ||
| 73 | Label nomFigurine = new Label(" - " + figurine.getNom()); | ||
| 74 | uniteContainer.getChildren().add(nomFigurine); | ||
| 75 | } | ||
| 76 | |||
| 77 | uniteBox.getChildren().add(uniteContainer); | ||
| 78 | } | ||
| 79 | listeBox.getChildren().addAll(nomListe, uniteBox); | ||
| 80 | afficheListe.getChildren().add(listeBox); | ||
| 81 | } | ||
| 82 | |||
| 83 | afficheListe.setPrefWidth(400); | ||
| 84 | afficheListe.setPrefHeight(500); | ||
| 85 | afficheListe.setBackground(Background.fill(Color.LIGHTGREY)); | ||
| 86 | |||
| 87 | // Colonne des unités disponibles | ||
| 88 | ArrayList<ArmeeListe> toutesUnites = modificationListe.getAllUnites(idArmee, idListe); | ||
| 89 | for (ArmeeListe armee : toutesUnites) { | ||
| 90 | VBox listeBox = new VBox(); | ||
| 91 | listeBox.setPadding(new Insets(10)); | ||
| 92 | listeBox.setSpacing(5); | ||
| 93 | listeBox.setStyle("-fx-border-color: black; -fx-border-width: 1px;"); | ||
| 94 | |||
| 95 | VBox uniteBox = new VBox(); | ||
| 96 | for (String unite : armee.getUniteListe()) { | ||
| 97 | Button ajouterUnit = new Button("ajouter"); | ||
| 98 | uniteBox.getChildren().add(ajouterUnit); | ||
| 99 | ajouterUnit.setOnAction(e -> { | ||
| 100 | if (!unitesAjoutees.contains(unite)) { | ||
| 101 | unitesAjoutees.add(unite); | ||
| 102 | |||
| 103 | // Ajouter l'unité et ses figurines à l'affichage | ||
| 104 | VBox nouvelleUniteContainer = new VBox(); | ||
| 105 | |||
| 106 | Button nouveauRetirerUnit = new Button("retirer"); | ||
| 107 | nouvelleUniteContainer.getChildren().add(nouveauRetirerUnit); | ||
| 108 | nouveauRetirerUnit.setOnAction(event -> { | ||
| 109 | if (!unitesSupprimees.contains(unite)) { | ||
| 110 | unitesSupprimees.add(unite); | ||
| 111 | afficheListe.getChildren().remove(nouvelleUniteContainer); | ||
| 112 | System.out.println("Unité retirée : " + unite); | ||
| 113 | } | ||
| 114 | }); | ||
| 115 | |||
| 116 | Label nouvelleUnite = new Label("| " + unite); | ||
| 117 | nouvelleUniteContainer.getChildren().add(nouvelleUnite); | ||
| 118 | |||
| 119 | // Récupère et affiche les figurines de unité | ||
| 120 | ArrayList<Figurine> figurines = modificationListe.getAllFigurineListe(idArmee, unite); | ||
| 121 | for (Figurine figurine : figurines) { | ||
| 122 | Label nomFigurine = new Label(" - " + figurine.getNom()); | ||
| 123 | nouvelleUniteContainer.getChildren().add(nomFigurine); | ||
| 124 | } | ||
| 125 | |||
| 126 | afficheListe.getChildren().add(nouvelleUniteContainer); | ||
| 127 | System.out.println("Unité ajoutée : " + unite); | ||
| 128 | } | ||
| 129 | }); | ||
| 130 | |||
| 131 | Label nomUnite = new Label("| " + unite); | ||
| 132 | uniteBox.getChildren().add(nomUnite); | ||
| 133 | |||
| 134 | // Récupérer et afficher les figurines de l'unité | ||
| 135 | ArrayList<Figurine> figurines = modificationListe.getAllFigurineListe(idArmee, unite); | ||
| 136 | for (Figurine figurine : figurines) { | ||
| 137 | Label nomFigurine = new Label(" - " + figurine.getNom()); | ||
| 138 | uniteBox.getChildren().add(nomFigurine); | ||
| 139 | } | ||
| 140 | } | ||
| 141 | listeBox.getChildren().addAll(uniteBox); | ||
| 142 | unitDispo.getChildren().add(listeBox); | ||
| 143 | } | ||
| 144 | |||
| 145 | unitDispo.setPrefWidth(400); | ||
| 146 | unitDispo.setPrefHeight(500); | ||
| 147 | unitDispo.setBackground(Background.fill(Color.LIGHTGREY)); | ||
| 148 | scrollModifListe.setContent(unitDispo); | ||
| 149 | scrollAfficheListe.setContent(afficheListe); | ||
| 150 | |||
| 151 | Button valider = new Button("Valider"); | ||
| 152 | valider.setOnAction(e -> { | ||
| 153 | // Envoyer les modifications à la bdd | ||
| 154 | modificationListe.ajouterUnites(idListe, unitesAjoutees); | ||
| 155 | modificationListe.supprimerUnites(idListe, unitesSupprimees); | ||
| 156 | System.out.println("Modifications validées."); | ||
| 157 | }); | ||
| 158 | |||
| 159 | boite.getChildren().addAll(scrollModifListe, scrollAfficheListe, valider); | ||
| 160 | root.getChildren().addAll(boite); | ||
| 161 | |||
| 162 | primaryStage.setScene(scene); | ||
| 163 | primaryStage.show(); | ||
| 164 | } | ||
| 165 | } | ||
diff --git a/src/main/java/vue/simulation/AfficheSimulation.java b/src/main/java/vue/simulation/AfficheSimulation.java new file mode 100644 index 0000000..bb658a3 --- /dev/null +++ b/src/main/java/vue/simulation/AfficheSimulation.java | |||
| @@ -0,0 +1,201 @@ | |||
| 1 | package vue.simulation; | ||
| 2 | |||
| 3 | |||
| 4 | import vue.AfficheTopMenu; | ||
| 5 | |||
| 6 | import java.util.ArrayList; | ||
| 7 | |||
| 8 | import application.Battle; | ||
| 9 | import controlleur.ControlleurSimu; | ||
| 10 | import javafx.geometry.Insets; | ||
| 11 | import javafx.geometry.Pos; | ||
| 12 | import javafx.scene.Scene; | ||
| 13 | import javafx.scene.control.Button; | ||
| 14 | import javafx.scene.control.ChoiceBox; | ||
| 15 | import javafx.scene.control.ScrollPane; | ||
| 16 | import javafx.scene.image.Image; | ||
| 17 | import javafx.scene.image.ImageView; | ||
| 18 | import javafx.scene.layout.HBox; | ||
| 19 | import javafx.scene.layout.Pane; | ||
| 20 | import javafx.scene.layout.VBox; | ||
| 21 | import javafx.stage.Stage; | ||
| 22 | import modele.ArmeeListe; | ||
| 23 | |||
| 24 | import modele.User; | ||
| 25 | |||
| 26 | public class AfficheSimulation | ||
| 27 | { | ||
| 28 | private static SimAptAndWeaponsVBox weapons_aptitudes_menu = new SimAptAndWeaponsVBox(); | ||
| 29 | public static boolean inversion = false; // pour le bouton inversion | ||
| 30 | |||
| 31 | public static void refreshWeaponAndAptitude(SimAptAndWeaponsVBox wap) | ||
| 32 | { | ||
| 33 | weapons_aptitudes_menu.getChildren().clear(); | ||
| 34 | weapons_aptitudes_menu.getChildren().addAll(wap.getChildren()); // copie profonde | ||
| 35 | //weapons_aptitudes_menu.setStyle("-fx-border-width: 1; -fx-border-color: black; -fx-border-radius: 2; -fx-padding: 3px;"); | ||
| 36 | weapons_aptitudes_menu.setStyle("-fx-background-color: rgb(210, 210, 210); -fx-padding: 4px; -fx-border-color: black; -fx-border-radius: 4;"); | ||
| 37 | } | ||
| 38 | |||
| 39 | public static SimAptAndWeaponsVBox getWeaponsAtitudesMenu() { | ||
| 40 | return weapons_aptitudes_menu; | ||
| 41 | } | ||
| 42 | public static void cleanWeaponsAtitudesMenu() { | ||
| 43 | weapons_aptitudes_menu = new SimAptAndWeaponsVBox(); | ||
| 44 | } | ||
| 45 | |||
| 46 | public static void affiche(Stage primaryStage, User session) | ||
| 47 | { | ||
| 48 | // listes d'armées | ||
| 49 | ArrayList<ArmeeListe> lists_of_lists = session.getListes(); // listes d'objets ArmeeListe | ||
| 50 | String[] list_names = session.getListNames(); // tableau des noms des listes | ||
| 51 | |||
| 52 | System.out.print(session.getListes() + "wawa" + session.getListNames() + "wiwi"); | ||
| 53 | VBox root_box = new VBox(); | ||
| 54 | |||
| 55 | AfficheTopMenu menu = new AfficheTopMenu(primaryStage, session); // menu du haut de l'écran | ||
| 56 | |||
| 57 | HBox main = new HBox(); // partie principale de la fenêtre | ||
| 58 | |||
| 59 | |||
| 60 | /* -- colonne de gauche -- */ | ||
| 61 | VBox column1_box = new VBox(); | ||
| 62 | column1_box.prefWidthProperty().bind(main.widthProperty().multiply(0.3)); | ||
| 63 | |||
| 64 | ScrollPane column1_scrollpane = new ScrollPane(); // conteneur avec barres de défilement | ||
| 65 | column1_scrollpane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER); // pas de barre horizontale | ||
| 66 | |||
| 67 | VBox column1 = new VBox(); | ||
| 68 | column1.prefWidthProperty().bind(column1_scrollpane.widthProperty()); | ||
| 69 | |||
| 70 | |||
| 71 | // menu choix armée | ||
| 72 | HBox col1_first_row = new HBox(); // menu déroulant + logo faction | ||
| 73 | ChoiceBox<String> list1_drop_down = new ChoiceBox<>(); | ||
| 74 | list1_drop_down.setStyle("-fx-font-size: 15;"); | ||
| 75 | list1_drop_down.prefWidthProperty().bind(column1_scrollpane.widthProperty()); | ||
| 76 | for(int i = 0; i < list_names.length; i++) | ||
| 77 | { | ||
| 78 | list1_drop_down.getItems().add(list_names[i]); | ||
| 79 | } | ||
| 80 | col1_first_row.getChildren().add(list1_drop_down); | ||
| 81 | column1.getChildren().add(col1_first_row); | ||
| 82 | |||
| 83 | // unités colonne 1 (par défaut) | ||
| 84 | SimUnitsVBox units_list1 = new SimUnitsVBox(1); | ||
| 85 | column1.getChildren().add(units_list1); | ||
| 86 | column1_scrollpane.setContent(column1); | ||
| 87 | |||
| 88 | VBox.setMargin(weapons_aptitudes_menu, new Insets(5,2,2,2)); | ||
| 89 | column1_box.getChildren().addAll(column1_scrollpane, weapons_aptitudes_menu); | ||
| 90 | |||
| 91 | |||
| 92 | /* -- colonne centrale -- */ | ||
| 93 | VBox column2 = new VBox(); | ||
| 94 | column2.prefWidthProperty().bind(main.widthProperty().multiply(0.4)); | ||
| 95 | column2.setAlignment(Pos.TOP_CENTER); | ||
| 96 | |||
| 97 | // boutons inverser et simuler | ||
| 98 | Button btn_simulate = new Button("Action !!"); | ||
| 99 | btn_simulate.setStyle("-fx-font-size: 15;"); | ||
| 100 | |||
| 101 | Image icons_inversion = new Image("/images/inversion_icons.png"); | ||
| 102 | ImageView icons_inversion_box = new ImageView(icons_inversion); | ||
| 103 | Button btn_reverse_armies = new Button(); | ||
| 104 | btn_reverse_armies.setGraphic(icons_inversion_box); | ||
| 105 | |||
| 106 | // grande image | ||
| 107 | Image image_col2 = new Image("/images/wip.jpg"); | ||
| 108 | ImageView image_box = new ImageView(); | ||
| 109 | image_box.setPreserveRatio(true); | ||
| 110 | image_box.fitWidthProperty().bind(column2.widthProperty()); | ||
| 111 | image_box.setImage(image_col2); | ||
| 112 | |||
| 113 | // contrairement aux VBox, ce conteneur ne s'adapte pas à la taille des ses enfants, c'est l'image qui s'adapte | ||
| 114 | Pane big_image_pane = new Pane(); | ||
| 115 | big_image_pane.getChildren().add(image_box); | ||
| 116 | |||
| 117 | // assemblage | ||
| 118 | column2.getChildren().addAll(btn_simulate, big_image_pane, btn_reverse_armies); | ||
| 119 | |||
| 120 | |||
| 121 | /* -- colonne de droite -- */ | ||
| 122 | ScrollPane column3_box = new ScrollPane(); // conteneur avec barres de défilement | ||
| 123 | column3_box.prefWidthProperty().bind(main.widthProperty().multiply(0.3)); | ||
| 124 | column3_box.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER); // pas de barre horizontale | ||
| 125 | |||
| 126 | VBox column3 = new VBox(); | ||
| 127 | column3.prefWidthProperty().bind(column3_box.widthProperty()); | ||
| 128 | |||
| 129 | HBox col3_first_row = new HBox(); // menu déroulant + logo faction | ||
| 130 | ChoiceBox<String> list2_drop_down = new ChoiceBox<>(); | ||
| 131 | list2_drop_down.setStyle("-fx-font-size: 15;"); | ||
| 132 | list2_drop_down.prefWidthProperty().bind(column1_scrollpane.widthProperty()); | ||
| 133 | for(int i = 0; i < list_names.length; i++) | ||
| 134 | { | ||
| 135 | list2_drop_down.getItems().add(list_names[i]); | ||
| 136 | } | ||
| 137 | col3_first_row.getChildren().add(list2_drop_down); | ||
| 138 | column3.getChildren().add(col3_first_row); | ||
| 139 | |||
| 140 | // unités colonne 3 | ||
| 141 | SimUnitsVBox units_list2 = new SimUnitsVBox(2); | ||
| 142 | column3.getChildren().add(units_list2); | ||
| 143 | column3_box.setContent(column3); | ||
| 144 | |||
| 145 | |||
| 146 | /* -- assemblage -- */ | ||
| 147 | main.getChildren().addAll(column1_box, column2, column3_box); | ||
| 148 | root_box.getChildren().addAll(menu, main); | ||
| 149 | |||
| 150 | |||
| 151 | /* ACTION !! */ | ||
| 152 | btn_simulate.setOnAction(e -> { | ||
| 153 | if(Battle.getSelectedList(1) != null && Battle.getSelectedList(2) != null | ||
| 154 | && Battle.getSelectedUnitIndex(1) >= 0 && Battle.getSelectedUnitIndex(2) >= 0) | ||
| 155 | { | ||
| 156 | ControlleurSimu.afficheSimu(big_image_pane, Battle.getSelectedUnit(1), Battle.getSelectedUnit(2)); | ||
| 157 | } | ||
| 158 | else { | ||
| 159 | System.out.println("conditions non remplies pour faire une simulation"); | ||
| 160 | } | ||
| 161 | }); | ||
| 162 | |||
| 163 | |||
| 164 | Scene scene = new Scene(root_box,800,600); | ||
| 165 | primaryStage.setTitle("Simulation"); | ||
| 166 | primaryStage.setScene(scene); | ||
| 167 | primaryStage.show(); | ||
| 168 | |||
| 169 | |||
| 170 | // choix des listes d'armées | ||
| 171 | ArrayList<SimUnitsVBox> unit_lists = new ArrayList<SimUnitsVBox>(); | ||
| 172 | unit_lists.add(units_list1); | ||
| 173 | unit_lists.add(units_list2); | ||
| 174 | ArrayList<ChoiceBox<String>> lists_drop_down = new ArrayList<ChoiceBox<String>>(); | ||
| 175 | lists_drop_down.add(list1_drop_down); | ||
| 176 | lists_drop_down.add(list2_drop_down);; | ||
| 177 | ArrayList<HBox> first_rows = new ArrayList<HBox>(); | ||
| 178 | first_rows.add(col1_first_row); | ||
| 179 | first_rows.add(col3_first_row); | ||
| 180 | for(int i = 0; i < 2; i++) | ||
| 181 | { | ||
| 182 | final int j = i; | ||
| 183 | lists_drop_down.get(i).getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> { | ||
| 184 | if(!inversion) { | ||
| 185 | ControlleurSimu.selectAList(j + 1, lists_of_lists, newValue); | ||
| 186 | } | ||
| 187 | ControlleurSimu.PullDownUnits(j + 1, first_rows.get(j), unit_lists.get(j)); | ||
| 188 | }); | ||
| 189 | } | ||
| 190 | |||
| 191 | // inversion de l'attaquant et du défenseur | ||
| 192 | btn_reverse_armies.setOnAction(e -> { | ||
| 193 | if(Battle.getSelectedList(1) != null && Battle.getSelectedList(2) != null) { | ||
| 194 | ControlleurSimu.reverseArmies(lists_drop_down); | ||
| 195 | } | ||
| 196 | else { | ||
| 197 | System.out.println("conditions non remplies pour inverser listes"); | ||
| 198 | } | ||
| 199 | }); | ||
| 200 | } | ||
| 201 | } | ||
diff --git a/src/main/java/vue/simulation/SimAptAndWeaponsVBox.java b/src/main/java/vue/simulation/SimAptAndWeaponsVBox.java new file mode 100644 index 0000000..5014b59 --- /dev/null +++ b/src/main/java/vue/simulation/SimAptAndWeaponsVBox.java | |||
| @@ -0,0 +1,130 @@ | |||
| 1 | package vue.simulation; | ||
| 2 | |||
| 3 | import java.util.ArrayList; | ||
| 4 | |||
| 5 | import application.Battle; | ||
| 6 | import controlleur.ControlleurSimu; | ||
| 7 | import javafx.geometry.Insets; | ||
| 8 | import javafx.geometry.Pos; | ||
| 9 | import javafx.scene.control.CheckBox; | ||
| 10 | import javafx.scene.control.ChoiceBox; | ||
| 11 | import javafx.scene.control.Label; | ||
| 12 | import javafx.scene.control.Slider; | ||
| 13 | import javafx.scene.layout.HBox; | ||
| 14 | import javafx.scene.layout.FlowPane; | ||
| 15 | import javafx.scene.layout.VBox; | ||
| 16 | import modele.Aptitude; | ||
| 17 | import modele.Arme; | ||
| 18 | import modele.Figurine; | ||
| 19 | |||
| 20 | public class SimAptAndWeaponsVBox extends VBox | ||
| 21 | { | ||
| 22 | private int group_number; | ||
| 23 | private String group_name; | ||
| 24 | int group_size; | ||
| 25 | String[] weapon_names; | ||
| 26 | String[] aptitude_names; | ||
| 27 | |||
| 28 | //public SimAptAndWeaponsVBox(){} | ||
| 29 | |||
| 30 | // setters | ||
| 31 | public void setFigGroup(int fig_group_number, String fig_group_name, int fig_group_size){ | ||
| 32 | group_number = fig_group_number; | ||
| 33 | group_name = fig_group_name; | ||
| 34 | group_size = fig_group_size; | ||
| 35 | } | ||
| 36 | public void setArmes(ArrayList<Arme> weapon_list){ | ||
| 37 | weapon_names = new String[weapon_list.size()]; | ||
| 38 | for(int i = 0; i < weapon_list.size(); i++) { | ||
| 39 | weapon_names[i] = weapon_list.get(i).getNom(); | ||
| 40 | } | ||
| 41 | } | ||
| 42 | public void setAptitudes(ArrayList<Aptitude> aptitude_list){ | ||
| 43 | aptitude_names = new String[aptitude_list.size()]; | ||
| 44 | for(int i = 0; i < aptitude_list.size(); i++) { | ||
| 45 | aptitude_names[i] = aptitude_list.get(i).getName(); | ||
| 46 | } | ||
| 47 | } | ||
| 48 | |||
| 49 | public void setAptAndWeapons(ArrayList<Figurine> fig_group) | ||
| 50 | { | ||
| 51 | /* -- ligne 1: numéro du group et nom figurine -- */ | ||
| 52 | HBox first_row = new HBox(); | ||
| 53 | |||
| 54 | // numéro du group de figurines identiques | ||
| 55 | Label number = new Label(Integer.toString(group_number)); | ||
| 56 | number.setAlignment(Pos.CENTER); | ||
| 57 | number.setMinHeight(25); | ||
| 58 | number.setMinWidth(25); | ||
| 59 | number.setStyle("-fx-text-fill: white; -fx-background-color: black; -fx-background-radius: 4;"); | ||
| 60 | HBox.setMargin(number, new Insets(0, 2, 2, 0)); | ||
| 61 | |||
| 62 | Label figurine_name = new Label(group_name); | ||
| 63 | first_row.getChildren().addAll(number, figurine_name); | ||
| 64 | |||
| 65 | |||
| 66 | /* -- ligne 2: menu déroulant choix de l'arme -- */ | ||
| 67 | ChoiceBox<String> select_weapon = new ChoiceBox<String>(); | ||
| 68 | |||
| 69 | // sécurité | ||
| 70 | for(int i = 0; i < weapon_names.length; i++) | ||
| 71 | { | ||
| 72 | select_weapon.getItems().add(weapon_names[i]); | ||
| 73 | } | ||
| 74 | |||
| 75 | // valeur initiale menu déroulante | ||
| 76 | Arme weapon = Battle.getSeletedWeapon(1, group_name); | ||
| 77 | if(weapon != null) { | ||
| 78 | select_weapon.setValue(weapon.getNom()); | ||
| 79 | } | ||
| 80 | else { | ||
| 81 | select_weapon.setValue(weapon_names[0]); | ||
| 82 | } | ||
| 83 | // caractéristiques | ||
| 84 | FlowPane weapon_stats = new FlowPane(); | ||
| 85 | setWeaponStats(weapon, weapon_stats); | ||
| 86 | |||
| 87 | select_weapon.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> { | ||
| 88 | ControlleurSimu.selectAWeapon(this, newValue, fig_group, weapon_stats); | ||
| 89 | }); | ||
| 90 | |||
| 91 | // choix du nombre d'attaquants (= nombre d'armes) | ||
| 92 | Slider nb_of_attackers = new Slider(0, group_size, Battle.getSelectedUnit(1).getAliveFigsOfAGroup(group_name)); | ||
| 93 | nb_of_attackers.setMajorTickUnit(1); | ||
| 94 | nb_of_attackers.setMinorTickCount(0); | ||
| 95 | nb_of_attackers.setSnapToTicks(true); | ||
| 96 | //nb_of_attackers.setShowTickMarks(true); | ||
| 97 | nb_of_attackers.setShowTickLabels(true); | ||
| 98 | //nb_of_attackers.setBlockIncrement(1); | ||
| 99 | |||
| 100 | nb_of_attackers.valueProperty().addListener((observable, oldValue, newValue) -> { | ||
| 101 | ControlleurSimu.AliveFigsChoice(1, newValue.intValue(), group_name); | ||
| 102 | }); | ||
| 103 | |||
| 104 | // checkbox | ||
| 105 | FlowPane aptitudes = new FlowPane(); | ||
| 106 | for(int i = 0; i < aptitude_names.length; i++) | ||
| 107 | { | ||
| 108 | CheckBox one_aptitude = new CheckBox(aptitude_names[i]); | ||
| 109 | one_aptitude.setStyle("-fx-padding: 2px;"); | ||
| 110 | aptitudes.getChildren().add(one_aptitude); | ||
| 111 | |||
| 112 | one_aptitude.setOnAction(e -> { | ||
| 113 | ControlleurSimu.checkOrUncheckAnAptitude(one_aptitude.isSelected(), one_aptitude.getText(), fig_group); | ||
| 114 | }); | ||
| 115 | } | ||
| 116 | |||
| 117 | this.getChildren().addAll(first_row, select_weapon, weapon_stats, nb_of_attackers, aptitudes); | ||
| 118 | } | ||
| 119 | |||
| 120 | public void setWeaponStats(Arme weapon, FlowPane weapon_stats) { | ||
| 121 | weapon_stats.setStyle("-fx-padding: 3px;"); | ||
| 122 | Label A = new Label("A " + weapon.getA() + " | "); | ||
| 123 | Label F = new Label("F " + weapon.getF() + " | "); | ||
| 124 | Label PA = new Label("PA " + weapon.getPA() + " | "); | ||
| 125 | Label D = new Label("D " + weapon.getD() + " | "); | ||
| 126 | Label portee = new Label("portée " + weapon.getPortee()); | ||
| 127 | weapon_stats.getChildren().addAll(A, F, PA, D, portee); | ||
| 128 | } | ||
| 129 | } | ||
| 130 | |||
diff --git a/src/main/java/vue/simulation/SimFigurinesVBox.java b/src/main/java/vue/simulation/SimFigurinesVBox.java new file mode 100644 index 0000000..4940917 --- /dev/null +++ b/src/main/java/vue/simulation/SimFigurinesVBox.java | |||
| @@ -0,0 +1,139 @@ | |||
| 1 | package vue.simulation; | ||
| 2 | |||
| 3 | import java.util.ArrayList; | ||
| 4 | import java.util.HashMap; | ||
| 5 | |||
| 6 | import application.Battle; | ||
| 7 | import controlleur.ControlleurSimu; | ||
| 8 | import javafx.geometry.Insets; | ||
| 9 | import javafx.geometry.Pos; | ||
| 10 | import javafx.scene.control.Button; | ||
| 11 | import javafx.scene.control.Label; | ||
| 12 | import javafx.scene.control.Slider; | ||
| 13 | import javafx.scene.control.Spinner; | ||
| 14 | import javafx.scene.image.Image; | ||
| 15 | import javafx.scene.image.ImageView; | ||
| 16 | import javafx.scene.layout.HBox; | ||
| 17 | import javafx.scene.layout.FlowPane; | ||
| 18 | import javafx.scene.layout.VBox; | ||
| 19 | import modele.Figurine; | ||
| 20 | import modele.Unit; | ||
| 21 | |||
| 22 | public class SimFigurinesVBox extends VBox | ||
| 23 | { | ||
| 24 | private Unit unit; | ||
| 25 | private int column; | ||
| 26 | private ArrayList<SimAptAndWeaponsVBox> weapons_aptitudes_menu_view = new ArrayList<SimAptAndWeaponsVBox>(); | ||
| 27 | private boolean open = false; // les figurines sont cachées par défaut | ||
| 28 | |||
| 29 | public SimFigurinesVBox(int col, Unit unit){ | ||
| 30 | column = col; | ||
| 31 | this.unit = unit; | ||
| 32 | this.setStyle("-fx-padding: 2px;"); | ||
| 33 | } | ||
| 34 | |||
| 35 | public boolean isOpen(){ | ||
| 36 | return open; | ||
| 37 | } | ||
| 38 | public void changeState(){ | ||
| 39 | open ^= true; // inversion de bouléen avec un masque 00000001 | ||
| 40 | } | ||
| 41 | |||
| 42 | public void setFigurines() | ||
| 43 | { | ||
| 44 | /* -- boucle sur les groupes de figuriones -- */ | ||
| 45 | int i = 0; // valeurs des boutons numérotés | ||
| 46 | for(HashMap.Entry<String, ArrayList<Figurine>> entry : unit.getIdenticalFigsGroups().entrySet()) | ||
| 47 | { | ||
| 48 | FlowPane fig_group = new FlowPane(); | ||
| 49 | //fig_group.setStyle("-fx-background-color: rgb(220, 220, 220);"); | ||
| 50 | String fig_name = entry.getKey(); | ||
| 51 | ArrayList<Figurine> fig_list = entry.getValue(); | ||
| 52 | i++; | ||
| 53 | if(column == 1) | ||
| 54 | { | ||
| 55 | // boutons numérotés des groupes de figurines | ||
| 56 | Button number = new Button(Integer.toString(i)); | ||
| 57 | number.setAlignment(Pos.CENTER); | ||
| 58 | number.setMinHeight(25); | ||
| 59 | number.setMinWidth(25); | ||
| 60 | number.setStyle("-fx-text-fill: white; -fx-background-color: black;"); | ||
| 61 | fig_group.getChildren().add(number); | ||
| 62 | |||
| 63 | // zone des armes et aptitudes | ||
| 64 | SimAptAndWeaponsVBox weapons_aptitudes_menu = new SimAptAndWeaponsVBox(); | ||
| 65 | weapons_aptitudes_menu.setFigGroup(i, fig_name, fig_list.size()); | ||
| 66 | weapons_aptitudes_menu_view.add(weapons_aptitudes_menu); | ||
| 67 | |||
| 68 | number.setOnAction(e -> | ||
| 69 | { | ||
| 70 | ControlleurSimu.makeWeaponsAndAptitudeZone(fig_list, weapons_aptitudes_menu); | ||
| 71 | }); | ||
| 72 | } | ||
| 73 | else { | ||
| 74 | Label fig_name_label = new Label(fig_name); | ||
| 75 | fig_name_label.setStyle("-fx-padding: 0 5px 0 0"); | ||
| 76 | fig_group.getChildren().add(fig_name_label); | ||
| 77 | |||
| 78 | Slider nb_of_defenders = new Slider(0, fig_list.size(), | ||
| 79 | Battle.getSelectedUnit(2).getAliveFigsOfAGroup(fig_name)); | ||
| 80 | nb_of_defenders.setMajorTickUnit(1); | ||
| 81 | nb_of_defenders.setMinorTickCount(0); | ||
| 82 | nb_of_defenders.setSnapToTicks(true); | ||
| 83 | //nb_of_attackers.setShowTickMarks(true); | ||
| 84 | nb_of_defenders.setShowTickLabels(true); | ||
| 85 | //nb_of_attackers.setBlockIncrement(1); | ||
| 86 | |||
| 87 | fig_group.getChildren().add(nb_of_defenders); | ||
| 88 | |||
| 89 | nb_of_defenders.valueProperty().addListener((observable, oldValue, newValue) -> { | ||
| 90 | ControlleurSimu.AliveFigsChoice(2, newValue.intValue(), fig_name); | ||
| 91 | }); | ||
| 92 | } | ||
| 93 | |||
| 94 | |||
| 95 | /* -- figurines d'un groupe -- */ | ||
| 96 | for(Figurine fig : fig_list) | ||
| 97 | { | ||
| 98 | HBox one_fig_box = new HBox(); | ||
| 99 | Image one_image; | ||
| 100 | if(fig.getHP() > 0) { | ||
| 101 | one_image = new Image("/images/android-fill.png"); | ||
| 102 | } | ||
| 103 | else { | ||
| 104 | one_image = new Image("/images/android-line.png"); | ||
| 105 | } | ||
| 106 | ImageView one_image_box = new ImageView(); | ||
| 107 | one_image_box.setPreserveRatio(true); | ||
| 108 | //one_image_box.setFitHeight(24); // appeler une des deux méthodes de dimensionnement | ||
| 109 | one_image_box.setFitWidth(24); | ||
| 110 | one_image_box.setImage(one_image); | ||
| 111 | one_fig_box.getChildren().add(one_image_box); | ||
| 112 | |||
| 113 | if(column == 1) { | ||
| 114 | Label hp_label = new Label(fig.getHP() + " PV "); | ||
| 115 | one_fig_box.getChildren().add(hp_label); | ||
| 116 | } | ||
| 117 | else { | ||
| 118 | Label hp_label = new Label("PV:"); | ||
| 119 | Spinner<Integer> spinner = new Spinner<>(0, fig.getHPMax(), fig.getHP()); | ||
| 120 | spinner.setMaxWidth(55); | ||
| 121 | one_fig_box.getChildren().add(hp_label); | ||
| 122 | one_fig_box.getChildren().add(spinner); | ||
| 123 | one_fig_box.setStyle("-fx-padding: 0 3px 0 0;"); | ||
| 124 | |||
| 125 | spinner.valueProperty().addListener((obs, oldValue, newValue) -> { | ||
| 126 | ControlleurSimu.hpUpdate(newValue, fig, one_image_box); | ||
| 127 | }); | ||
| 128 | } | ||
| 129 | |||
| 130 | SimFigurinesVBox.setMargin(one_fig_box, new Insets(5)); | ||
| 131 | fig_group.getChildren().add(one_fig_box); | ||
| 132 | } | ||
| 133 | SimFigurinesVBox.setMargin(fig_group, new Insets(3)); | ||
| 134 | |||
| 135 | this.getChildren().add(fig_group); | ||
| 136 | } | ||
| 137 | } | ||
| 138 | } | ||
| 139 | |||
diff --git a/src/main/java/vue/simulation/SimHistogramme.java b/src/main/java/vue/simulation/SimHistogramme.java new file mode 100644 index 0000000..519c90b --- /dev/null +++ b/src/main/java/vue/simulation/SimHistogramme.java | |||
| @@ -0,0 +1,101 @@ | |||
| 1 | package vue.simulation; | ||
| 2 | import javafx.application.Application; | ||
| 3 | import javafx.scene.Scene; | ||
| 4 | import javafx.scene.chart.Axis; | ||
| 5 | import javafx.scene.chart.BarChart; | ||
| 6 | import javafx.scene.chart.CategoryAxis; | ||
| 7 | import javafx.scene.chart.NumberAxis; | ||
| 8 | import javafx.scene.chart.XYChart; | ||
| 9 | import javafx.scene.layout.Pane; | ||
| 10 | import javafx.scene.layout.Priority; | ||
| 11 | import javafx.scene.layout.VBox; | ||
| 12 | import javafx.stage.Stage; | ||
| 13 | |||
| 14 | public class SimHistogramme extends Pane{ | ||
| 15 | private Pane p; | ||
| 16 | |||
| 17 | |||
| 18 | |||
| 19 | // public SimHistogramme() { | ||
| 20 | // super(); | ||
| 21 | // } | ||
| 22 | |||
| 23 | public static void setHist(int[] tabdegat ,int[] tabmort, float degat_moyen ,float mort_moyen,Pane p) { | ||
| 24 | Axis<String> xAxis = new CategoryAxis(); | ||
| 25 | xAxis.setLabel("nbr mort"); | ||
| 26 | |||
| 27 | NumberAxis yAxis = new NumberAxis(); | ||
| 28 | yAxis.setLabel("pourcentage"); | ||
| 29 | |||
| 30 | Axis<String> xAxis2 = new CategoryAxis(); | ||
| 31 | xAxis2.setLabel("nbr degat"); | ||
| 32 | |||
| 33 | javafx.scene.chart.NumberAxis yAxis2 = new NumberAxis(); | ||
| 34 | yAxis2.setLabel("pourcentage"); | ||
| 35 | |||
| 36 | // Create a BarChart | ||
| 37 | BarChart<String, Number> barChart = new BarChart<String, Number>(xAxis, yAxis); | ||
| 38 | BarChart<String, Number> barChart2 = new BarChart<String, Number>(xAxis2, yAxis2); | ||
| 39 | |||
| 40 | // Series 1 - Data of 2014 | ||
| 41 | XYChart.Series<String, Number> dataSeries1 = new XYChart.Series<String, Number>(); | ||
| 42 | //dataSeries1.setName("mort moyen : "+mort_moyen); | ||
| 43 | for(int i=0;i<tabmort.length;i++) { | ||
| 44 | if(tabmort[i]!=0) { | ||
| 45 | dataSeries1.getData().add(new XYChart.Data<String, Number>(""+i , tabmort[i]/100)); | ||
| 46 | } | ||
| 47 | } | ||
| 48 | |||
| 49 | //barChart.getData().add(dataSeries1); | ||
| 50 | |||
| 51 | |||
| 52 | // Series 1 - Data of 2014 | ||
| 53 | XYChart.Series<String, Number> dataSeries2 = new XYChart.Series<String, Number>(); | ||
| 54 | //dataSeries2.setName("degat moyen : "+degat_moyen); | ||
| 55 | for(int i=0;i<tabdegat.length;i++) { | ||
| 56 | if(tabdegat[i]!=0) { | ||
| 57 | dataSeries2.getData().add(new XYChart.Data<String, Number>(""+i , tabdegat[i]/100)); | ||
| 58 | } | ||
| 59 | } | ||
| 60 | |||
| 61 | barChart.getData().add(dataSeries1); | ||
| 62 | barChart2.getData().add(dataSeries2); | ||
| 63 | |||
| 64 | |||
| 65 | |||
| 66 | VBox vbox = new VBox(); | ||
| 67 | vbox.getChildren().add(barChart); | ||
| 68 | vbox.getChildren().add(barChart2); | ||
| 69 | barChart.maxWidthProperty().bind(p.widthProperty()); | ||
| 70 | barChart2.maxWidthProperty().bind(p.widthProperty()); | ||
| 71 | barChart2.prefHeight(150); | ||
| 72 | barChart.prefHeight(150); | ||
| 73 | barChart.lookupAll(".default-color0.chart-bar") | ||
| 74 | .forEach(n -> n.setStyle("-fx-bar-fill: red;")); | ||
| 75 | barChart2.lookupAll(".default-color0.chart-bar") | ||
| 76 | .forEach(n -> n.setStyle("-fx-bar-fill: green;")); | ||
| 77 | |||
| 78 | |||
| 79 | barChart.setMaxHeight(220); | ||
| 80 | barChart2.setMaxHeight(220); | ||
| 81 | barChart.prefHeight(200); | ||
| 82 | barChart.setLegendVisible(false); | ||
| 83 | barChart2.setLegendVisible(false); | ||
| 84 | barChart.setTitle("nbr mort moyen : "+mort_moyen); | ||
| 85 | barChart2.setTitle("nbr degat moyen : "+degat_moyen); | ||
| 86 | barChart2.prefHeight(200); | ||
| 87 | VBox.setVgrow(barChart, Priority.ALWAYS); | ||
| 88 | VBox.setVgrow(barChart2, Priority.ALWAYS); | ||
| 89 | //vbox.setSpacing(10); | ||
| 90 | |||
| 91 | |||
| 92 | p.getChildren().add(vbox); | ||
| 93 | } | ||
| 94 | |||
| 95 | |||
| 96 | |||
| 97 | |||
| 98 | //BarChart<String, Number> barChart = new BarChart<String, Number>(xAxis, yAxis); | ||
| 99 | |||
| 100 | } | ||
| 101 | |||
diff --git a/src/main/java/vue/simulation/SimUnitsVBox.java b/src/main/java/vue/simulation/SimUnitsVBox.java new file mode 100644 index 0000000..df02f82 --- /dev/null +++ b/src/main/java/vue/simulation/SimUnitsVBox.java | |||
| @@ -0,0 +1,65 @@ | |||
| 1 | package vue.simulation; | ||
| 2 | |||
| 3 | import java.util.ArrayList; | ||
| 4 | |||
| 5 | import application.Battle; | ||
| 6 | import controlleur.ControlleurSimu; | ||
| 7 | import javafx.scene.control.Button; | ||
| 8 | import javafx.scene.layout.VBox; | ||
| 9 | import modele.Unit; | ||
| 10 | |||
| 11 | public class SimUnitsVBox extends VBox | ||
| 12 | { | ||
| 13 | private ArrayList<Button> buttons = new ArrayList<Button>(); | ||
| 14 | private ArrayList<SimFigurinesVBox> fig_boxes = new ArrayList<SimFigurinesVBox>(); | ||
| 15 | private int column; // = 1 ou 2 | ||
| 16 | |||
| 17 | public SimUnitsVBox(int col){ | ||
| 18 | column = col; | ||
| 19 | this.setStyle("-fx-padding: 2px;"); | ||
| 20 | } | ||
| 21 | |||
| 22 | // getters | ||
| 23 | public ArrayList<Button> getButtons(){ | ||
| 24 | return buttons; | ||
| 25 | } | ||
| 26 | public ArrayList<SimFigurinesVBox> getFigBoxes(){ | ||
| 27 | return fig_boxes; | ||
| 28 | } | ||
| 29 | |||
| 30 | // afficher les unités de la liste déroulée | ||
| 31 | public void setList(int num_list) | ||
| 32 | { | ||
| 33 | ArrayList<Unit> units = Battle.getSelectedList(num_list).getUnits(); | ||
| 34 | for(int i = 0; i < units.size(); i++) | ||
| 35 | { | ||
| 36 | VBox one_unit = new VBox(); | ||
| 37 | |||
| 38 | // chaque unité est un bouton pour dérouler des figurines | ||
| 39 | Button tmp_button = new Button(units.get(i).getName()); | ||
| 40 | tmp_button.setMaxWidth(Double.MAX_VALUE); | ||
| 41 | one_unit.getChildren().add(tmp_button); | ||
| 42 | buttons.add(tmp_button); | ||
| 43 | |||
| 44 | // créer une zone de figurines par unité | ||
| 45 | SimFigurinesVBox one_fig_box = new SimFigurinesVBox(column, units.get(i)); | ||
| 46 | one_unit.getChildren().add(one_fig_box); | ||
| 47 | fig_boxes.add(one_fig_box); | ||
| 48 | |||
| 49 | this.getChildren().add(one_unit); | ||
| 50 | } | ||
| 51 | |||
| 52 | /* -- activation des boutons pour dérouler les unités --*/ | ||
| 53 | for(int i = 0; i < buttons.size(); i++) | ||
| 54 | { | ||
| 55 | final int j = i; // merci chatgpt pour le trick! | ||
| 56 | // java interdit à i et c d'être paramètres de la fonction lambda parce qu'ils changent à chaque itération | ||
| 57 | // on garantit que col et j seront constants (final) dans la méthode setOnAction | ||
| 58 | |||
| 59 | buttons.get(i).setOnAction(e -> | ||
| 60 | { | ||
| 61 | ControlleurSimu.selectAnUnit(this, column, j); | ||
| 62 | }); | ||
| 63 | } | ||
| 64 | } | ||
| 65 | } | ||
