Skip to content
Snippets Groups Projects
Commit 77441daa authored by Thomas BREIL's avatar Thomas BREIL
Browse files

Add MarkdownDisplay and MarkdwonWriteFile methods

parent 683a4754
Branches main
No related tags found
No related merge requests found
......@@ -15,6 +15,6 @@ public class Main {
System.out.println(Display.afficherJoueur(firstPlayer));
System.out.println("------------------");
MarkdownDisplay.writeMarkdownFile(firstPlayer);
}
}
\ No newline at end of file
package re.forestier.edu.rpg;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
public class MarkdownDisplay {
public static String displayPlayer(Player player) {
String finalString = "# Joueur Gnognak le Barbare joué par Florian" + "\n";
finalString += "## Niveau : 2 (XP totale : 20)" + "\n";
finalString += "## Capacités :" + "\n";
finalString += "ATK : 3" + "\n";
finalString += "DEF : 1" + "\n";
finalString += "CHA : 3" + "\n";
finalString += "INT : 2" + "\n";
finalString += "## Inventaire :" + "\n";
finalString += "SWORD" + "\n";
return finalString;
final String[] finalString = {"# Joueur " + player.avatarName + " joué par " + player.playerName + "\n"};
finalString[0] += "\n## Niveau : "+ player.level+ " (XP totale : " + player.xp + ")" + "\n";
finalString[0] += "\n## Capacités :" + "\n";
// Sort the abilities by name before displaying them to have a consistent display
player.abilities.keySet().stream()
.sorted()
.forEach((name) -> finalString[0] += "\n" + name + " : " + player.abilities.get(name) + "\n");
finalString[0] += "\n" + "## Inventaire :" + "\n";
player.inventory.forEach(item -> finalString[0] += "\n" + item.name + "\n");
return finalString[0];
}
public static void writeMarkdownFile(Player player) {
String markdown = displayPlayer(player);
try {
Path path = Paths.get("src/main/resources");
if (!Files.exists(path)) {
Files.createDirectory(path);
}
Path path1 = Paths.get(path + "/Markdown.md");
if (!Files.exists(path1)) {
Files.createFile(path1);
}
Files.write(path1, markdown.getBytes());
} catch (IOException e) {
System.out.println("An error occurred while creating Markdown File.");
}
}
}
# Joueur Ruzberg de Rivehaute joué par Florian
## Niveau : 3 (XP totale : 35)
## Capacités :
ALC : 5
ATK : 4
DEF : 1
INT : 1
## Inventaire :
Scroll of Stupidity
Magic Charm
......@@ -13,10 +13,13 @@ public class MarkdownTest {
@Test
@DisplayName("Name test")
void testDisplay() {
Dwarf player = new Dwarf("Florian", "Grognak le barbare", 100, new ArrayList<>());
Dwarf player = new Dwarf("Florian", "Grognak le Barbare", 100, new ArrayList<>());
Object sword = new Object("SWORD", 10, 5, "Epée en bois");
player.inventory.add(sword);
player.addXp(20);
player.sell(player.inventory.get(1));
MarkdownDisplay.writeMarkdownFile(player);
verify(MarkdownDisplay.displayPlayer(player));
}
......
# Joueur Gnognak le Barbare joué par Florian
# Joueur Grognak le Barbare joué par Florian
## Niveau : 2 (XP totale : 20)
## Capacités :
ALC : 5
ATK : 3
DEF : 1
CHA : 3
INT : 2
INT : 1
## Inventaire :
SWORD
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment