passage de Player.abilities en privé et correction commit précédent
Clement Colmerauer

Clement Colmerauer commited on 2024-12-13 09:49:46
Showing 10 changed files, with 21 additions and 6 deletions.

... ...
@@ -8,7 +8,13 @@ import re.forestier.edu.lib.Natural;
8 8
 
9 9
 public class Player {
10 10
     private static final Natural defaultMaxHp = Natural.valueOf(20);
11
-    private static final Integer[] xpForlevel = {0,10,27,57,111}; //Level = i+1 
11
+    private static final Natural[] xpForlevel = {
12
+        Natural.valueOf(0),
13
+        Natural.valueOf(10),
14
+        Natural.valueOf(27),
15
+        Natural.valueOf(57),
16
+        Natural.valueOf(111)
17
+    }; //Level = i+1 
12 18
        //We consider that level is a player thing, not a job one.
13 19
 
14 20
     private String playerName;
... ...
@@ -23,7 +29,7 @@ public class Player {
23 29
     private Natural currentHealthPoints;
24 30
     private Natural xp;
25 31
 
26
-    public HashMap<Ability, Integer> abilities; //Ability = stat
32
+    private HashMap<Ability, Integer> abilities; //Ability = stat
27 33
     public ArrayList<String> inventory;
28 34
 
29 35
     public Player(String playerName, String avatar_name, Jobs avatarClass, int money, ArrayList<String> inventory) {
... ...
@@ -84,6 +90,15 @@ public class Player {
84 90
         return this.currentHealthPoints.toInt();
85 91
     }
86 92
 
93
+    public HashMap<Ability,Integer> getAbilities()
94
+    {
95
+        HashMap<Ability,Integer> copy = new HashMap<Ability,Integer>(); //In doubt, deep copy
96
+        this.abilities.forEach((key,value) -> {
97
+            copy.put(key,value);}
98
+        );
99
+        return copy;
100
+    }
101
+
87 102
     public void heal(int hp)
88 103
     {
89 104
         if(hp < 0 )
... ...
@@ -120,7 +135,7 @@ public class Player {
120 135
         Natural ancientLevel = (Natural)this.level.clone();
121 136
         this.xp.add(Natural.valueOf(xp));
122 137
         int i = 0;
123
-        while(i < xpForlevel.length && this.xp.toInt() >= xpForlevel[i])
138
+        while(i < xpForlevel.length && this.xp.compareTo(xpForlevel[i]) <= 0)
124 139
         {
125 140
             i++;
126 141
         }
... ...
@@ -116,8 +116,8 @@ public class UnitTests {
116 116
         int tailleinv = p.inventory.size();
117 117
         p.addXp(10);
118 118
         /*fail(p.avatarClass.getAbilityPerLevel().toString());
119
-        fail(p.abilities.toString());*/
120
-        int atk = p.abilities.get(Ability.ATK);
119
+        fail(p.getAbilities().toString());*/
120
+        int atk = p.getAbilities().get(Ability.ATK);
121 121
         assertNotEquals(p.inventory.size(),tailleinv);
122 122
         assertThat(p.getLevel(),is(2));
123 123
         p.addXp(17);
... ...
@@ -127,7 +127,7 @@ public class UnitTests {
127 127
         p.addXp(54);
128 128
         assertThat(p.getLevel(),is(5));
129 129
         p.addXp(1);
130
-        assertNotEquals(p.abilities.get(Ability.ATK),atk);
130
+        assertNotEquals(p.getAbilities().get(Ability.ATK),atk);
131 131
     }
132 132
 
133 133
     @Test
134 134