From 4cc849ee0b5176b9e560af47bd9b65f360e03d4f Mon Sep 17 00:00:00 2001 From: Ozan-Can Ekinci Date: Tue, 10 Jan 2023 17:10:36 +0100 Subject: [PATCH] refactoring: implemented method for loading next question --- src/main/java/game/loadNextQuestion.java | 34 +++++++++++------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/src/main/java/game/loadNextQuestion.java b/src/main/java/game/loadNextQuestion.java index b38c8cb..bedc45d 100644 --- a/src/main/java/game/loadNextQuestion.java +++ b/src/main/java/game/loadNextQuestion.java @@ -12,49 +12,45 @@ public class loadNextQuestion implements ActionListener { if (runGame.splitAns[4].equals("1")) { if (e.getSource() == GameGui.AnswersBtn1) { - if (GameGui.questionNr != runGame.arrQuestions.length - 1) { - runGame StartGame = new runGame(); - StartGame.run(GameGui.questionNr); - } + loadQuestions(); } else { System.exit(0); } } + else if (runGame.splitAns[4].equals("2")) { if (e.getSource() == GameGui.AnswersBtn2) { - if (GameGui.questionNr != runGame.arrQuestions.length - 1) { - runGame StartGame = new runGame(); - StartGame.run(GameGui.questionNr); - } + loadQuestions(); } else { System.exit(0); } } + else if (runGame.splitAns[4].equals("3")) { if (e.getSource() == GameGui.AnswersBtn3) { - if (GameGui.questionNr != runGame.arrQuestions.length - 1) { - runGame StartGame = new runGame(); - StartGame.run(GameGui.questionNr); - } + loadQuestions(); } else { System.exit(0); } } + else if (runGame.splitAns[4].equals("4")) { if (e.getSource() == GameGui.AnswersBtn4) { - if (GameGui.questionNr != runGame.arrQuestions.length - 1) { - runGame StartGame = new runGame(); - StartGame.run(GameGui.questionNr); - } + loadQuestions(); } else { System.exit(0); } } - + } - } + public void loadQuestions() { + if (GameGui.questionNr != runGame.arrQuestions.length - 1) { + runGame StartGame = new runGame(); + StartGame.run(GameGui.questionNr); + } + } -} + }