diff --git a/src/main/java/re/forestier/edu/rpg/Adventurer.java b/src/main/java/re/forestier/edu/rpg/Adventurer.java index 0ba1aa4ff19d4f11cc4e09404a6ddbe3dd6a8210..e4ce04a2e75e0ad9121b46faf252f1deb91d3aed 100644 --- a/src/main/java/re/forestier/edu/rpg/Adventurer.java +++ b/src/main/java/re/forestier/edu/rpg/Adventurer.java @@ -8,29 +8,19 @@ public class Adventurer extends Player { public Adventurer(String playerName, String avatar_name, int money, ArrayList<String> inventory) { - super(playerName, avatar_name, money, inventory); + super(playerName, avatar_name, money, inventory, + List.of( + Map.of("INT", 1, "DEF", 1, "ATK", 3, "CHA", 2), // Niveau 1 + Map.of("INT", 2, "CHA", 3), // Niveau 2 + Map.of("ATK", 5, "ALC", 1), // Niveau 3 + Map.of("DEF", 3), // Niveau 4 + Map.of("VIS", 1, "DEF", 4) // Niveau 5 + ) + ); levelUp(); } - @Override - protected void levelUp() { - super.levelUp(); - final List<Map<String, Integer>> ADVENTURER_ABILITIES = List.of( - Map.of("INT", 1, "DEF", 1, "ATK", 3, "CHA", 2), // Niveau 1 - Map.of("INT", 2, "CHA", 3), // Niveau 2 - Map.of("ATK", 5, "ALC", 1), // Niveau 3 - Map.of("DEF", 3), // Niveau 4 - Map.of("VIS", 1, "DEF", 4) // Niveau 5 - ); - - if (getLevel() <= ADVENTURER_ABILITIES.size()) { - Map<String, Integer> newAbilities = ADVENTURER_ABILITIES.get(getLevel() - 1); - abilities.putAll(newAbilities); // Remplace ou ajoute les stats - - } - } - @Override public void majFinDeTour() { super.majFinDeTour(); diff --git a/src/main/java/re/forestier/edu/rpg/Archer.java b/src/main/java/re/forestier/edu/rpg/Archer.java index 35ddd7e9ef962849c89595a26cc574b8d40338f3..d76af0604e4e748ef4d215e380ecb02038af95c1 100644 --- a/src/main/java/re/forestier/edu/rpg/Archer.java +++ b/src/main/java/re/forestier/edu/rpg/Archer.java @@ -6,27 +6,20 @@ import java.util.Map; public class Archer extends Player { - public Archer(String playerName, String avatar_name, int money, ArrayList<String> inventory) { - super(playerName, avatar_name, money, inventory); - levelUp(); - } - @Override - protected void levelUp() { - super.levelUp(); - final List<Map<String, Integer>> ARCHER_ABILITIES = List.of( - Map.of("INT", 1, "ATK", 3, "CHA", 1, "VIS", 3), // Niveau 1 - Map.of("DEF", 1, "CHA", 2), // Niveau 2 - Map.of("ATK", 3), // Niveau 3 - Map.of("DEF", 2), // Niveau 4 - Map.of("ATK", 4) // Niveau 5 - ); - if (level <= ARCHER_ABILITIES.size()) { - Map<String, Integer> newAbilities = ARCHER_ABILITIES.get(level - 1); - abilities.putAll(newAbilities); // Remplace ou ajoute les stats + public Archer(String playerName, String avatar_name, int money, ArrayList<String> inventory) { - } + super(playerName, avatar_name, money, inventory, + List.of( + Map.of("INT", 1, "ATK", 3, "CHA", 1, "VIS", 3), // Niveau 1 + Map.of("DEF", 1, "CHA", 2), // Niveau 2 + Map.of("ATK", 3), // Niveau 3 + Map.of("DEF", 2), // Niveau 4 + Map.of("ATK", 4) // Niveau 5 + ) + ); + levelUp(); } @Override diff --git a/src/main/java/re/forestier/edu/rpg/Dwarf.java b/src/main/java/re/forestier/edu/rpg/Dwarf.java index 64122ea14d6cac98d8af3523d4ce76bd97070e09..23c506050f4975e6cac22a8564de0595acf6ca6a 100644 --- a/src/main/java/re/forestier/edu/rpg/Dwarf.java +++ b/src/main/java/re/forestier/edu/rpg/Dwarf.java @@ -7,26 +7,16 @@ import java.util.Map; public class Dwarf extends Player { public Dwarf(String playerName, String avatar_name, int money, ArrayList<String> inventory) { - super(playerName, avatar_name, money, inventory); - levelUp(); - } - - @Override - protected void levelUp() { - super.levelUp(); - final List<Map<String, Integer>> DWARF_ABILITIES = List.of( - Map.of("ALC", 4, "INT", 1, "ATK", 3), // Niveau 1 - Map.of("DEF", 1, "ALC", 5), // Niveau 2 - Map.of("ATK", 4), // Niveau 3 - Map.of("DEF", 2), // Niveau 4 - Map.of("CHA", 1) // Niveau 5 + super(playerName, avatar_name, money, inventory, + List.of( + Map.of("ALC", 4, "INT", 1, "ATK", 3), // Niveau 1 + Map.of("DEF", 1, "ALC", 5), // Niveau 2 + Map.of("ATK", 4), // Niveau 3 + Map.of("DEF", 2), // Niveau 4 + Map.of("CHA", 1) // Niveau 5 + ) ); - - if (level <= DWARF_ABILITIES.size()) { - Map<String, Integer> newAbilities = DWARF_ABILITIES.get(level - 1); - abilities.putAll(newAbilities); // Remplace ou ajoute les stats - - } + levelUp(); } diff --git a/src/main/java/re/forestier/edu/rpg/Goblin.java b/src/main/java/re/forestier/edu/rpg/Goblin.java index 4ef5e07fb81b47931612007d6d55abac18dc23d5..af552fa668a400251ca812cf16309f2eb18fa8f3 100644 --- a/src/main/java/re/forestier/edu/rpg/Goblin.java +++ b/src/main/java/re/forestier/edu/rpg/Goblin.java @@ -7,27 +7,18 @@ import java.util.Map; public class Goblin extends Player { public Goblin (String playerName, String avatar_name, int money, ArrayList<String> inventory) { - super(playerName, avatar_name, money, inventory); + super(playerName, avatar_name, money, inventory, + List.of( + Map.of("INT", 2, "ATK", 2, "ALC", 1), // Niveau 1 + Map.of("ATK", 3, "ALC", 4), // Niveau 2 + Map.of("VIS", 1), // Niveau 3 + Map.of("DEF", 1), // Niveau 4 + Map.of("ATK", 4, "DEF", 2) // Niveau 5 + ) + ); levelUp(); } - @Override - protected void levelUp() { - super.levelUp(); - final List<Map<String, Integer>> ADVENTURER_ABILITIES = List.of( - Map.of("INT", 2, "ATK", 2, "ALC", 1), // Niveau 1 - Map.of("ATK", 3, "ALC", 4), // Niveau 2 - Map.of("VIS", 1), // Niveau 3 - Map.of("DEF", 1), // Niveau 4 - Map.of("ATK", 4, "DEF", 2) // Niveau 5 - ); - - if (getLevel() <= ADVENTURER_ABILITIES.size()) { - Map<String, Integer> newAbilities = ADVENTURER_ABILITIES.get(getLevel() - 1); - abilities.putAll(newAbilities); // Remplace ou ajoute les stats - - } - } @Override public void majFinDeTour() { diff --git a/src/main/java/re/forestier/edu/rpg/Player.java b/src/main/java/re/forestier/edu/rpg/Player.java index 6a52518290c1e0e956f3368ef718f64f63777677..ed02ba4700286269c2f44bcebbf0f2c499807be4 100644 --- a/src/main/java/re/forestier/edu/rpg/Player.java +++ b/src/main/java/re/forestier/edu/rpg/Player.java @@ -1,8 +1,12 @@ package re.forestier.edu.rpg; + +import java.util.List; +import java.util.Map; +import java.util.Random; import java.util.ArrayList; import java.util.HashMap; -import java.util.Random; + public abstract class Player { public String playerName; @@ -16,6 +20,8 @@ public abstract class Player { public Integer currentHealthPoints; protected Integer xp; + protected List<Map<String, Integer>> ABILITIES_LIST; + private final static String[] objectList = {"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", "Magic Bow : Bow is magic !","Rune Staff of Curse : May burn your ennemies... Or yourself. Who knows?", "Combat Edge : Well, that's an edge", "Holy Elixir : Recover your HP" }; @@ -23,7 +29,7 @@ public abstract class Player { public HashMap<String, Integer> abilities; public ArrayList<String> inventory; - public Player(String playerName, String avatar_name, int money, ArrayList<String> inventory) { + public Player(String playerName, String avatar_name, int money, ArrayList<String> inventory, List<Map<String, Integer>> abilitiesList) { this.playerName = playerName; this.avatarName = avatar_name; @@ -33,6 +39,7 @@ public abstract class Player { this.xp = 0; this.lvlXp = 10; this.abilities = new HashMap<>(); + this.ABILITIES_LIST = abilitiesList; } @@ -45,7 +52,11 @@ public abstract class Player { } protected void levelUp() { - //The rest of the method is implemented in the subclasses + if (level <= ABILITIES_LIST.size()) { + Map<String, Integer> newAbilities = ABILITIES_LIST.get(level - 1); + abilities.putAll(newAbilities); // Remplace ou ajoute les stats + + } }