You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -27,17 +31,39 @@ public class TriviaController {
27
31
privateTextquestionBox;
28
32
29
33
privateTriviaLogicgame;
30
-
privateintscore=0;
31
-
34
+
35
+
/*
36
+
* This method initializes a game
37
+
*/
32
38
publicvoidinitialize() {
33
-
ReadFile.openFile();
34
-
game=newTriviaLogic();
35
-
setScore();
36
-
setGameRound();
39
+
ReadFile.openFile();//opens the questions and answers file
40
+
game=newTriviaLogic();//creates a game of triviaLogic
41
+
setScore();//set the score to 0;
42
+
setGameRound();//sets the game for the round
37
43
}
38
-
44
+
45
+
/*
46
+
* This method sets a next round of the game
47
+
* changes the question and the possible four answers
48
+
*/
39
49
privatevoidsetGameRound(){
40
-
questionBox.setText(ReadFile.nextLine());
50
+
Stringquestion=ReadFile.nextLine();
51
+
if (question.equals("Game Ended")) {
52
+
Alertalert = newAlert(AlertType.CONFIRMATION);
53
+
alert.setTitle("Game Ended");
54
+
alert.setHeaderText("You have reached the end of the game");
55
+
alert.setContentText("You have reached the end of the game\nYou got "+ game.get_score() + " Points \nThanks for playing \nIf you wish to play again press: OK \nIf you wish to close the game press: CANCEL");
* This method displays a message if the answer was correct or incorrect and allows the player to choose to close the game or continue for the next question
100
+
*/
101
+
privatevoiddisplayMessage(booleancorrect) {
102
+
Alertalert = newAlert(AlertType.CONFIRMATION);
103
+
alert.setContentText("The answer was: " + game.getCorrectAnswer()+ "\nIf you wish to try another question press: OK \nIf you wish to close the game press: CANCEL ");
* This method sets _correctAnswer variable to contain the correct answer
8
+
*/
9
+
publicvoidsetCorrectAnswer(StringcorrectAnswer) {
10
+
_correctAnswer = correctAnswer;
11
+
}
11
12
12
-
publicbooleancheckAnswer(Stringanswer) {
13
-
return (_correctAnswer.equals(answer));
14
-
}
13
+
/*
14
+
* This method returns the correct answer
15
+
*/
16
+
publicStringgetCorrectAnswer() {
17
+
return_correctAnswer;
18
+
}
19
+
20
+
/*
21
+
* This method checks if the answer given as parameter is equal to the correct answer, if it is it means that the answer provided as parameter is the correct answer for the question
0 commit comments