diff options
Diffstat (limited to 'src/main/java/application/Battle.java')
| -rw-r--r-- | src/main/java/application/Battle.java | 90 |
1 files changed, 90 insertions, 0 deletions
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 | } | ||
