Browse Source

refactoring: Outsourced gold method

The method to add gold after your answer was right is now in a seperate method
remotes/origin/quiz
Friederike von Gruben 2 years ago
parent
commit
eadd9316e1
  1. 19
      src/main/java/org/bitbiome/commands/QuizCommand.java

19
src/main/java/org/bitbiome/commands/QuizCommand.java

@ -32,13 +32,8 @@ public class QuizCommand implements CommandAPI {
int eingabe = quizScanner.nextInt(); int eingabe = quizScanner.nextInt();
if (answerIsCorrect(eingabe, korrekteAntwort, antworten)) { 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 { } else {
print("Leider falsch... Richtig ist: " + korrekteAntwort + "\n"); print("Leider falsch... Richtig ist: " + korrekteAntwort + "\n");
} }
@ -68,6 +63,16 @@ public class QuizCommand implements CommandAPI {
return sb.toString(); 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;
}
} }
Loading…
Cancel
Save