summaryrefslogtreecommitdiff
path: root/src/main/java/modele/Unit.java
blob: 11b51d963a43d8463e4c8b7a66511359fcb5b60d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package modele;

import java.util.ArrayList;
import java.util.HashMap;



public class Unit {
	
	private ArrayList<Figurine> figurines;
	private HashMap<String, ArrayList<Figurine>> identical_figs = new HashMap<String, ArrayList<Figurine>>();
	private int id;
	private String nom;
	private int points;
	private String logo;
	private Armee armee;
	
	public Unit(ArrayList<Figurine> 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<Figurine> 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<Figurine> list_unit) {
		this.nom = nom_unit;
		this.figurines = list_unit;
	}
	
	// getters
	public ArrayList<Figurine> getFigurines() {
		return figurines;
	}
	public HashMap<String, ArrayList<Figurine>> 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<Figurine> 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<Figurine>()); // 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 + "";
	}
}