From eadd9316e157fd30ef6027b7ab0112a753bebaa0 Mon Sep 17 00:00:00 2001 From: Friederike von Gruben Date: Thu, 2 Feb 2023 01:09:33 +0100 Subject: [PATCH] refactoring: Outsourced gold method The method to add gold after your answer was right is now in a seperate method --- .../org/bitbiome/commands/QuizCommand.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/bitbiome/commands/QuizCommand.java b/src/main/java/org/bitbiome/commands/QuizCommand.java index 2c1007d..658a898 100644 --- a/src/main/java/org/bitbiome/commands/QuizCommand.java +++ b/src/main/java/org/bitbiome/commands/QuizCommand.java @@ -32,13 +32,8 @@ public class QuizCommand implements CommandAPI { int eingabe = quizScanner.nextInt(); if (answerIsCorrect(eingabe, korrekteAntwort, antworten)) { - String playerpath = "src\\main\\resources\\playerconfig.json"; - JSONObject playerconfig = JsonParser.readJSONFile(playerpath); - int gold = playerconfig.getInt("gold"); - gold = gold + 5; - playerconfig.put("gold", gold); - JsonParser.writeObject(playerpath, playerconfig); - print("Richtig! Du hast 5 Münzen verdient.\nDein Münzstand beträgt: " + gold); + int neuerStand = addGold(); + print("Richtig! Du hast 5 Münzen verdient.\nDein Münzstand beträgt: " + neuerStand); } else { print("Leider falsch... Richtig ist: " + korrekteAntwort + "\n"); } @@ -68,6 +63,16 @@ public class QuizCommand implements CommandAPI { return sb.toString(); } + public static int addGold() { + String playerpath = "src\\main\\resources\\playerconfig.json"; + JSONObject playerconfig = JsonParser.readJSONFile(playerpath); + int gold = playerconfig.getInt("gold"); + gold = gold + 5; + playerconfig.put("gold", gold); + JsonParser.writeObject(playerpath, playerconfig); + return gold; + } + }