diff --git a/src/main/java/event/Event02.java b/src/main/java/event/Event02.java index ae445fb..fbf2870 100644 --- a/src/main/java/event/Event02.java +++ b/src/main/java/event/Event02.java @@ -2,20 +2,41 @@ import main.GameManager; +/** +* This class manages the scenes and actions for Event02 +*/ + public class Event02 { GameManager gm; + /** + * Sets up Event02 with the game manager. + * + * @param gm the main game manager + */ public Event02(GameManager gm) { this.gm = gm; } + + /** + * Checks the first spot on the Honda. + */ public void search1Honda() { gm.ui.messageText.setText("Nothing sus here"); } + + /** + * Checks the second spot on the Honda. + */ public void search2Honda() { gm.ui.messageText.setText("OH MY GYAT MY ENGINE IS MISSING"); } + + /** + * Lets the player rest on the Honda and heal life. + */ public void restHonda() { if(gm.player.playerLife != gm.player.playerMaxLife) { gm.ui.messageText.setText("*You rest on the hood of your car*\n(Your life has been recovered)"); @@ -29,4 +50,7 @@ public void restHonda() { } } + // TODO: Make sure the game manager (gm) is not null in the constructor. + // TODO: Combine repeated actions like updating player status into a helper method. + // TODO: Check that player life values are not negative to avoid errors. } diff --git a/src/main/java/event/Event03.java b/src/main/java/event/Event03.java index d0d0de4..624b89b 100644 --- a/src/main/java/event/Event03.java +++ b/src/main/java/event/Event03.java @@ -2,22 +2,45 @@ import main.GameManager; +/** + * Handles scenes and actions for Event03. + */ public class Event03 { GameManager gm; + /** + * Sets up Event03 with the game manager. + * + * @param gm the main game manager + */ public Event03(GameManager gm) { this.gm = gm; } + + /** + * Shows the description of the Hondaur. + */ public void lookHondaur() { gm.ui.messageText.setText("Its a Hondaur"); } + + /** + * Describes the interaction with the Hondaur. + */ public void talkHondaur() { gm.ui.messageText.setText("The Hondaur growls at you and revs his engine "); } + + /** + * Explains the player's attack on the Hondaur. + */ public void attackHondaur() { gm.ui.messageText.setText("*You start beating the shit out of the poor Hondaur*"); } + + // TODO: Check that the game manager (gm) is not null when this class is created. + // TODO: Add error handling for sounds in case they are missing or invalid. } diff --git a/src/main/java/event/Event04.java b/src/main/java/event/Event04.java index 05e8356..b85eaf3 100644 --- a/src/main/java/event/Event04.java +++ b/src/main/java/event/Event04.java @@ -2,17 +2,33 @@ import main.GameManager; +/** + * Manages scenes and actions for Event04. + */ public class Event04 { GameManager gm; + /** + * Sets up Event04 with the game manager. + * + * @param gm the main game manager + */ public Event04(GameManager gm) { this.gm = gm; } + + /** + * Shows the description of Denzel. + */ public void lookDenzel() { gm.ui.messageText.setText("This is Denzel. (He listens to Valorant music)"); } + + /** + * Lets Denzel give the player a pistol if they don't already have one. + */ public void talkDenzel() { if(gm.player.hasPistol == 0) { gm.player.hasPistol = 1; @@ -26,6 +42,10 @@ public void talkDenzel() { gm.playSE(gm.cannotSound); } } + + /** + * Lets the player recover life with Denzel's help. + */ public void restDenzel() { if(gm.player.playerLife != gm.player.playerMaxLife) { gm.ui.messageText.setText("(Denzel has been lonely without his girlfriend)\n*Denzel runs up to you unexpectedly and gives you a hug*\n(Your life has been recovered)"); @@ -39,4 +59,8 @@ public void restDenzel() { gm.playSE(gm.cannotSound); } } + + // TODO: Check that the game manager (gm) is not null when the class is created. + // TODO: Create a helper method for repeated life recovery code. + // TODO: Make sure the pistol value (hasPistol) is either 0 or 1 only. } diff --git a/src/main/java/event/Event05.java b/src/main/java/event/Event05.java index 1d44ad5..8375c19 100644 --- a/src/main/java/event/Event05.java +++ b/src/main/java/event/Event05.java @@ -2,14 +2,26 @@ import main.GameManager; +/** + * Manages scenes and actions for Event05. + */ public class Event05 { GameManager gm; + /** + * Sets up Event05 with the game manager. + * + * @param gm the main game manager + */ public Event05(GameManager gm) { this.gm = gm; } + + /** + * Shows that Brian is in the Honda trunk. + */ public void lookHondaTrunk() { if(gm.player.hasPistol == 1){ gm.ui.messageText.setText("IS THAT BRIAN FROM MARAUDER CODED!"); @@ -18,6 +30,10 @@ public void lookHondaTrunk() { gm.ui.messageText.setText("(You see Brian's dead body)"); } } + + /** + * Talks to the Honda trunk. + */ public void talkHondaTrunk() { if(gm.theodoor.currentLife==0 && gm.wheeler.currentLife==0) { if(gm.player.hasPistol == 1){ @@ -32,6 +48,10 @@ public void talkHondaTrunk() { gm.playSE(gm.cannotSound); } } + + /** + * Ends Brian's misery in the Honda trunk. + */ public void killHondaTrunk() { if(gm.theodoor.currentLife == 0 && gm.wheeler.currentLife == 0) { @@ -51,4 +71,8 @@ public void killHondaTrunk() { } } + + // TODO: Add checks to ensure game objects like gm and player are valid. + // TODO: Restructure repeated conditions like checking currentLife into a helper method to make sure there's no code duplication and so readbility could be better since it makes sure the purpose of the condition is clear. + // TODO: Add a log to track when the pistol state (hasPistol) changes } diff --git a/src/main/java/event/Event06.java b/src/main/java/event/Event06.java index ddb4d8a..9acf587 100644 --- a/src/main/java/event/Event06.java +++ b/src/main/java/event/Event06.java @@ -3,27 +3,49 @@ import javafx.scene.image.ImageView; import main.GameManager; +/** + * Handles scenes and actions for Event06. + */ public class Event06 { GameManager gm; private ImageView denzel; + /** + * Sets up Event06 with the game manager. + * + * @param gm the main game manager + */ public Event06(GameManager gm) { this.gm = gm; } + + /** + * Resets Denzel's visibility. + */ public void reset(){ if (denzel != null) { denzel.setVisible(false); } } - + + /** + * Shows Denzel. + */ public void lookDenzel(){ gm.ui.messageText.setText("Denzel shows up"); } + + /** + * Talks to Denzel. + */ public void talkDenzel(){ gm.ui.messageText.setText("I got worried for you so I ran after you"); - } + + /** + * Plays Valorant music to cheer up Denzel. + */ public void playDenzel(){ if(gm.player.hasAk47 == 0) { @@ -40,12 +62,23 @@ public void playDenzel(){ } + /** + * Shows Brandon. + */ public void lookBrandon() { gm.ui.messageText.setText("This is Brandon. He seems to be doing a fit check"); } + + /** + * Talks to Brandon. + */ public void talkBrandon() { gm.ui.messageText.setText("Yo I wouldn't go in there if I were you! A monster is on the loose!"); } + + /** + * Lets the player rest and recover life with Brandon's help. + */ public void restBrandon() { if(gm.player.playerLife != gm.player.playerMaxLife) { gm.ui.messageText.setText("You look injured... Come here\n*Brandon gives you a warm hug*\n(You gain life)"); @@ -70,4 +103,8 @@ public void restBrandon() { } } + +// TODO: Check if gm and Denzel are not null before using them. +// TODO: Create a method to play sounds instead of repeating the code. +// TODO: Make sure hasAk47 is valid before using it. } diff --git a/src/main/java/event/Event07.java b/src/main/java/event/Event07.java index 96a2825..9d251dd 100644 --- a/src/main/java/event/Event07.java +++ b/src/main/java/event/Event07.java @@ -2,21 +2,37 @@ import main.GameManager; +/** + * Manages scenes and actions for Event07. + */ public class Event07 { GameManager gm; public int julianLife = 2; + /** + * Sets up Event07 with the game manager. + * + * @param gm the main game manager + */ public Event07(GameManager gm) { this.gm = gm; } + + /** + * Shows Julian and his current condition. + */ public void lookJulian() { gm.ui.messageText.setText("Julian is in serious condition"); if(julianLife ==0) { gm.ui.messageText.setText("You see Julien's lifeless body"); } } + + /** + * Talks to Julian. + */ public void talkJulian() { if(julianLife == 2 || julianLife == 1) { gm.ui.messageText.setText("*Julian cries when he sees you* I don't want to die..."); @@ -26,6 +42,10 @@ public void talkJulian() { gm.playSE(gm.cannotSound); } } + + /** + * Comforts Julian and updates his state. + */ public void holdJulian() { if(julianLife == 2) { gm.ui.messageText.setText("*You hold Julian's hand and tell him it'll be okay*\nJulian says his last words: Can you spin it one last time for me?"); @@ -73,4 +93,8 @@ public void thankAdrian() { gm.ui.messageText.setText("*You thank Adrian for his great efforts*\n (Adrian will give you 10% of his profits if you avenge Julian)"); } + + // TODO: Add checks for null or invalid game manager and player objects. + // TODO: Ensure Julian's life values are limited to valid states (0, 1, 2). + // TODO: Simplify repeated messages and conditions into a helper function. } diff --git a/src/main/java/main/ActionHandler.java b/src/main/java/main/ActionHandler.java index 2716af9..f267f26 100644 --- a/src/main/java/main/ActionHandler.java +++ b/src/main/java/main/ActionHandler.java @@ -7,7 +7,9 @@ import javafx.event.EventHandler; public class ActionHandler implements EventHandler { - + // TODO: Add a class-level Javadoc to explain the purpose of this class + // TODO: Ensure class names and methods follow naming conventions + // TODO: Use meaningful variable names for 'yourChoice', like 'buttonText' GameManager gm; public ActionHandler(GameManager gm) { @@ -16,12 +18,16 @@ public ActionHandler(GameManager gm) { @Override public void handle(ActionEvent e) { + // TODO: Catch exceptions to handle unexpected errors when casting or processing button actions String yourChoice = ((javafx.scene.control.Button) e.getSource()).getText(); handleAction(yourChoice); } // handles the action commands public void handleAction(String yourChoice) { + // TODO: Use a Map or more efficient structure to store button actions instead of switch-case + // TODO: Add comments for each section of switch-case to describe what each block does + // TODO: Add input validation for 'yourChoice' to avoid NullPointerExceptions switch (yourChoice) { // SCENE 1 case "lookJeramiah": diff --git a/src/main/java/main/GameManager.java b/src/main/java/main/GameManager.java index cd88b9e..142b84d 100644 --- a/src/main/java/main/GameManager.java +++ b/src/main/java/main/GameManager.java @@ -16,6 +16,9 @@ import java.util.List; public class GameManager extends Application { + // TODO: Add Javadoc to explain the purpose of this class and its main responsibilities + // TODO: Handles exceptions gracefully in all methods, such as file-related operations or invalid inputs + // TODO: Add proper shutdown handling when the application exists ActionHandler aHandler = new ActionHandler(this); public UI ui = new UI(this); @@ -67,6 +70,8 @@ public static void main(String[] args) { @Override public void start(Stage primaryStage) { + // TODO: Add a try-catch block to catch expressions during UI initialization + // TODO: Ensure all JavaFX components are initialized before use currentMusic = mainTheme; playMusic(currentMusic); @@ -77,6 +82,7 @@ public void start(Stage primaryStage) { } public void playSE(URL url) { + // TODO: Add null checks for 'url' before using it se.setFile(url); se.play(url); @@ -94,6 +100,7 @@ public void stopMusic(URL url){ public void startGameTimer() { + // TODO: Ensure the timer stops properly if already running before starting a new one startTime = System.nanoTime(); gameTimer = new AnimationTimer() { @Override @@ -104,6 +111,10 @@ public void handle(long now) { }; gameTimer.start(); } + + /** + * Stops the game timer and updates the leaderboard if the monster is defeated. + */ public void stopGameTimer() { if (gameTimer != null) { @@ -116,6 +127,10 @@ public void stopGameTimer() { } } +/** + * Updates the game's timer display on the UI. + */ + public void updateTimerUI() { // Format the time as minutes and seconds long seconds = elapsedTime / 1000; @@ -125,6 +140,11 @@ public void updateTimerUI() { // Display the timer on the UI ui.timerLabel.setText(String.format("%02d:%02d", minutes, seconds)); } + + /** + * Displays the Leaderboard with the fastest times. + */ + public void showLeaderboard() { List leaderboard = timeManager.getFormattedFastestTimes(); ui.displayLeaderboard(leaderboard); // Add a method in UI to display the leaderboard diff --git a/src/main/java/main/Music.java b/src/main/java/main/Music.java index 0053b11..0390178 100644 --- a/src/main/java/main/Music.java +++ b/src/main/java/main/Music.java @@ -19,7 +19,8 @@ public void setFile(URL name){ clip = AudioSystem.getClip(); clip.open(sound); } catch (UnsupportedAudioFileException | IOException | LineUnavailableException e) { - throw new RuntimeException(e); + //TODO: Log the error or notify the user via the UI + throw new RuntimeException(e); // TODO: Replace with more user-friendly error handling } } diff --git a/src/main/java/main/Player.java b/src/main/java/main/Player.java index cd20c21..24ea38a 100644 --- a/src/main/java/main/Player.java +++ b/src/main/java/main/Player.java @@ -4,6 +4,9 @@ * this class handles the player logic */ public class Player { + // TODO: Add Javadoc to explain the purpose of this class and its fields + // TODO: Make fields private and provide getter and setter methods as needed + // TODO: Add input validation in setter methods like prevent negative health GameManager gm; @@ -21,6 +24,7 @@ public Player(GameManager gm) { } public void setPlayerDefaultStatus() { + // TODO: Use constants for default value instead of magic numbers like 'PLAYER_MAX_LIFE = 5' and so on playerMaxLife = 5; playerLife = 2; @@ -31,6 +35,7 @@ public void setPlayerDefaultStatus() { updatePlayerStatus(); } public void updatePlayerStatus() { + // TODO: Add comments to explain each step of updating the player status int i = 0; while (i < 5) { @@ -39,6 +44,7 @@ public void updatePlayerStatus() { } // Set visible only the icons corresponding to playerLife + // TODO: Ensure array bounds are checked when updating UI Labels int lifeCount = playerLife; i = 0; // Reset i to 0 to use for setting life icons while (lifeCount > 0 && i < gm.ui.lifeLabels.length) {