From 0c2c3ee5a55f36d270171f2f67938542e251fdc5 Mon Sep 17 00:00:00 2001 From: polo Date: Thu, 2 Jul 2026 00:14:17 +0200 Subject: fork utilisant maven --- src/main/java/modele/Unit.java | 96 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 src/main/java/modele/Unit.java (limited to 'src/main/java/modele/Unit.java') 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 @@ +package modele; + +import java.util.ArrayList; +import java.util.HashMap; + + + +public class Unit { + + private ArrayList figurines; + private HashMap> identical_figs = new HashMap>(); + private int id; + private String nom; + private int points; + private String logo; + private Armee armee; + + public Unit(ArrayList figurines, String nom, int points, String logo, Armee armee) { + this.figurines = figurines; + this.makeIdenticalFigsGroups(); + this.nom = nom; + this.points = points; + this.logo = logo; + this.armee = armee; + } + public Unit(ArrayList figurines,int id, String nom, int points,String logo, Armee armee) { + this.id = id; + this.figurines = figurines; + this.nom = nom; + this.logo = logo; + this.points = points; + this.armee = armee; + } + + // bientôt inutile + public Unit(String nom_unit,ArrayList list_unit) { + this.nom = nom_unit; + this.figurines = list_unit; + } + + // getters + public ArrayList getFigurines() { + return figurines; + } + public HashMap> getIdenticalFigsGroups(){ + return identical_figs; + } + + // est exécuté dès qu'on touche au slider + public int getAliveFigsOfAGroup(String group_name) { + int nb = 0; + for(Figurine fig : identical_figs.get(group_name)) + { + if(fig.getHP() > 0) { + nb++; + } + } + return nb; + } + + public int getId() { + return id; + } + public String getName() { + return nom; + } + public int getPoints() { + return points; + } + public String getLogo() { + return nom; + } + public Armee getArmee() { + return armee; + } + + public void setFigurine(ArrayList liste) { + figurines = liste; + } + + private void makeIdenticalFigsGroups() { + for(Figurine fig : figurines) + { + if(!identical_figs.containsKey(fig.getNom())) // si nouveau type de figurines + { + identical_figs.put(fig.getNom(), new ArrayList()); // création d'uné paire clé/liste dans la hashmap + } + identical_figs.get(fig.getNom()).add(fig); // récupérer la liste correspondante à la clé et ajouter la figurine + } + } + + @Override + public String toString() { + return "" + nom + ""; + } +} -- cgit v1.2.3