From 1b0d11c9ad6c3306f6725d1b516f4c9b0757f90e Mon Sep 17 00:00:00 2001 From: Ozan-Can Ekinci Date: Mon, 16 Jan 2023 22:24:37 +0100 Subject: [PATCH] refactoring: refactored createShowQuestion method --- src/main/java/Gui/GameGui.java | 23 ++++++++++++----------- src/main/java/Gui/GameGuiInterface.java | 2 +- src/main/java/Gui/StartGameGui.java | 2 +- src/main/java/game/loadNextQuestion.java | 2 +- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/main/java/Gui/GameGui.java b/src/main/java/Gui/GameGui.java index 52c2a30..a7dade6 100644 --- a/src/main/java/Gui/GameGui.java +++ b/src/main/java/Gui/GameGui.java @@ -21,6 +21,7 @@ public class GameGui implements GameGuiInterface { public static int questionNr = 0; public static int currentQuestion = 1; public static int highScore = 0; + public static String Path ="QandA/Money.txt"; GridLayout grid; GridBagConstraints gbc; @@ -104,17 +105,17 @@ public class GameGui implements GameGuiInterface { } @Override - public void createShowQuestion(int i) { - int numLines = runGame.CountFileLines("QandA/Money.txt"); - String[] arrMoney = runGame.readFile("QandA/Money.txt", numLines); - String questionText = "Frage " + currentQuestion + ": " + arrMoney[i - 1] + " Euro"; - currentQuestion++; - - CurrentQuestionNrLabel.setText(questionText); - CurrentQuestionNrLabel.setFont(new Font("Serif", Font.BOLD, 20)); - MainPanel.add(CurrentQuestionNrLabel); - } - + public void createShowQuestion(int i, String Path) { + int numLines = runGame.CountFileLines(Path); + String[] arrMoney = runGame.readFile(Path, numLines); + String questionText = "Frage " + currentQuestion + ": " + arrMoney[i - 1] + " Euro"; + currentQuestion++; + + CurrentQuestionNrLabel.setText(questionText); + CurrentQuestionNrLabel.setFont(new Font("Serif", Font.BOLD, 20)); + MainPanel.add(CurrentQuestionNrLabel); + } + @Override public void createHeadline() { HeadlineLabel = new JLabel("Wer wird Millionaer"); diff --git a/src/main/java/Gui/GameGuiInterface.java b/src/main/java/Gui/GameGuiInterface.java index 5250685..48acac5 100644 --- a/src/main/java/Gui/GameGuiInterface.java +++ b/src/main/java/Gui/GameGuiInterface.java @@ -18,7 +18,7 @@ public interface GameGuiInterface { void createButtons(); - void createShowQuestion(int questionNr); + void createShowQuestion(int questionNr, String Path); void highScore(); diff --git a/src/main/java/Gui/StartGameGui.java b/src/main/java/Gui/StartGameGui.java index c98e8d1..591f7d2 100644 --- a/src/main/java/Gui/StartGameGui.java +++ b/src/main/java/Gui/StartGameGui.java @@ -19,6 +19,6 @@ public class StartGameGui implements ActionListener { runGame rungame = new runGame(); rungame.run(GameGui.questionNr); - Gui.createShowQuestion(GameGui.questionNr); + Gui.createShowQuestion(GameGui.questionNr, GameGui.Path); } } diff --git a/src/main/java/game/loadNextQuestion.java b/src/main/java/game/loadNextQuestion.java index b2fafdd..a94a168 100644 --- a/src/main/java/game/loadNextQuestion.java +++ b/src/main/java/game/loadNextQuestion.java @@ -49,7 +49,7 @@ public class loadNextQuestion implements ActionListener { public void loadQuestions() { if (GameGui.questionNr != runGame.arrQuestions.length - 1) { StartGame.run(GameGui.questionNr); - gameStatus.createShowQuestion(GameGui.questionNr); + gameStatus.createShowQuestion(GameGui.questionNr, GameGui.Path); } else { gameStatus.createWinningPanel(); }