Clement COLMERAUER commited on 2024-10-04 16:31:09
Showing 6 changed files, with 27 additions and 114 deletions.
| ... | ... |
@@ -1,13 +1,13 @@ |
| 1 | 1 |
package re.forestier.edu; |
| 2 | 2 |
import re.forestier.edu.rpg.Affichage; |
| 3 | 3 |
import re.forestier.edu.rpg.UpdatePlayer; |
| 4 |
-import re.forestier.edu.rpg.player; |
|
| 4 |
+import re.forestier.edu.rpg.Player; |
|
| 5 | 5 |
|
| 6 | 6 |
import java.util.ArrayList; |
| 7 | 7 |
|
| 8 | 8 |
public class Main {
|
| 9 | 9 |
public static void main(String[] args) {
|
| 10 |
- player firstPlayer = new player("Florian", "Ruzberg de Rivehaute", "DWARF", 200, new ArrayList<>());
|
|
| 10 |
+ Player firstPlayer = new Player("Florian", "Ruzberg de Rivehaute", "DWARF", 200, new ArrayList<>());
|
|
| 11 | 11 |
firstPlayer.addMoney(400); |
| 12 | 12 |
|
| 13 | 13 |
UpdatePlayer.addXp(firstPlayer, 15); |
| ... | ... |
@@ -2,7 +2,7 @@ package re.forestier.edu.rpg; |
| 2 | 2 |
|
| 3 | 3 |
public class Affichage {
|
| 4 | 4 |
|
| 5 |
- public static String afficherJoueur(player player) {
|
|
| 5 |
+ public static String afficherJoueur(Player player) {
|
|
| 6 | 6 |
final String[] finalString = {"Joueur " + player.Avatar_name + " joué par " + player.playerName};
|
| 7 | 7 |
finalString[0] += "\nNiveau : " + player.retrieveLevel() + " (XP totale : " + player.xp + ")"; |
| 8 | 8 |
finalString[0] += "\n\nCapacités :"; |
| ... | ... |
@@ -98,7 +98,7 @@ public class UpdatePlayer {
|
| 98 | 98 |
return abilitiesPerTypeAndLevel; |
| 99 | 99 |
} |
| 100 | 100 |
|
| 101 |
- public static boolean addXp(player player, int xp) {
|
|
| 101 |
+ public static boolean addXp(Player player, int xp) {
|
|
| 102 | 102 |
int currentLevel = player.retrieveLevel(); |
| 103 | 103 |
player.xp += xp; |
| 104 | 104 |
int newLevel = player.retrieveLevel(); |
| ... | ... |
@@ -123,7 +123,7 @@ public class UpdatePlayer {
|
| 123 | 123 |
|
| 124 | 124 |
|
| 125 | 125 |
// majFinDeTour met à jour les points de vie |
| 126 |
- public static void majFinDeTour(player player) {
|
|
| 126 |
+ public static void majFinDeTour(Player player) {
|
|
| 127 | 127 |
if(player.currenthealthpoints == 0) {
|
| 128 | 128 |
System.out.println("Le joueur est KO !");
|
| 129 | 129 |
return; |
| ... | ... |
@@ -1,87 +0,0 @@ |
| 1 |
-package re.forestier.edu.rpg; |
|
| 2 |
- |
|
| 3 |
-import java.util.ArrayList; |
|
| 4 |
-import java.util.HashMap; |
|
| 5 |
- |
|
| 6 |
-public class player {
|
|
| 7 |
- public String playerName; |
|
| 8 |
- public String Avatar_name; |
|
| 9 |
- private String AvatarClass; |
|
| 10 |
- |
|
| 11 |
- public Integer money; |
|
| 12 |
- private Float __real_money__; |
|
| 13 |
- |
|
| 14 |
- public int level; |
|
| 15 |
- public int healthpoints; |
|
| 16 |
- public int currenthealthpoints; |
|
| 17 |
- protected int xp; |
|
| 18 |
- |
|
| 19 |
- public HashMap<String, Integer> abilities; //Ability = stat |
|
| 20 |
- public ArrayList<String> inventory; |
|
| 21 |
- |
|
| 22 |
- public player(String playerName, String avatar_name, String avatarClass, int money, ArrayList<String> inventory) {
|
|
| 23 |
- if (!avatarClass.equals("ARCHER") && !avatarClass.equals("ADVENTURER") && !avatarClass.equals("DWARF"))
|
|
| 24 |
- {
|
|
| 25 |
- return; |
|
| 26 |
- } |
|
| 27 |
- |
|
| 28 |
- this.playerName = playerName; |
|
| 29 |
- Avatar_name = avatar_name; |
|
| 30 |
- AvatarClass = avatarClass; |
|
| 31 |
- this.money = Integer.valueOf(money); |
|
| 32 |
- this.inventory = inventory; |
|
| 33 |
- this.abilities = UpdatePlayer.abilitiesPerTypeAndLevel().get(AvatarClass).get(1); |
|
| 34 |
- } |
|
| 35 |
- |
|
| 36 |
- public String getAvatarClass () {
|
|
| 37 |
- return AvatarClass; |
|
| 38 |
- } |
|
| 39 |
- |
|
| 40 |
- public void removeMoney(int amount) throws IllegalArgumentException {
|
|
| 41 |
- if (money - amount < 0) {
|
|
| 42 |
- throw new IllegalArgumentException("Player can't have a negative money!");
|
|
| 43 |
- } |
|
| 44 |
- |
|
| 45 |
- money = Integer.parseInt(money.toString()) - amount; |
|
| 46 |
- } |
|
| 47 |
- public void addMoney(int amount) {
|
|
| 48 |
- var value = Integer.valueOf(amount); |
|
| 49 |
- money = money + (value != null ? value : 0); |
|
| 50 |
- } |
|
| 51 |
- public int retrieveLevel() {
|
|
| 52 |
- // (lvl-1) * 10 + round((lvl * xplvl-1)/4) |
|
| 53 |
- HashMap<Integer, Integer> levels = new HashMap<>(); |
|
| 54 |
- levels.put(2,10); // 1*10 + ((2*0)/4) |
|
| 55 |
- levels.put(3,27); // 2*10 + ((3*10)/4) |
|
| 56 |
- levels.put(4,57); // 3*10 + ((4*27)/4) |
|
| 57 |
- levels.put(5,111); // 4*10 + ((5*57)/4) |
|
| 58 |
- //TODO : ajouter les prochains niveaux |
|
| 59 |
- |
|
| 60 |
- if (xp < levels.get(2)) {
|
|
| 61 |
- return 1; |
|
| 62 |
- } |
|
| 63 |
- else if (xp < levels.get(3)) {return 2;
|
|
| 64 |
- } |
|
| 65 |
- if (xp < levels.get(4)) {
|
|
| 66 |
- return 3; |
|
| 67 |
- } |
|
| 68 |
- if (xp < levels.get(5)) return 4; |
|
| 69 |
- return 5; |
|
| 70 |
- } |
|
| 71 |
- |
|
| 72 |
- public int getXp() {
|
|
| 73 |
- return this.xp; |
|
| 74 |
- } |
|
| 75 |
- |
|
| 76 |
- /* |
|
| 77 |
- Ингредиенты: |
|
| 78 |
- Для теста: |
|
| 79 |
- |
|
| 80 |
- 250 г муки |
|
| 81 |
- 125 г сливочного масла (холодное) |
|
| 82 |
- 70 г сахара |
|
| 83 |
- 1 яйцо |
|
| 84 |
- 1 щепотка соли |
|
| 85 |
- */ |
|
| 86 |
- |
|
| 87 |
-} |
|
| 88 | 0 |
\ No newline at end of file |
| ... | ... |
@@ -4,7 +4,7 @@ import org.junit.jupiter.api.DisplayName; |
| 4 | 4 |
import org.junit.jupiter.api.Test; |
| 5 | 5 |
import re.forestier.edu.rpg.Affichage; |
| 6 | 6 |
import re.forestier.edu.rpg.UpdatePlayer; |
| 7 |
-import re.forestier.edu.rpg.player; |
|
| 7 |
+import re.forestier.edu.rpg.Player; |
|
| 8 | 8 |
|
| 9 | 9 |
import java.util.ArrayList; |
| 10 | 10 |
|
| ... | ... |
@@ -17,7 +17,7 @@ public class GlobalTest {
|
| 17 | 17 |
|
| 18 | 18 |
@Test |
| 19 | 19 |
void testAffichageBase() {
|
| 20 |
- player player = new player("Florian", "Gnognak le Barbare", "ADVENTURER", 200, new ArrayList<>());
|
|
| 20 |
+ Player player = new Player("Florian", "Gnognak le Barbare", "ADVENTURER", 200, new ArrayList<>());
|
|
| 21 | 21 |
UpdatePlayer.addXp(player, 20); |
| 22 | 22 |
player.inventory = new ArrayList<>(); |
| 23 | 23 |
|
| ... | ... |
@@ -33,29 +33,29 @@ public class UnitTests {
|
| 33 | 33 |
@Test |
| 34 | 34 |
@DisplayName("Sample test")
|
| 35 | 35 |
void testPlayerName() {
|
| 36 |
- player player = new player("Florian", "Grognak le barbare", "ADVENTURER", 100, new ArrayList<>());
|
|
| 37 |
- assertThat(player.playerName, is("Florian"));
|
|
| 36 |
+ Player Player = new Player("Florian", "Grognak le barbare", "ADVENTURER", 100, new ArrayList<>());
|
|
| 37 |
+ assertThat(Player.playerName, is("Florian"));
|
|
| 38 | 38 |
|
| 39 | 39 |
} |
| 40 | 40 |
|
| 41 | 41 |
@Test |
| 42 |
- @DisplayName("Constructor player")
|
|
| 42 |
+ @DisplayName("Constructor Player")
|
|
| 43 | 43 |
void testPlayerConstructor() |
| 44 | 44 |
{
|
| 45 |
- player p = new player("Florian", "Grognak le barbare", "jgn", 100, new ArrayList<>());
|
|
| 45 |
+ Player p = new Player("Florian", "Grognak le barbare", "jgn", 100, new ArrayList<>());
|
|
| 46 | 46 |
assertThat(p.playerName, not("Florian"));
|
| 47 |
- p = new player("Florian", "Grognak le barbare", "ADVENTURER", 100, new ArrayList<>());
|
|
| 47 |
+ p = new Player("Florian", "Grognak le barbare", "ADVENTURER", 100, new ArrayList<>());
|
|
| 48 | 48 |
assertThat(p.playerName, is("Florian"));
|
| 49 |
- p = new player("Florian", "Grognak le barbare", "DWARF", 100, new ArrayList<>());
|
|
| 49 |
+ p = new Player("Florian", "Grognak le barbare", "DWARF", 100, new ArrayList<>());
|
|
| 50 | 50 |
assertThat(p.playerName, is("Florian"));
|
| 51 |
- p = new player("Florian", "Grognak le barbare", "ARCHER", 100, new ArrayList<>());
|
|
| 51 |
+ p = new Player("Florian", "Grognak le barbare", "ARCHER", 100, new ArrayList<>());
|
|
| 52 | 52 |
assertThat(p.playerName, is("Florian"));
|
| 53 | 53 |
} |
| 54 | 54 |
|
| 55 | 55 |
@Test |
| 56 | 56 |
@DisplayName("removeMoney")
|
| 57 | 57 |
void testRemoveMoney() {
|
| 58 |
- player p = new player("Florian", "Grognak le barbare", "ADVENTURER", 100, new ArrayList<>());
|
|
| 58 |
+ Player p = new Player("Florian", "Grognak le barbare", "ADVENTURER", 100, new ArrayList<>());
|
|
| 59 | 59 |
|
| 60 | 60 |
assertThrows(IllegalArgumentException.class, () -> p.removeMoney(200)); |
| 61 | 61 |
p.removeMoney(50); |
| ... | ... |
@@ -68,7 +68,7 @@ public class UnitTests {
|
| 68 | 68 |
@Test |
| 69 | 69 |
@DisplayName("addMoney")
|
| 70 | 70 |
void testAddMoney() {
|
| 71 |
- player p = new player("Florian", "Grognak le barbare", "ADVENTURER", 100, new ArrayList<>());
|
|
| 71 |
+ Player p = new Player("Florian", "Grognak le barbare", "ADVENTURER", 100, new ArrayList<>());
|
|
| 72 | 72 |
p.addMoney(50); |
| 73 | 73 |
assertThat(p.money, is(150)); |
| 74 | 74 |
} |
| ... | ... |
@@ -83,7 +83,7 @@ public class UnitTests {
|
| 83 | 83 |
@Test |
| 84 | 84 |
@DisplayName("ex & lvl")
|
| 85 | 85 |
void testRetrieveLevel() {
|
| 86 |
- player p = new player("Florian", "Grognak le barbare", "ADVENTURER", 100, new ArrayList<>());
|
|
| 86 |
+ Player p = new Player("Florian", "Grognak le barbare", "ADVENTURER", 100, new ArrayList<>());
|
|
| 87 | 87 |
boolean b; |
| 88 | 88 |
b = UpdatePlayer.addXp(p,5); |
| 89 | 89 |
assertThat(p.getXp(),is(5)); |
| ... | ... |
@@ -97,7 +97,7 @@ public class UnitTests {
|
| 97 | 97 |
b = UpdatePlayer.addXp(p,100); |
| 98 | 98 |
assertThat(p.retrieveLevel(),is(5)); |
| 99 | 99 |
|
| 100 |
- p = new player("Florian", "Grognak le barbare", "ADVENTURER", 100, new ArrayList<>());
|
|
| 100 |
+ p = new Player("Florian", "Grognak le barbare", "ADVENTURER", 100, new ArrayList<>());
|
|
| 101 | 101 |
int tailleinv = p.inventory.size(); |
| 102 | 102 |
b = UpdatePlayer.addXp(p,10); |
| 103 | 103 |
int atk = p.abilities.get("ATK");
|
| ... | ... |
@@ -118,7 +118,7 @@ public class UnitTests {
|
| 118 | 118 |
@Test |
| 119 | 119 |
@DisplayName("majDeFinDeTour")
|
| 120 | 120 |
void testMajFinTour() {
|
| 121 |
- player p = new player("Florian", "Grognak le barbare", "ADVENTURER", 100, new ArrayList<>());
|
|
| 121 |
+ Player p = new Player("Florian", "Grognak le barbare", "ADVENTURER", 100, new ArrayList<>());
|
|
| 122 | 122 |
p.currenthealthpoints = 0; |
| 123 | 123 |
UpdatePlayer.majFinDeTour(p); |
| 124 | 124 |
assertEquals("Le joueur est KO !", outContent.toString().trim());
|
| ... | ... |
@@ -135,13 +135,13 @@ public class UnitTests {
|
| 135 | 135 |
UpdatePlayer.majFinDeTour(p); |
| 136 | 136 |
assertThat(p.currenthealthpoints,is(p.healthpoints)); |
| 137 | 137 |
|
| 138 |
- p = new player("Florian", "Grognak le barbare", "DWARF", 100, new ArrayList<>());
|
|
| 138 |
+ p = new Player("Florian", "Grognak le barbare", "DWARF", 100, new ArrayList<>());
|
|
| 139 | 139 |
p.currenthealthpoints = 1; |
| 140 | 140 |
p.healthpoints = 10; |
| 141 | 141 |
UpdatePlayer.majFinDeTour(p); |
| 142 | 142 |
assertThat(p.currenthealthpoints,is(2)); |
| 143 | 143 |
|
| 144 |
- p = new player("Florian", "Grognak le barbare", "DWARF", 100, new ArrayList<>());
|
|
| 144 |
+ p = new Player("Florian", "Grognak le barbare", "DWARF", 100, new ArrayList<>());
|
|
| 145 | 145 |
p.currenthealthpoints = 5; |
| 146 | 146 |
p.healthpoints = 10; |
| 147 | 147 |
UpdatePlayer.majFinDeTour(p); |
| ... | ... |
@@ -149,19 +149,19 @@ public class UnitTests {
|
| 149 | 149 |
|
| 150 | 150 |
ArrayList<String> inv = new ArrayList<String>(); |
| 151 | 151 |
inv.add("Holy Elixir");
|
| 152 |
- p = new player("Florian", "Grognak le barbare", "DWARF", 100, inv);
|
|
| 152 |
+ p = new Player("Florian", "Grognak le barbare", "DWARF", 100, inv);
|
|
| 153 | 153 |
p.currenthealthpoints = 1; |
| 154 | 154 |
p.healthpoints = 10; |
| 155 | 155 |
UpdatePlayer.majFinDeTour(p); |
| 156 | 156 |
assertThat(p.currenthealthpoints,is(3)); |
| 157 | 157 |
|
| 158 |
- p = new player("Florian", "Grognak le barbare", "ARCHER", 100, new ArrayList<>());
|
|
| 158 |
+ p = new Player("Florian", "Grognak le barbare", "ARCHER", 100, new ArrayList<>());
|
|
| 159 | 159 |
p.currenthealthpoints = 1; |
| 160 | 160 |
p.healthpoints = 10; |
| 161 | 161 |
UpdatePlayer.majFinDeTour(p); |
| 162 | 162 |
assertThat(p.currenthealthpoints,is(2)); |
| 163 | 163 |
|
| 164 |
- p = new player("Florian", "Grognak le barbare", "ADVENTURER", 100, new ArrayList<>());
|
|
| 164 |
+ p = new Player("Florian", "Grognak le barbare", "ADVENTURER", 100, new ArrayList<>());
|
|
| 165 | 165 |
p.currenthealthpoints = 1; |
| 166 | 166 |
p.healthpoints = 10; |
| 167 | 167 |
UpdatePlayer.addXp(p,28); |
| ... | ... |
@@ -169,7 +169,7 @@ public class UnitTests {
|
| 169 | 169 |
assertThat(p.currenthealthpoints,is(3)); |
| 170 | 170 |
|
| 171 | 171 |
inv.add("Magic Bow");
|
| 172 |
- p = new player("Florian", "Grognak le barbare", "ARCHER", 100, inv);
|
|
| 172 |
+ p = new Player("Florian", "Grognak le barbare", "ARCHER", 100, inv);
|
|
| 173 | 173 |
p.currenthealthpoints = 1; |
| 174 | 174 |
p.healthpoints = 10; |
| 175 | 175 |
UpdatePlayer.majFinDeTour(p); |
| ... | ... |
@@ -180,7 +179,7 @@ public class UnitTests {
|
| 180 | 179 |
UpdatePlayer.majFinDeTour(p); |
| 181 | 180 |
assertThat(p.currenthealthpoints,is(17 + 17/8-1)); |
| 182 | 181 |
|
| 183 |
- p = new player("Florian", "Grognak le barbare", "ADVENTURER", 100, new ArrayList<>());
|
|
| 182 |
+ p = new Player("Florian", "Grognak le barbare", "ADVENTURER", 100, new ArrayList<>());
|
|
| 184 | 183 |
p.currenthealthpoints = 20; |
| 185 | 184 |
p.healthpoints = 40; |
| 186 | 185 |
UpdatePlayer.majFinDeTour(p); |
| ... | ... |
@@ -195,7 +194,7 @@ public class UnitTests {
|
| 195 | 194 |
|
| 196 | 195 |
ArrayList<String> inv = new ArrayList<String>(); |
| 197 | 196 |
inv.add("Holy Elixir");
|
| 198 |
- player p = new player("Florian", "Grognak le barbare", "ADVENTURER", 100, inv);
|
|
| 197 |
+ Player p = new Player("Florian", "Grognak le barbare", "ADVENTURER", 100, inv);
|
|
| 199 | 198 |
assertEquals("Joueur Grognak le barbare joué par Florian\nNiveau : 1 (XP totale : 0)\n\nCapacités :\n DEF : 1\n ATK : 3\n CHA : 3\n INT : 2\n\nInventaire :\n Holy Elixir", Affichage.afficherJoueur(p));
|
| 200 | 199 |
} |
| 201 | 200 |
|
| 202 | 201 |