diff --git a/src/main/java/org/bitbiome/commands/QuizCommand.java b/src/main/java/org/bitbiome/commands/QuizCommand.java index cdcf4e1..3d10aea 100644 --- a/src/main/java/org/bitbiome/commands/QuizCommand.java +++ b/src/main/java/org/bitbiome/commands/QuizCommand.java @@ -1,12 +1,35 @@ package org.bitbiome.commands; +import org.bitbiome.classes.JsonParser; +import org.json.JSONArray; +import org.json.JSONObject; + +import java.util.Random; import java.util.Scanner; public class QuizCommand implements CommandAPI { @Override public void performCommand(Scanner scanner, boolean isRunning, String message) { + String path = "src\\main\\resources\\quiz.json"; + JSONObject quiz = JsonParser.readJSONFile(path); + + JSONArray fragen = quiz.getJSONArray("Quiz"); + int index = new Random().nextInt(fragen.length()); + JSONObject frage = fragen.getJSONObject(index); + JSONArray antworten = frage.getJSONArray("antworten"); + + System.out.println("Du hast das Quiz gestartet! Hinweis: Wähle deine Antwort, indem du die Zahl (1-4) eingibst. Ist deine Lösung richtig, erhälst du 5 Münzen. Viel Erfolg! \n"); + + String frageString = frage.getString("frage"); + + System.out.println(frageString); + + for (int i = 0; i < antworten.length(); i++) { + String antwort = antworten.getString(i); + System.out.println(i + 1 + ". " + antwort); + } } }