Initial commit
Clement COLMERAUER

Clement COLMERAUER commited on 2024-09-20 15:50:04
Showing 14 changed files, with 824 additions and 0 deletions.

... ...
@@ -0,0 +1,105 @@
1
+# Correctif - machine ISIMA
2
+
3
+Sur les machines ISIMA, vous **devez** :
4
+
5
+* Ouvrir un terminal
6
+* Taper la commande suivante : `echo "JAVA_HOME=/usr/lib/jvm/jdk-21.0.4-oracle-x64" >> ~/.bashrc`
7
+* Fermer le terminal (et vous pouvez ensuite ouvrir à nouveau des terminaux sur votre VSCode ou autre)
8
+
9
+
10
+# M1 - Kata
11
+
12
+## RPG Player Manager
13
+
14
+Bienvenue sur RPG Player Manager, un superbe projet rédigé en Java... Enfin ça, c'est que vous a dit le client avant de
15
+vous envoyer le code source.
16
+
17
+### Partie 1 - Tests unitaires
18
+
19
+En effet, le code de ce projet est moche, complexe, et surtout, moche. Et félicitations, vous devez coder une nouvelle
20
+fonctionnalité à l'intérieur !
21
+
22
+Avant de pouvoir implémenter la nouvelle fonctionnalité (qui sera décrite plus tard), vous allez en premier lieu vous
23
+assurer de ne rien casser. Pour cela, vous allez devoir :
24
+
25
+* Comprendre le code actuel (prenez des notes sur les règles métier, ça vous aidera) ;
26
+* Rédiger des tests unitaires et globaux pour vous assurer que tout fonctionne correctement ;
27
+* Le tout, sans toucher le code actuel.
28
+
29
+JaCoCo et PIT seront vos amis (+ de détails dans le sujet de TP).
30
+
31
+Attention, le client vous informe que pour une raison inconnue, le passage de l'aventurier au niveau 2 ne fonctionne
32
+pas... Mais le niveau 3, 4 et 5, eux, fonctionnent.
33
+
34
+Rédigez des tests unitaires et globaux de manière que JaCoCo vous indique 100% de code coverage. Des exemples vous
35
+sont fournis dans `src/test/java/re.forestier.re`.
36
+
37
+Durant cette phase, il est **strictement interdit** de toucher au code source !
38
+
39
+### Partie 2 - Refactoring
40
+
41
+Durant la phase de refactoring, vous êtes libres de toucher à ce que vous voulez dans le programme ! N'oubliez pas de
42
+régulièrement commiter votre travail pour éviter de vous retrouver perdu dans un refactoring impossible...
43
+
44
+L'objectif : rendre propre le code actuel sans casser vos tests actuels ! Dans cette phase, il est **strictement
45
+interdit** de toucher aux tests !
46
+
47
+Quelques pistes :
48
+
49
+* Réduire la complexité cognitive ;
50
+* Améliorer le système d'affichage, par exemple avec FreeMarker ou un StringBuilder (FreeMarker sera plus approprié) ;
51
+* Est-il cohérent d'avoir ces trois classes dans `re.forestier.re.rpg` ? (probablement un redécoupage à faire) ;
52
+* Consistence dans le code ;
53
+* Gérer correctement les erreurs ;
54
+* Utiliser des énumérations, regarder si les structures sont bien adaptées, etc.
55
+
56
+N'hésitez pas à demander à votre chargé de TP des conseils au fur et à mesure.
57
+
58
+Note : Durant cette phase, vous pouvez en profiter pour corriger le bug de l'aventurier niveau 2...
59
+
60
+### Partie 3 - Ajouter les nouvelles fonctionnalités
61
+
62
+En vous donnant le projet, le client vous a demandé d'implémenter de nouvelles fonctionnalités :
63
+
64
+#### Ajout d'un nouveau rôle de joueur : Gobelin (`GOBLIN` en anglais) :
65
+
66
+- Niveau 1 :
67
+    - `INT` = 2
68
+    - `ATK` = 2
69
+    - `ALC` = 1
70
+- Niveau 2 :
71
+    - `ATF` = 3
72
+    - `ALC` = 4
73
+- Niveau 3 :
74
+    - `VIS` = 1
75
+- Niveau 4 :
76
+    - `DEF` = 1
77
+- Niveau 5 :
78
+    - `DEF` = 2
79
+    - `ATK` = 3
80
+
81
+#### Améliorer la gestion des objets :
82
+
83
+Actuellement, un objet, c'est une simple chaîne de caractères. L'idée est d'en faire un vrai objet, disposant :
84
+
85
+- D'un nom ;
86
+- D'une description ;
87
+- D'un poids ;
88
+- D'une valeur.
89
+- Il sera possible pour un joueur de vendre un objet de son inventaire (prévoir une méthode `sell()`).
90
+- Par ailleurs, le joueur a désormais un poids max qu'il peut porter. Si un joueur ajoute un objet à son inventaire qui
91
+  fait dépasser le poids maximal, l'opération échoue.
92
+
93
+Lors de l'ajout de ces fonctionnalités, vous penserez à créer les tests nécessaires.
94
+
95
+#### Ajouter une nouvelle méthode d'affichage :
96
+
97
+Actuellement, il est uniquement possible d'avoir le détail d'un joueur dans un affichage textuel. Le client souhaiterait
98
+que vous ajoutiez un affichage complémentaire en Markdown. Markdown est un moyen simple de formater du texte. Voici
99
+quelques règles de Markdown :
100
+
101
+* `#` permet de créer un titre, `##` un sous-titre, et ainsi de suite ;
102
+* Des caractères entre `*` formate un texte *en italique* ; et `**` formate un texte **en gras** ;
103
+* Les listes doivent commencer par `*` au début de la ligne ;
104
+
105
+Pour découvrir davantage la syntaxe Markdown, regardez le contenu de ce fichier !
... ...
@@ -0,0 +1,28 @@
1
+plugins {
2
+    id 'java'
3
+    id "jacoco"
4
+    id 'info.solidsoft.pitest' version '1.7.4'
5
+}
6
+
7
+group = 're.forestier.edu'
8
+version = '1.0-SNAPSHOT'
9
+
10
+repositories {
11
+    mavenCentral()
12
+}
13
+
14
+dependencies {
15
+    testImplementation platform('org.junit:junit-bom:5.10.0')
16
+    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.1'
17
+    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.1'
18
+    testImplementation 'org.pitest:pitest-junit5-plugin:0.12'
19
+    testImplementation("com.approvaltests:approvaltests:15.6.0")
20
+    implementation 'org.hamcrest:hamcrest:2.2'
21
+    implementation("org.freemarker:freemarker:2.3.30")
22
+
23
+
24
+}
25
+
26
+test {
27
+    useJUnitPlatform()
28
+}
0 29
\ No newline at end of file
... ...
@@ -0,0 +1,6 @@
1
+#Wed Jul 24 15:43:23 CEST 2024
2
+distributionBase=GRADLE_USER_HOME
3
+distributionPath=wrapper/dists
4
+distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
5
+zipStoreBase=GRADLE_USER_HOME
6
+zipStorePath=wrapper/dists
... ...
@@ -0,0 +1,234 @@
1
+#!/bin/sh
2
+
3
+#
4
+# Copyright © 2015-2021 the original authors.
5
+#
6
+# Licensed under the Apache License, Version 2.0 (the "License");
7
+# you may not use this file except in compliance with the License.
8
+# You may obtain a copy of the License at
9
+#
10
+#      https://www.apache.org/licenses/LICENSE-2.0
11
+#
12
+# Unless required by applicable law or agreed to in writing, software
13
+# distributed under the License is distributed on an "AS IS" BASIS,
14
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+# See the License for the specific language governing permissions and
16
+# limitations under the License.
17
+#
18
+
19
+##############################################################################
20
+#
21
+#   Gradle start up script for POSIX generated by Gradle.
22
+#
23
+#   Important for running:
24
+#
25
+#   (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
26
+#       noncompliant, but you have some other compliant shell such as ksh or
27
+#       bash, then to run this script, type that shell name before the whole
28
+#       command line, like:
29
+#
30
+#           ksh Gradle
31
+#
32
+#       Busybox and similar reduced shells will NOT work, because this script
33
+#       requires all of these POSIX shell features:
34
+#         * functions;
35
+#         * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
36
+#           «${var#prefix}», «${var%suffix}», and «$( cmd )»;
37
+#         * compound commands having a testable exit status, especially «case»;
38
+#         * various built-in commands including «command», «set», and «ulimit».
39
+#
40
+#   Important for patching:
41
+#
42
+#   (2) This script targets any POSIX shell, so it avoids extensions provided
43
+#       by Bash, Ksh, etc; in particular arrays are avoided.
44
+#
45
+#       The "traditional" practice of packing multiple parameters into a
46
+#       space-separated string is a well documented source of bugs and security
47
+#       problems, so this is (mostly) avoided, by progressively accumulating
48
+#       options in "$@", and eventually passing that to Java.
49
+#
50
+#       Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
51
+#       and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
52
+#       see the in-line comments for details.
53
+#
54
+#       There are tweaks for specific operating systems such as AIX, CygWin,
55
+#       Darwin, MinGW, and NonStop.
56
+#
57
+#   (3) This script is generated from the Groovy template
58
+#       https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
59
+#       within the Gradle project.
60
+#
61
+#       You can find Gradle at https://github.com/gradle/gradle/.
62
+#
63
+##############################################################################
64
+
65
+# Attempt to set APP_HOME
66
+
67
+# Resolve links: $0 may be a link
68
+app_path=$0
69
+
70
+# Need this for daisy-chained symlinks.
71
+while
72
+    APP_HOME=${app_path%"${app_path##*/}"}  # leaves a trailing /; empty if no leading path
73
+    [ -h "$app_path" ]
74
+do
75
+    ls=$( ls -ld "$app_path" )
76
+    link=${ls#*' -> '}
77
+    case $link in             #(
78
+      /*)   app_path=$link ;; #(
79
+      *)    app_path=$APP_HOME$link ;;
80
+    esac
81
+done
82
+
83
+APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
84
+
85
+APP_NAME="Gradle"
86
+APP_BASE_NAME=${0##*/}
87
+
88
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
89
+DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
90
+
91
+# Use the maximum available, or set MAX_FD != -1 to use that value.
92
+MAX_FD=maximum
93
+
94
+warn () {
95
+    echo "$*"
96
+} >&2
97
+
98
+die () {
99
+    echo
100
+    echo "$*"
101
+    echo
102
+    exit 1
103
+} >&2
104
+
105
+# OS specific support (must be 'true' or 'false').
106
+cygwin=false
107
+msys=false
108
+darwin=false
109
+nonstop=false
110
+case "$( uname )" in                #(
111
+  CYGWIN* )         cygwin=true  ;; #(
112
+  Darwin* )         darwin=true  ;; #(
113
+  MSYS* | MINGW* )  msys=true    ;; #(
114
+  NONSTOP* )        nonstop=true ;;
115
+esac
116
+
117
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
118
+
119
+
120
+# Determine the Java command to use to start the JVM.
121
+if [ -n "$JAVA_HOME" ] ; then
122
+    if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
123
+        # IBM's JDK on AIX uses strange locations for the executables
124
+        JAVACMD=$JAVA_HOME/jre/sh/java
125
+    else
126
+        JAVACMD=$JAVA_HOME/bin/java
127
+    fi
128
+    if [ ! -x "$JAVACMD" ] ; then
129
+        die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
130
+
131
+Please set the JAVA_HOME variable in your environment to match the
132
+location of your Java installation."
133
+    fi
134
+else
135
+    JAVACMD=java
136
+    which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
137
+
138
+Please set the JAVA_HOME variable in your environment to match the
139
+location of your Java installation."
140
+fi
141
+
142
+# Increase the maximum file descriptors if we can.
143
+if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
144
+    case $MAX_FD in #(
145
+      max*)
146
+        MAX_FD=$( ulimit -H -n ) ||
147
+            warn "Could not query maximum file descriptor limit"
148
+    esac
149
+    case $MAX_FD in  #(
150
+      '' | soft) :;; #(
151
+      *)
152
+        ulimit -n "$MAX_FD" ||
153
+            warn "Could not set maximum file descriptor limit to $MAX_FD"
154
+    esac
155
+fi
156
+
157
+# Collect all arguments for the java command, stacking in reverse order:
158
+#   * args from the command line
159
+#   * the main class name
160
+#   * -classpath
161
+#   * -D...appname settings
162
+#   * --module-path (only if needed)
163
+#   * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
164
+
165
+# For Cygwin or MSYS, switch paths to Windows format before running java
166
+if "$cygwin" || "$msys" ; then
167
+    APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
168
+    CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
169
+
170
+    JAVACMD=$( cygpath --unix "$JAVACMD" )
171
+
172
+    # Now convert the arguments - kludge to limit ourselves to /bin/sh
173
+    for arg do
174
+        if
175
+            case $arg in                                #(
176
+              -*)   false ;;                            # don't mess with options #(
177
+              /?*)  t=${arg#/} t=/${t%%/*}              # looks like a POSIX filepath
178
+                    [ -e "$t" ] ;;                      #(
179
+              *)    false ;;
180
+            esac
181
+        then
182
+            arg=$( cygpath --path --ignore --mixed "$arg" )
183
+        fi
184
+        # Roll the args list around exactly as many times as the number of
185
+        # args, so each arg winds up back in the position where it started, but
186
+        # possibly modified.
187
+        #
188
+        # NB: a `for` loop captures its iteration list before it begins, so
189
+        # changing the positional parameters here affects neither the number of
190
+        # iterations, nor the values presented in `arg`.
191
+        shift                   # remove old arg
192
+        set -- "$@" "$arg"      # push replacement arg
193
+    done
194
+fi
195
+
196
+# Collect all arguments for the java command;
197
+#   * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
198
+#     shell script including quotes and variable substitutions, so put them in
199
+#     double quotes to make sure that they get re-expanded; and
200
+#   * put everything else in single quotes, so that it's not re-expanded.
201
+
202
+set -- \
203
+        "-Dorg.gradle.appname=$APP_BASE_NAME" \
204
+        -classpath "$CLASSPATH" \
205
+        org.gradle.wrapper.GradleWrapperMain \
206
+        "$@"
207
+
208
+# Use "xargs" to parse quoted args.
209
+#
210
+# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
211
+#
212
+# In Bash we could simply go:
213
+#
214
+#   readarray ARGS < <( xargs -n1 <<<"$var" ) &&
215
+#   set -- "${ARGS[@]}" "$@"
216
+#
217
+# but POSIX shell has neither arrays nor command substitution, so instead we
218
+# post-process each arg (as a line of input to sed) to backslash-escape any
219
+# character that might be a shell metacharacter, then use eval to reverse
220
+# that process (while maintaining the separation between arguments), and wrap
221
+# the whole thing up as a single "set" statement.
222
+#
223
+# This will of course break if any of these variables contains a newline or
224
+# an unmatched quote.
225
+#
226
+
227
+eval "set -- $(
228
+        printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
229
+        xargs -n1 |
230
+        sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
231
+        tr '\n' ' '
232
+    )" '"$@"'
233
+
234
+exec "$JAVACMD" "$@"
... ...
@@ -0,0 +1,89 @@
1
+@rem
2
+@rem Copyright 2015 the original author or authors.
3
+@rem
4
+@rem Licensed under the Apache License, Version 2.0 (the "License");
5
+@rem you may not use this file except in compliance with the License.
6
+@rem You may obtain a copy of the License at
7
+@rem
8
+@rem      https://www.apache.org/licenses/LICENSE-2.0
9
+@rem
10
+@rem Unless required by applicable law or agreed to in writing, software
11
+@rem distributed under the License is distributed on an "AS IS" BASIS,
12
+@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+@rem See the License for the specific language governing permissions and
14
+@rem limitations under the License.
15
+@rem
16
+
17
+@if "%DEBUG%" == "" @echo off
18
+@rem ##########################################################################
19
+@rem
20
+@rem  Gradle startup script for Windows
21
+@rem
22
+@rem ##########################################################################
23
+
24
+@rem Set local scope for the variables with windows NT shell
25
+if "%OS%"=="Windows_NT" setlocal
26
+
27
+set DIRNAME=%~dp0
28
+if "%DIRNAME%" == "" set DIRNAME=.
29
+set APP_BASE_NAME=%~n0
30
+set APP_HOME=%DIRNAME%
31
+
32
+@rem Resolve any "." and ".." in APP_HOME to make it shorter.
33
+for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34
+
35
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36
+set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37
+
38
+@rem Find java.exe
39
+if defined JAVA_HOME goto findJavaFromJavaHome
40
+
41
+set JAVA_EXE=java.exe
42
+%JAVA_EXE% -version >NUL 2>&1
43
+if "%ERRORLEVEL%" == "0" goto execute
44
+
45
+echo.
46
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47
+echo.
48
+echo Please set the JAVA_HOME variable in your environment to match the
49
+echo location of your Java installation.
50
+
51
+goto fail
52
+
53
+:findJavaFromJavaHome
54
+set JAVA_HOME=%JAVA_HOME:"=%
55
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56
+
57
+if exist "%JAVA_EXE%" goto execute
58
+
59
+echo.
60
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61
+echo.
62
+echo Please set the JAVA_HOME variable in your environment to match the
63
+echo location of your Java installation.
64
+
65
+goto fail
66
+
67
+:execute
68
+@rem Setup the command line
69
+
70
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71
+
72
+
73
+@rem Execute Gradle
74
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75
+
76
+:end
77
+@rem End local scope for the variables with windows NT shell
78
+if "%ERRORLEVEL%"=="0" goto mainEnd
79
+
80
+:fail
81
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82
+rem the _cmd.exe /c_ return code!
83
+if  not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84
+exit /b 1
85
+
86
+:mainEnd
87
+if "%OS%"=="Windows_NT" endlocal
88
+
89
+:omega
... ...
@@ -0,0 +1,2 @@
1
+rootProject.name = 'kata'
2
+
... ...
@@ -0,0 +1,19 @@
1
+package re.forestier.edu;
2
+import re.forestier.edu.rpg.Affichage;
3
+import re.forestier.edu.rpg.UpdatePlayer;
4
+import re.forestier.edu.rpg.player;
5
+
6
+import java.util.ArrayList;
7
+
8
+public class Main {
9
+    public static void main(String[] args) {
10
+        player firstPlayer = new player("Florian", "Ruzberg de Rivehaute", "DWARF", 200, new ArrayList<>());
11
+        firstPlayer.addMoney(400);
12
+
13
+        UpdatePlayer.addXp(firstPlayer, 15);
14
+        System.out.println(Affichage.afficherJoueur(firstPlayer));
15
+        System.out.println("------------------");
16
+        UpdatePlayer.addXp(firstPlayer, 20);
17
+        System.out.println(Affichage.afficherJoueur(firstPlayer));
18
+    }
19
+}
0 20
\ No newline at end of file
... ...
@@ -0,0 +1,19 @@
1
+package re.forestier.edu.rpg;
2
+
3
+public class Affichage {
4
+
5
+    public static String afficherJoueur(player player) {
6
+        final String[] finalString = {"Joueur " + player.Avatar_name + " joué par " + player.playerName};
7
+        finalString[0] += "\nNiveau : " + player.retrieveLevel() + " (XP totale : " + player.xp + ")";
8
+        finalString[0] += "\n\nCapacités :";
9
+        player.abilities.forEach((name, level) -> {
10
+            finalString[0] += "\n   " + name + " : " + level;
11
+        });
12
+        finalString[0] += "\n\nInventaire :";
13
+        player.inventory.forEach(item -> {
14
+            finalString[0] += "\n   " + item;
15
+        });
16
+
17
+        return finalString[0];
18
+    }
19
+}
... ...
@@ -0,0 +1,166 @@
1
+package re.forestier.edu.rpg;
2
+
3
+import java.util.HashMap;
4
+import java.util.Random;
5
+
6
+public class UpdatePlayer {
7
+
8
+    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", "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
+    };
10
+
11
+    public static HashMap<String, HashMap<Integer, HashMap<String, Integer>>> abilitiesPerTypeAndLevel() {
12
+        HashMap<String, HashMap<Integer, HashMap<String, Integer>>> abilitiesPerTypeAndLevel = new HashMap<>();
13
+
14
+        HashMap<Integer, HashMap<String, Integer>> adventurerMap = new HashMap<>();
15
+        HashMap<String, Integer> adventurerLevel1 = new HashMap<>();
16
+        adventurerLevel1.put("INT", 1);
17
+        adventurerLevel1.put("DEF", 1);
18
+        adventurerLevel1.put("ATK", 3);
19
+        adventurerLevel1.put("CHA", 2);
20
+        adventurerMap.put(1, adventurerLevel1);
21
+
22
+        HashMap<String, Integer> adventurerLevel2 = new HashMap<>();
23
+        adventurerLevel1.put("INT", 2);
24
+        adventurerLevel1.put("CHA", 3);
25
+        adventurerMap.put(2, adventurerLevel2);
26
+
27
+        HashMap<String, Integer> adventurerLevel3 = new HashMap<>();
28
+        adventurerLevel3.put("ATK", 5);
29
+        adventurerLevel3.put("ALC", 1);
30
+        adventurerMap.put(3, adventurerLevel3);
31
+
32
+        HashMap<String, Integer> adventurerLevel4 = new HashMap<>();
33
+        adventurerLevel4.put("DEF", 3);
34
+        adventurerMap.put(4, adventurerLevel4);
35
+
36
+        HashMap<String, Integer> adventurerLevel5 = new HashMap<>();
37
+        adventurerLevel5.put("VIS", 1);
38
+        adventurerLevel5.put("DEF", 4);
39
+        adventurerMap.put(5, adventurerLevel5);
40
+
41
+        abilitiesPerTypeAndLevel.put("ADVENTURER", adventurerMap);
42
+
43
+
44
+        HashMap<Integer, HashMap<String, Integer>> archerMap = new HashMap<>();
45
+        HashMap<String, Integer> archerLevel1 = new HashMap<>();
46
+        archerLevel1.put("INT", 1);
47
+        archerLevel1.put("ATK", 3);
48
+        archerLevel1.put("CHA", 1);
49
+        archerLevel1.put("VIS", 3);
50
+        archerMap.put(1, archerLevel1);
51
+
52
+        HashMap<String, Integer> archerLevel2 = new HashMap<>();
53
+        archerLevel2.put("DEF", 1);
54
+        archerLevel2.put("CHA", 2);
55
+        archerMap.put(2, archerLevel2);
56
+
57
+        HashMap<String, Integer> archerLevel3 = new HashMap<>();
58
+        archerLevel3.put("ATK", 3);
59
+        archerMap.put(3, archerLevel3);
60
+
61
+        HashMap<String, Integer> archerLevel4 = new HashMap<>();
62
+        archerLevel4.put("DEF", 2);
63
+        archerMap.put(4, archerLevel4);
64
+
65
+        HashMap<String, Integer> archerLevel5 = new HashMap<>();
66
+        archerLevel5.put("ATK", 4);
67
+        archerMap.put(5, archerLevel5);
68
+
69
+        abilitiesPerTypeAndLevel.put("ARCHER", archerMap);
70
+
71
+
72
+        HashMap<Integer, HashMap<String, Integer>> dwarf = new HashMap<>();
73
+        HashMap<String, Integer> dwarfLevel1 = new HashMap<>();
74
+        dwarfLevel1.put("ALC", 4);
75
+        dwarfLevel1.put("INT", 1);
76
+        dwarfLevel1.put("ATK", 3);
77
+        dwarf.put(1, dwarfLevel1);
78
+
79
+        HashMap<String, Integer> dwarfLevel2 = new HashMap<>();
80
+        dwarfLevel2.put("DEF", 1);
81
+        dwarfLevel2.put("ALC", 5);
82
+        dwarf.put(2, dwarfLevel2);
83
+
84
+        HashMap<String, Integer> dwarfLevel3 = new HashMap<>();
85
+        dwarfLevel3.put("ATK", 4);
86
+        dwarf.put(3, dwarfLevel3);
87
+
88
+        HashMap<String, Integer> dwarfLevel4 = new HashMap<>();
89
+        dwarfLevel4.put("DEF", 2);
90
+        dwarf.put(4, dwarfLevel4);
91
+
92
+        HashMap<String, Integer> dwarfLevel5 = new HashMap<>();
93
+        dwarfLevel5.put("CHA", 1);
94
+        dwarf.put(5, dwarfLevel5);
95
+
96
+        abilitiesPerTypeAndLevel.put("DWARF", dwarf);
97
+
98
+        return abilitiesPerTypeAndLevel;
99
+    }
100
+
101
+    public static boolean addXp(player player, int xp) {
102
+        int currentLevel = player.retrieveLevel();
103
+        player.xp += xp;
104
+        int newLevel = player.retrieveLevel();
105
+
106
+        if (newLevel != currentLevel) {
107
+            // Player leveled-up!
108
+            // Give a random object
109
+            ;
110
+            Random random = new Random();
111
+            player.inventory.add(objectList[random.nextInt(objectList.length - 0) + 0]);
112
+
113
+            // Add/upgrade abilities to player
114
+            HashMap<String, Integer> abilities = abilitiesPerTypeAndLevel().get(player.getAvatarClass()).get(newLevel);
115
+            abilities.forEach((ability, level) -> {
116
+                player.abilities.put(ability, abilities.get(ability));
117
+            });
118
+            return true;
119
+        }
120
+        return false;
121
+    }
122
+
123
+    // majFinDeTour met à jour les points de vie
124
+    public static void majFinDeTour(player player) {
125
+        if(player.currenthealthpoints == 0) {
126
+            System.out.println("Le joueur est KO !");
127
+            return;
128
+        }
129
+
130
+        if(player.currenthealthpoints < player.healthpoints/2) {
131
+            if(!player.getAvatarClass().equals("ADVENTURER")) {
132
+                if(player.getAvatarClass().equals("DWARF")) {
133
+                    if(player.inventory.contains("Holy Elixir")) {
134
+                        player.currenthealthpoints+=1;
135
+                    }
136
+                    player.currenthealthpoints+=1;
137
+                } else if(player.getAvatarClass().equals("ADVENTURER")) {
138
+                    player.currenthealthpoints+=2;
139
+                }
140
+
141
+
142
+                if(player.getAvatarClass().equals("ARCHER")) {
143
+                    player.currenthealthpoints+=1;
144
+                    if(player.inventory.contains("Magic Bow")) {
145
+                        player.currenthealthpoints+=player.currenthealthpoints/8-1;
146
+                    }
147
+                }
148
+            } else {
149
+                player.currenthealthpoints+=2;
150
+                if(player.retrieveLevel() < 3) {
151
+                    player.currenthealthpoints-=1;
152
+                }
153
+            }
154
+        } else if(player.currenthealthpoints >= player.healthpoints/2){
155
+            if(player.currenthealthpoints >= player.healthpoints) {
156
+                player.currenthealthpoints = player.healthpoints;
157
+                return;
158
+            }
159
+        }
160
+
161
+
162
+        if(player.currenthealthpoints >= player.healthpoints) {
163
+            player.currenthealthpoints = player.healthpoints;
164
+        }
165
+    }
166
+}
0 167
\ No newline at end of file
... ...
@@ -0,0 +1,87 @@
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
+
15
+    public int level;
16
+    public int healthpoints;
17
+    public int currenthealthpoints;
18
+    protected int xp;
19
+
20
+
21
+    public HashMap<String, Integer> abilities;
22
+    public ArrayList<String> inventory;
23
+    public player(String playerName, String avatar_name, String avatarClass, int money, ArrayList<String> inventory) {
24
+        if (!avatarClass.equals("ARCHER") && !avatarClass.equals("ADVENTURER") && !avatarClass.equals("DWARF") ) {
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
+}
0 88
\ No newline at end of file
... ...
@@ -0,0 +1,26 @@
1
+package re.forestier.edu;
2
+
3
+import org.junit.jupiter.api.DisplayName;
4
+import org.junit.jupiter.api.Test;
5
+import re.forestier.edu.rpg.Affichage;
6
+import re.forestier.edu.rpg.UpdatePlayer;
7
+import re.forestier.edu.rpg.player;
8
+
9
+import java.util.ArrayList;
10
+
11
+import static org.approvaltests.Approvals.verify;
12
+import static org.hamcrest.MatcherAssert.assertThat;
13
+import static org.hamcrest.Matchers.is;
14
+import static org.junit.jupiter.api.Assertions.fail;
15
+
16
+public class GlobalTest {
17
+
18
+    @Test
19
+    void testAffichageBase() {
20
+        player player = new player("Florian", "Gnognak le Barbare", "ADVENTURER", 200, new ArrayList<>());
21
+        UpdatePlayer.addXp(player, 20);
22
+        player.inventory = new ArrayList<>();
23
+
24
+        verify(Affichage.afficherJoueur(player));
25
+    }
26
+}
... ...
@@ -0,0 +1,10 @@
1
+Joueur Gnognak le Barbare joué par Florian
2
+Niveau : 2 (XP totale : 20)
3
+
4
+Capacités :
5
+   DEF : 1
6
+   ATK : 3
7
+   CHA : 3
8
+   INT : 2
9
+
10
+Inventaire :
0 11
\ No newline at end of file
... ...
@@ -0,0 +1,33 @@
1
+package re.forestier.edu;
2
+
3
+import org.junit.jupiter.api.*;
4
+import re.forestier.edu.rpg.player;
5
+import static org.hamcrest.MatcherAssert.assertThat;
6
+import static org.hamcrest.Matchers.*;
7
+import static org.junit.jupiter.api.Assertions.fail;
8
+
9
+import java.util.ArrayList;
10
+
11
+public class UnitTests {
12
+
13
+    @Test
14
+    @DisplayName("Sample test")
15
+    void testPlayerName() {
16
+        player player = new player("Florian", "Grognak le barbare", "ADVENTURER", 100, new ArrayList<>());
17
+        assertThat(player.playerName, is("Florian"));
18
+    }
19
+
20
+    @Test
21
+    @DisplayName("Impossible to have negative money")
22
+    void testNegativeMoney() {
23
+        player p = new player("Florian", "Grognak le barbare", "ADVENTURER", 100, new ArrayList<>());
24
+
25
+        try {
26
+            p.removeMoney(200);
27
+        } catch (IllegalArgumentException e) {
28
+            return;
29
+        }
30
+        fail();
31
+    }
32
+
33
+}
0 34