Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/main/java/edu/sdccd/cisc190/Main.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package edu.sdccd.cisc190;

import edu.sdccd.cisc190.game.QuizGame;
import edu.sdccd.cisc190.question.MultipleChoiceQuestion;
import edu.sdccd.cisc190.question.Question;
import edu.sdccd.cisc190.question.TrueFalseQuestion;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Scene;
Expand Down Expand Up @@ -110,6 +114,7 @@ public void startGame() {
* </p>
*/
private void showQuestion() {
//TODO: Create an exception for out-of-bounds index.
if (currentQuestionIndex >= quizGame.getQuestions().size()) {
endGame();
return;
Expand Down Expand Up @@ -171,6 +176,11 @@ public void startTimer() {
}, 0, 1, TimeUnit.SECONDS);
}


//TODO: alert the user after every minute passes by

//TODO: Change the font color of the timer to red when the time reaches 30 seconds left
//TODO: could add some color to the game
/**
* Ends the quiz game and displays the final score.
* <p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

package edu.sdccd.cisc190;
package edu.sdccd.cisc190.game;
/**
* Abstract base class that provides the structure for any game.
* <p>
Expand All @@ -9,7 +9,7 @@
* </p>
*/
public abstract class Game {

//Space out Javdocs and code for better style and readability/understanding//
/**
* The name of the game.
*/
Expand All @@ -19,6 +19,10 @@ public abstract class Game {
*/

private boolean isRunning;
//TODO: Use protected visibility for 'isRunning' if subclasses need access. Otherwise, leave it private
// This could be protected depending on design needs.




/**
Expand All @@ -31,20 +35,24 @@ public Game(String gameName) {
this.gameName = gameName;
this.isRunning = false;
}
//TODO: create a logger to log instead of using system.out
/**
* Starts the game by setting the status to running and printing a start message.
*/
public void startGame() {
isRunning = true;
System.out.println(gameName + " has started!");
System.out.printf("%s has started!", gameName);
}
/**
* Ends the game by setting the status to not running and printing an end message.
*/
public void endGame() {
isRunning = false;

//TODO: use a formatted print statement just like in startGame()
System.out.println(gameName + " has ended.");
}

/**
* Checks whether the game is currently running.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
package edu.sdccd.cisc190;
package edu.sdccd.cisc190.game;

import edu.sdccd.cisc190.question.MultipleChoiceQuestion;
import edu.sdccd.cisc190.question.Question;
import edu.sdccd.cisc190.question.TrueFalseQuestion;

import java.io.*;
import java.util.ArrayList;
Expand All @@ -11,12 +15,19 @@
* for managing quiz questions and scores, loading questions from a file, and saving high scores.
* </p>
*/

//TODO: Integrate JavaFX UI to display questions and collect answers interactively.

public class QuizGame extends Game {
//TODO: Implement a game timer using a background thread to track the elapsed time.
// Example: Use Thread.sleep() in a loop and update the timer in the console or GUI.

/**
* A list of questions for the quiz game.
*/
private final List<Question> questions;
// TODO: Consider using an array if the number of questions is fixed.


/**
* The player's current score in the game.
Expand Down Expand Up @@ -48,21 +59,21 @@ public QuizGame(String gameName) {
* @param filePath the path to the file containing questions
* @throws IOException if an I/O error occurs while reading the file
*/
// explination is to Catch and handle exceptions gracefully. Update the UI to notify users of issues and allow retrying.
public void loadQuestions(String filePath) throws IOException {
BufferedReader reader = new BufferedReader(new FileReader(filePath));
String line;

while ((line = reader.readLine()) != null) {
String[] parts = line.split(";");
if (parts[0].equalsIgnoreCase("MC")) {
questions.add(new MultipleChoiceQuestion(parts[1], parts[2], parts[3].split(",")));
} else if (parts[0].equalsIgnoreCase("TF")) {
questions.add(new TrueFalseQuestion(parts[1], parts[2]));
try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) {
String line;
while ((line = reader.readLine()) != null) {
// Parsing logic here
}
} catch (IOException e) {
//TODO: Notify user of the error via GUI and provide a retry option.
throw new IOException("Error reading questions file: " + filePath, e);
}
reader.close();
}



/**
* Saves the player's high score to a file.
* <p>
Expand All @@ -74,12 +85,16 @@ public void loadQuestions(String filePath) throws IOException {
* @throws IOException if an I/O error occurs while writing to the file
*/
public void saveHighScore(int score) throws IOException {
//TODO: Confirm file location is writable and handle potential IOException with user notification.
String highScoresFile = "src/main/resources/highscores.txt";
BufferedWriter writer = new BufferedWriter(new FileWriter(highScoresFile, true));
writer.write("Score: " + score + "\n");
writer.close();
}



//TODO: create a leaderboard that stores the user's best time/high scores
/**
* Returns the list of questions in the game.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package edu.sdccd.cisc190;
package edu.sdccd.cisc190.question;

/**
* Represents a multiple-choice question.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package edu.sdccd.cisc190;
package edu.sdccd.cisc190.question;

/**
* Represents a general question in a quiz or game.
Expand Down Expand Up @@ -43,3 +43,6 @@ public String getQuestionText() {
*/
public abstract boolean checkAnswer(String answer);
}
//TODO: Demonstrate polymorphism by adding a `displayQuestion()` method in the base class
// and overriding it in child classes to provide specific behavior.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package edu.sdccd.cisc190;
package edu.sdccd.cisc190.question;

/**
* Represents a "True/False" type question in the quiz game.
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/edu/sdccd/cisc190/GameTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package edu.sdccd.cisc190;

import edu.sdccd.cisc190.game.Game;
import edu.sdccd.cisc190.game.QuizGame;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package edu.sdccd.cisc190;

import edu.sdccd.cisc190.question.MultipleChoiceQuestion;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package edu.sdccd.cisc190;

import edu.sdccd.cisc190.game.QuizGame;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;

Expand Down
1 change: 1 addition & 0 deletions src/test/java/edu/sdccd/cisc190/QuizGameTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package edu.sdccd.cisc190;

import edu.sdccd.cisc190.game.QuizGame;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.io.IOException;
Expand Down
1 change: 1 addition & 0 deletions src/test/java/edu/sdccd/cisc190/TrueFalseQuestionTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package edu.sdccd.cisc190;

import edu.sdccd.cisc190.question.TrueFalseQuestion;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;

Expand Down