Intégration item dans Manage et Player (sans sell)
Clement Colmerauer

Clement Colmerauer commited on 2024-12-13 10:55:33
Showing 14 changed files, with 38 additions and 9 deletions.

... ...
@@ -17,6 +17,12 @@ public class Item implements Cloneable
17 17
 		this.value = value;
18 18
 	}
19 19
 
20
+	Item(String name)
21
+	{
22
+		this.name = name;
23
+		this.description = "Is used to search in list, if you see me, there is a problem";
24
+	}
25
+
20 26
 	public String getName()
21 27
 	{
22 28
 		return this.name;
... ...
@@ -55,4 +61,17 @@ public class Item implements Cloneable
55 61
 	{
56 62
 		return new Item(this.name,this.description,(Natural)this.weight.clone(),(Natural)this.value.clone());
57 63
 	}
64
+
65
+	@Override
66
+	public boolean equals(Object o)
67
+	{
68
+		if(o != null && o instanceof Item && ((Item)o).getName() == this.name)
69
+		{
70
+			return true;
71
+		}
72
+		else 
73
+		{
74
+			return false;
75
+		}
76
+	}
58 77
 }
59 78
\ No newline at end of file
... ...
@@ -2,11 +2,21 @@ 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;
5 6
 
6 7
 public class Manager {
7 8
 
8
-    public final static String[] objectList = {"Magic bow : Heal by 1/8th of your HP","Lookout Ring : Prevents surprise attacks","Scroll of Stupidity : INT-2 when applied to an enemy", "Draupnir : Increases XP gained by 100%", "Magic Charm : Magic +10 for 5 rounds", "Rune Staff of Curse : May burn your ennemies... Or yourself. Who knows?", "Combat Edge : Well, that's an edge", "Holy Elixir : Recover your HP"
9
-    }; //SHOULDDO : Create an item class
9
+    public final static Item[] objectList = {
10
+        new Item("Magic bow", "Heal by 1/8th of your HP",Natural.valueOf(0),Natural.valueOf(0)),
11
+        new Item("Lookout Ring","Prevents surprise attacks",Natural.valueOf(0),Natural.valueOf(0)),
12
+        new Item("Scroll of Stupidity","INT-2 when applied to an enemy",Natural.valueOf(0),Natural.valueOf(0)), 
13
+        new Item("Draupnir", "Increases XP gained by 100%",Natural.valueOf(0),Natural.valueOf(0)), 
14
+        new Item("Magic Charm","Magic +10 for 5 rounds",Natural.valueOf(0),Natural.valueOf(0)), 
15
+        new Item("Rune Staff of Curse","May burn your ennemies... Or yourself. Who knows?",Natural.valueOf(0),Natural.valueOf(0)),
16
+        new Item("Combat Edge","Well, that's an edge",Natural.valueOf(0),Natural.valueOf(0)), 
17
+        new Item("Holy Elixir","Recover your HP",Natural.valueOf(0),Natural.valueOf(0))
18
+    }; //SHOULDDO : Instantiate from file (xml)
19
+       //Since we don't have value for weight and value, we put neutral
10 20
 
11 21
     // majFinDeTour met à jour les points de vie
12 22
     public static void majFinDeTour(Player player) {
... ...
@@ -26,13 +36,13 @@ public class Manager {
26 36
                     break;
27 37
                 case DWARF :
28 38
                     player.heal(1);
29
-                    if(player.getInventory().contains("Holy Elixir")) {
39
+                    if(player.getInventory().contains(new Item("Holy Elixir"))) {
30 40
                         player.heal(1);
31 41
                     }
32 42
                     break;
33 43
                 case ARCHER :
34 44
                     player.heal(1);
35
-                    if(player.getInventory().contains("Magic Bow")) {
45
+                    if(player.getInventory().contains(new Item("Magic Bow"))) {
36 46
                         int potentialHeal = player.getCurrentHealthPoints()/8-1;
37 47
                         player.heal(potentialHeal < 0 ? 0 : potentialHeal);
38 48
                     }
... ...
@@ -30,13 +30,13 @@ public class Player {
30 30
 
31 31
     private final HashMap<Ability, Integer> abilities; //Ability = stat
32 32
                                                        //SHOULDDO : have another hashmap to have contextual modifier (items,...)
33
-    private ArrayList<String> inventory;
33
+    private ArrayList<Item> inventory;
34 34
 
35
-    public Player(String playerName, String avatar_name, Jobs avatarClass, int money, ArrayList<String> inventory) {
35
+    public Player(String playerName, String avatar_name, Jobs avatarClass, int money, ArrayList<Item> inventory) {
36 36
         this(playerName,avatar_name,avatarClass,money,inventory,Player.defaultMaxHp.toInt());
37 37
     }
38 38
 
39
-    public Player(String playerName, String avatar_name, Jobs avatarClass, int money, ArrayList<String> inventory, int maxHp)
39
+    public Player(String playerName, String avatar_name, Jobs avatarClass, int money, ArrayList<Item> inventory, int maxHp)
40 40
     {
41 41
         this.playerName = playerName;
42 42
         this.avatarName = avatar_name;
... ...
@@ -93,9 +93,9 @@ public class Player {
93 93
         return copy;
94 94
     }
95 95
 
96
-    public ArrayList<String> getInventory()
96
+    public ArrayList<Item> getInventory()
97 97
     {
98
-        return new ArrayList<String>(this.inventory);
98
+        return new ArrayList<Item>(this.inventory);
99 99
     }
100 100
 
101 101
     public void heal(int hp)
102 102