passage de player.money en Natural
Clement COLMERAUER

Clement COLMERAUER commited on 2024-10-24 16:43:09
Showing 20 changed files, with 41 additions and 38 deletions.

... ...
@@ -41,7 +41,7 @@
41 41
 </td>
42 42
 <td>
43 43
 <div class="infoBox" id="duration">
44
-<div class="counter">0.167s</div>
44
+<div class="counter">0.169s</div>
45 45
 <p>duration</p>
46 46
 </div>
47 47
 </td>
... ...
@@ -76,7 +76,7 @@
76 76
 </thead>
77 77
 <tr>
78 78
 <td class="success">testAffichageBase()</td>
79
-<td class="success">0.167s</td>
79
+<td class="success">0.169s</td>
80 80
 <td class="success">passed</td>
81 81
 </tr>
82 82
 </table>
... ...
@@ -89,7 +89,7 @@
89 89
 <input id="line-wrapping-toggle" type="checkbox" autocomplete="off"/>
90 90
 </label>
91 91
 </div>Generated by 
92
-<a href="http://www.gradle.org">Gradle 8.8</a> at 24 oct. 2024, 16:29:02</p>
92
+<a href="http://www.gradle.org">Gradle 8.8</a> at 24 oct. 2024, 16:42:45</p>
93 93
 </div>
94 94
 </div>
95 95
 </body>
... ...
@@ -41,7 +41,7 @@
41 41
 </td>
42 42
 <td>
43 43
 <div class="infoBox" id="duration">
44
-<div class="counter">0.021s</div>
44
+<div class="counter">0.019s</div>
45 45
 <p>duration</p>
46 46
 </div>
47 47
 </td>
... ...
@@ -84,7 +84,7 @@
84 84
 <tr>
85 85
 <td class="success">Main</td>
86 86
 <td class="success">testMain()</td>
87
-<td class="success">0.006s</td>
87
+<td class="success">0.005s</td>
88 88
 <td class="success">passed</td>
89 89
 </tr>
90 90
 <tr>
... ...
@@ -96,37 +96,37 @@
96 96
 <tr>
97 97
 <td class="success">Natural Tests</td>
98 98
 <td class="success">testNatural()</td>
99
-<td class="success">0.003s</td>
99
+<td class="success">0.002s</td>
100 100
 <td class="success">passed</td>
101 101
 </tr>
102 102
 <tr>
103 103
 <td class="success">Constructor Player</td>
104 104
 <td class="success">testPlayerConstructor()</td>
105
-<td class="success">0s</td>
105
+<td class="success">0.001s</td>
106 106
 <td class="success">passed</td>
107 107
 </tr>
108 108
 <tr>
109 109
 <td class="success">Sample test</td>
110 110
 <td class="success">testPlayerName()</td>
111
-<td class="success">0s</td>
111
+<td class="success">0.001s</td>
112 112
 <td class="success">passed</td>
113 113
 </tr>
114 114
 <tr>
115 115
 <td class="success">removeMoney</td>
116 116
 <td class="success">testRemoveMoney()</td>
117
-<td class="success">0.006s</td>
117
+<td class="success">0.004s</td>
118 118
 <td class="success">passed</td>
119 119
 </tr>
120 120
 <tr>
121 121
 <td class="success">ex &amp; lvl</td>
122 122
 <td class="success">testRetrieveLevel()</td>
123
-<td class="success">0.003s</td>
123
+<td class="success">0.002s</td>
124 124
 <td class="success">passed</td>
125 125
 </tr>
126 126
 <tr>
127 127
 <td class="success">Construcor UpdatePlayer</td>
128 128
 <td class="success">testUpdatePlayer()</td>
129
-<td class="success">0s</td>
129
+<td class="success">0.001s</td>
130 130
 <td class="success">passed</td>
131 131
 </tr>
132 132
 </table>
... ...
@@ -139,7 +139,7 @@
139 139
 <input id="line-wrapping-toggle" type="checkbox" autocomplete="off"/>
140 140
 </label>
141 141
 </div>Generated by 
142
-<a href="http://www.gradle.org">Gradle 8.8</a> at 24 oct. 2024, 16:29:02</p>
142
+<a href="http://www.gradle.org">Gradle 8.8</a> at 24 oct. 2024, 16:42:45</p>
143 143
 </div>
144 144
 </div>
145 145
 </body>
... ...
@@ -112,7 +112,7 @@
112 112
 <td>1</td>
113 113
 <td>0</td>
114 114
 <td>0</td>
115
-<td>0.167s</td>
115
+<td>0.169s</td>
116 116
 <td class="success">100%</td>
117 117
 </tr>
118 118
 <tr>
... ...
@@ -122,7 +122,7 @@
122 122
 <td>9</td>
123 123
 <td>0</td>
124 124
 <td>0</td>
125
-<td>0.021s</td>
125
+<td>0.019s</td>
126 126
 <td class="success">100%</td>
127 127
 </tr>
128 128
 </tbody>
... ...
@@ -136,7 +136,7 @@
136 136
 <input id="line-wrapping-toggle" type="checkbox" autocomplete="off"/>
137 137
 </label>
138 138
 </div>Generated by 
139
-<a href="http://www.gradle.org">Gradle 8.8</a> at 24 oct. 2024, 16:29:02</p>
139
+<a href="http://www.gradle.org">Gradle 8.8</a> at 24 oct. 2024, 16:42:45</p>
140 140
 </div>
141 141
 </div>
142 142
 </body>
... ...
@@ -83,7 +83,7 @@
83 83
 <td>1</td>
84 84
 <td>0</td>
85 85
 <td>0</td>
86
-<td>0.167s</td>
86
+<td>0.169s</td>
87 87
 <td class="success">100%</td>
88 88
 </tr>
89 89
 <tr>
... ...
@@ -93,7 +93,7 @@
93 93
 <td>9</td>
94 94
 <td>0</td>
95 95
 <td>0</td>
96
-<td>0.021s</td>
96
+<td>0.019s</td>
97 97
 <td class="success">100%</td>
98 98
 </tr>
99 99
 </table>
... ...
@@ -106,7 +106,7 @@
106 106
 <input id="line-wrapping-toggle" type="checkbox" autocomplete="off"/>
107 107
 </label>
108 108
 </div>Generated by 
109
-<a href="http://www.gradle.org">Gradle 8.8</a> at 24 oct. 2024, 16:29:02</p>
109
+<a href="http://www.gradle.org">Gradle 8.8</a> at 24 oct. 2024, 16:42:45</p>
110 110
 </div>
111 111
 </div>
112 112
 </body>
... ...
@@ -1,7 +1,7 @@
1 1
 <?xml version="1.0" encoding="UTF-8"?>
2
-<testsuite name="re.forestier.edu.GlobalTest" tests="1" skipped="0" failures="0" errors="0" timestamp="2024-10-24T14:29:02" hostname="a206pc27L.local.isima.fr" time="0.167">
2
+<testsuite name="re.forestier.edu.GlobalTest" tests="1" skipped="0" failures="0" errors="0" timestamp="2024-10-24T14:42:44" hostname="a206pc27L.local.isima.fr" time="0.169">
3 3
   <properties/>
4
-  <testcase name="testAffichageBase()" classname="re.forestier.edu.GlobalTest" time="0.167"/>
4
+  <testcase name="testAffichageBase()" classname="re.forestier.edu.GlobalTest" time="0.169"/>
5 5
   <system-out><![CDATA[]]></system-out>
6 6
   <system-err><![CDATA[]]></system-err>
7 7
 </testsuite>
... ...
@@ -1,15 +1,15 @@
1 1
 <?xml version="1.0" encoding="UTF-8"?>
2
-<testsuite name="re.forestier.edu.UnitTests" tests="9" skipped="0" failures="0" errors="0" timestamp="2024-10-24T14:29:02" hostname="a206pc27L.local.isima.fr" time="0.028">
2
+<testsuite name="re.forestier.edu.UnitTests" tests="9" skipped="0" failures="0" errors="0" timestamp="2024-10-24T14:42:45" hostname="a206pc27L.local.isima.fr" time="0.021">
3 3
   <properties/>
4
-  <testcase name="Main" classname="re.forestier.edu.UnitTests" time="0.006"/>
5
-  <testcase name="removeMoney" classname="re.forestier.edu.UnitTests" time="0.006"/>
6
-  <testcase name="ex &amp; lvl" classname="re.forestier.edu.UnitTests" time="0.003"/>
4
+  <testcase name="Main" classname="re.forestier.edu.UnitTests" time="0.005"/>
5
+  <testcase name="removeMoney" classname="re.forestier.edu.UnitTests" time="0.004"/>
6
+  <testcase name="ex &amp; lvl" classname="re.forestier.edu.UnitTests" time="0.002"/>
7 7
   <testcase name="addMoney" classname="re.forestier.edu.UnitTests" time="0.001"/>
8
-  <testcase name="Construcor UpdatePlayer" classname="re.forestier.edu.UnitTests" time="0.0"/>
8
+  <testcase name="Construcor UpdatePlayer" classname="re.forestier.edu.UnitTests" time="0.001"/>
9 9
   <testcase name="majDeFinDeTour" classname="re.forestier.edu.UnitTests" time="0.002"/>
10
-  <testcase name="Constructor Player" classname="re.forestier.edu.UnitTests" time="0.0"/>
11
-  <testcase name="Natural Tests" classname="re.forestier.edu.UnitTests" time="0.003"/>
12
-  <testcase name="Sample test" classname="re.forestier.edu.UnitTests" time="0.0"/>
10
+  <testcase name="Constructor Player" classname="re.forestier.edu.UnitTests" time="0.001"/>
11
+  <testcase name="Natural Tests" classname="re.forestier.edu.UnitTests" time="0.002"/>
12
+  <testcase name="Sample test" classname="re.forestier.edu.UnitTests" time="0.001"/>
13 13
   <system-out><![CDATA[]]></system-out>
14 14
   <system-err><![CDATA[]]></system-err>
15 15
 </testsuite>
... ...
@@ -14,8 +14,7 @@ public class Player {
14 14
     private String avatarName;
15 15
     private String avatarClass;
16 16
 
17
-    private Integer money;
18
-    private Float __real_money__;
17
+    private Natural money;
19 18
 
20 19
     private Natural level;
21 20
     private Natural maxHealthPoint;
... ...
@@ -44,7 +43,7 @@ public class Player {
44 43
         this.playerName = playerName;
45 44
         this.avatarName = avatar_name;
46 45
         this.avatarClass = avatarClass;
47
-        this.money = Integer.valueOf(money);
46
+        this.money = Natural.valueOf(money);
48 47
         this.inventory = inventory;
49 48
         this.level = Natural.valueOf(1);
50 49
         this.xp = Natural.valueOf(0);
... ...
@@ -65,7 +64,7 @@ public class Player {
65 64
             
66 65
     public Integer getMoney()
67 66
     {
68
-        return this.money;
67
+        return this.money.toInt();
69 68
     }
70 69
 
71 70
     public int getLevel()
... ...
@@ -141,15 +140,19 @@ public class Player {
141 140
         }
142 141
     }
143 142
 
144
-    public void removeMoney(int amount) throws IllegalArgumentException {
145
-        if (money - amount < 0) {
143
+    public void removeMoney(int amount)
144
+    {
145
+        Natural toRemove = Natural.valueOf(amount);
146
+        if (this.money.compareTo(toRemove) == 1) 
147
+        {
146 148
             throw new IllegalArgumentException("Player can't have a negative money!");
147 149
         }
148
-
149
-        money = Integer.parseInt(money.toString()) - amount;
150
+        this.money.substract(toRemove);
150 151
     }
151
-    public void addMoney(int amount) { 
152
-        money = money + amount;
152
+    public void addMoney(int amount) 
153
+    { 
154
+        Natural toAdd = Natural.valueOf(amount);
155
+        this.money.add(toAdd);
153 156
     }
154 157
 
155 158
     @Override 
156 159