Revert "integration entier naturel et ajout surcharge opérateur (ne marche pas)"
Clement COLMERAUER

Clement COLMERAUER commited on 2024-10-21 10:31:52
Showing 8 changed files, with 39 additions and 46 deletions.


This reverts commit 4531fec7897f78101d984b89418cadec51e89c32.
... ...
@@ -2,19 +2,18 @@ package re.forestier.edu;
2 2
 import re.forestier.edu.rpg.Affichage;
3 3
 import re.forestier.edu.rpg.UpdatePlayer;
4 4
 import re.forestier.edu.rpg.Player;
5
-import re.forestier.edu.lib.Natural;
6 5
 
7 6
 import java.util.ArrayList;
8 7
 
9 8
 public class Main {
10 9
     public static void main(String[] args) {
11 10
         Player firstPlayer = new Player("Florian", "Ruzberg de Rivehaute", "DWARF", 200, new ArrayList<>());
12
-        firstPlayer.addMoney(Natural.valueOf(400));
11
+        firstPlayer.addMoney(400);
13 12
 
14
-        firstPlayer.addXp(Natural.valueOf(15));
13
+        firstPlayer.addXp(15);
15 14
         System.out.println(Affichage.afficherJoueur(firstPlayer));
16 15
         System.out.println("------------------");
17
-        firstPlayer.addXp(Natural.valueOf(20));
16
+        firstPlayer.addXp(20);
18 17
         System.out.println(Affichage.afficherJoueur(firstPlayer));
19 18
     }
20 19
 }
21 20
\ No newline at end of file
... ...
@@ -3,7 +3,6 @@ package re.forestier.edu.rpg;
3 3
 import java.util.Random;
4 4
 import java.util.ArrayList;
5 5
 import java.util.HashMap;
6
-import re.forestier.edu.lib.Natural;
7 6
 
8 7
 public class Player {
9 8
     private static final Integer[] xpForlevel = {0,10,27,57,111}; //Level = i+1 
... ...
@@ -13,12 +12,13 @@ public class Player {
13 12
     private String Avatar_name;
14 13
     private String AvatarClass;
15 14
 
16
-    private Natural money;
15
+    private Integer money;
16
+    private Float __real_money__;
17 17
 
18
-    private Natural level;
19
-    private Natural healthpoints;
20
-    private Natural currenthealthpoints;
21
-    private Natural xp;
18
+    private int level;
19
+    private int healthpoints;
20
+    private int currenthealthpoints;
21
+    private int xp;
22 22
 
23 23
     public HashMap<String, Integer> abilities; //Ability = stat
24 24
     public ArrayList<String> inventory;
... ...
@@ -32,10 +32,10 @@ public class Player {
32 32
         this.playerName = playerName;
33 33
         Avatar_name = avatar_name;
34 34
         AvatarClass = avatarClass;
35
-        this.money = Natural.valueOf(money);
35
+        this.money = Integer.valueOf(money);
36 36
         this.inventory = inventory;
37
-        this.level = Natural.valueOf(1);
38
-        this.xp = Natural.valueOf(0);
37
+        this.level = 1;
38
+        this.xp = 0;
39 39
         this.abilities = UpdatePlayer.abilitiesPerTypeAndLevel().get(AvatarClass).get(1);
40 40
     }
41 41
 
... ...
@@ -49,42 +49,42 @@ public class Player {
49 49
         return this.Avatar_name;
50 50
     }
51 51
             
52
-    public Natural getMoney()
52
+    public Integer getMoney()
53 53
     {
54 54
         return this.money;
55 55
     }
56 56
 
57
-    public Natural getLevel()
57
+    public int getLevel()
58 58
     {
59 59
         return this.level;
60 60
     }
61 61
 
62
-    public Natural getHealthPoints()
62
+    public int getHealthPoints()
63 63
     {
64 64
         return this.healthpoints;
65 65
     }
66 66
 
67
-    public void setHealthPoints(Natural hp)
67
+    public void setHealthPoints(int hp)
68 68
     {
69
-        this.healthpoints = hp.clone();
69
+        this.healthpoints = hp;
70 70
     }
71 71
 
72
-    public Natural getCurrentHealthPoints()
72
+    public int getCurrentHealthPoints()
73 73
     {
74
-        return this.currenthealthpoints.clone();
74
+        return this.currenthealthpoints;
75 75
     }
76 76
 
77 77
     public void setCurrentHealthPoints(int hp)
78 78
     {
79
-        this.currenthealthpoints = hp.clone();
79
+        this.currenthealthpoints = hp;
80 80
     }
81 81
 
82
-    public Natural getXp()
82
+    public int getXp()
83 83
     {
84 84
         return this.xp;
85 85
     }
86 86
 
87
-    public void setXp(Natural xp)
87
+    public void setXp(int xp)
88 88
     {
89 89
         this.xp = xp;
90 90
     }
... ...
@@ -93,18 +93,18 @@ public class Player {
93 93
         return AvatarClass;
94 94
     }
95 95
 
96
-    public void addXp(Natural xp) {
97
-        Natural ancientLevel = this.level;
98
-        this.xp.add(xp);
96
+    public void addXp(int xp) {
97
+        int ancientLevel = this.level;
98
+        this.xp += xp;
99 99
         int i = 0;
100 100
         while(i < xpForlevel.length && this.xp >= xpForlevel[i])
101 101
         {
102 102
             i++;
103 103
         }
104 104
 
105
-        this.level = Natural.valueof(i);
105
+        this.level = i;
106 106
 
107
-        if (this.level.compareTo(ancientLevel) == -1) {
107
+        if (this.level != ancientLevel) {
108 108
             // Player leveled-up!
109 109
             // Give a random object
110 110
             ;
... ...
@@ -119,16 +119,14 @@ public class Player {
119 119
         }
120 120
     }
121 121
 
122
-    public void removeMoney(Natural amount)
123
-    {
122
+    public void removeMoney(int amount) throws IllegalArgumentException {
124 123
         if (money - amount < 0) {
125 124
             throw new IllegalArgumentException("Player can't have a negative money!");
126 125
         }
127 126
 
128
-        money.remove(amount);
127
+        money = Integer.parseInt(money.toString()) - amount;
129 128
     }
130
-
131
-    public void addMoney(Natural amount) { 
132
-        money.add(amount);
129
+    public void addMoney(int amount) { 
130
+        money = money + amount;
133 131
     }
134 132
 }
135 133
\ No newline at end of file
... ...
@@ -2,7 +2,6 @@ package re.forestier.edu.rpg;
2 2
 
3 3
 import java.util.HashMap;
4 4
 import java.util.Random;
5
-import re.forestier.edu.lib.Natural;
6 5
 
7 6
 public class UpdatePlayer {
8 7
 
... ...
@@ -101,31 +100,31 @@ public class UpdatePlayer {
101 100
 
102 101
     // majFinDeTour met à jour les points de vie
103 102
     public static void majFinDeTour(Player player) {
104
-        if(player.getCurrentHealthPoints().equals(Natural.ZERO)) {
103
+        if(player.getCurrentHealthPoints() == 0) {
105 104
             System.out.println("Le joueur est KO !");
106 105
             return;
107 106
         }
108 107
 
109
-        if(player.getCurrentHealthPoints().compareTo(Natural.divide(player.getHealthPoints(),2)) == 1 ) {
108
+        if(player.getCurrentHealthPoints() < player.getHealthPoints()/2) {
110 109
             if(!player.getAvatarClass().equals("ADVENTURER")) {
111 110
                 if(player.getAvatarClass().equals("DWARF")) {
112 111
                     if(player.inventory.contains("Holy Elixir")) {
113
-                        player.setCurrentHealthPoints(Natural.add(player.getCurrentHealthPoints(),1));
112
+                        player.setCurrentHealthPoints(player.getCurrentHealthPoints()+1);
114 113
                     }
115
-                    player.setCurrentHealthPoints(Natural.add(player.getCurrentHealthPoints(),1));
114
+                    player.setCurrentHealthPoints(player.getCurrentHealthPoints()+1);
116 115
                 }
117 116
 
118 117
 
119 118
                 if(player.getAvatarClass().equals("ARCHER")) {
120
-                    player.setCurrentHealthPoints(Natural.add(player.getCurrentHealthPoints(),1));
119
+                    player.setCurrentHealthPoints(player.getCurrentHealthPoints()+1);
121 120
                     if(player.inventory.contains("Magic Bow")) {
122
-                        player.setCurrentHealthPoints(Natural.add(player.getCurrentHealthPoints(), Natural.substract(Natural.divide(player.getCurrentHealthPoints(),8),1),player.getCurrentHealthPoints))
121
+                        player.setCurrentHealthPoints(player.getCurrentHealthPoints()+player.getCurrentHealthPoints()/8-1);
123 122
                     }
124 123
                 }
125 124
             } else {
126 125
                 player.setCurrentHealthPoints(player.getCurrentHealthPoints()+2);
127
-                if(player.getLevel().compareTo(Natural.valueOf(3)) == 1) {
128
-                    player.setCurrentHealthPoints(player.getCurrentHealthPoints().substract(1));
126
+                if(player.getLevel() < 3) {
127
+                    player.setCurrentHealthPoints(player.getCurrentHealthPoints()-1);
129 128
                 }
130 129
             }
131 130
         } else 
... ...
@@ -229,9 +229,6 @@ public class UnitTests {
229 229
         assertEquals(n.substract(Natural.valueOf(2)),Natural.valueOf(0));
230 230
         assertThrows(IllegalArgumentException.class, () -> Natural.valueOf(0).substract(Natural.valueOf(4)));
231 231
 
232
-        assertEquals(Natural.valueOf(4).divide(Natural.valueOf(2)),Natural.valueOf(2));
233
-        assertThrows(IllegalArgumentException.class, () -> Natural.valueOf(0).divide(null));
234
-
235 232
         assertEquals(n.toString(),"2");
236 233
         assertTrue(n.equals(Natural.valueOf(2)));
237 234
         assertTrue(n.equals(n));
238 235