Ending Cutscenes Test Plan - UQcsse3200/2024-studio-3 GitHub Wiki
Overview
The Fired triggerFiredEnd()
and Raise Ending triggerRaiseEnd()
cutscenes handle the logic for triggering two different cutscenes based on the player's performance in the game. These cutscenes serve as the final outcome of the game, either rewarding the player with a raise or firing them, depending on their success. Both methods use asynchronous execution to manage the timing of events in the cutscenes, ensuring that certain actions happen after specific delays without blocking the main game thread. By using separate threads, the game can continue running while the cutscene plays out in the background, ensuring smooth performance and proper resource management. Both cutscenes share a similar structure but differ in the message delivered to the player, with the game exiting after a total of 30 seconds in either case.
Key Concepts Within the Code
1. ExecutorService:
-
Both methods use
ExecutorService
, specificallyExecutors.newSingleThreadExecutor()
, to manage a separate thread for executing the cutscene logic asynchronously. This allows the cutscenes to play out in the background without interrupting the flow of the rest of the game. -
The
executor.submit()
method is used to submit a task (in this case, a lambda function) that runs the cutscene events.
2. Thread.sleep():
- The flow of each cutscene is managed using
Thread.sleep()
calls to create delays between the steps of the cutscene. This provides a timed sequence for when the boss is introduced, the message is displayed, and the game exits.
3. Entity Spawning:
- In both endings, a boss character is spawned during the cutscene after a 10-second delay using the
spawnBoss()
method. This entity plays a key role in delivering the final message to the player to ensure a winning/losing feature is clearly shown by the end of the game.
4. Game Exit:
- Both cutscenes end by exiting the game after a total delay of 30 seconds (10 seconds before spawning the boss and 20 seconds after displaying the message). The
app.exit()
method is called to gracefully terminate the game.
5. Thread Shutdown:
To avoid leaving dangling threads running after the game exits, the executor.shutdown()
method is called at the end of each cutscene, ensuring that all resources are properly cleaned up.
Testing Objective
- Ensure that both the fired and raise cutscenes are triggered appropriately based on player performance.
- Verify that each cutscene correctly spawns entities, displays text, and exits the game after the appropriate delay.
- Ensure no dangling threads remain after cutscene execution.
Test Scenario: Fired End Cutscene
Objective: Test that the fired cutscene is correctly triggered when player performance fails to meet the gold threshold.
1. Setup Condition:
- Simulate a situation where the player earns less than the winAmount (e.g., 55 gold).
- Ensure game reaches the "end of day" scenario.
2. Test Execution:
- The game should now proceed through the bird screen and moral screen.
- Press "M" after closing the moral screen.
3. Expected Behaviour:
- The fired cutscene should be triggered (
triggerFiredEnd()
). - After 10 seconds, the boss entity should be spawned (
spawnBoss()
). - A text box should appear with the message: "You oink two-legged moron! You're ruining my business' oink reputation! Get out!".
- After another 20 seconds, the game should automatically exit (
app.exit()
).
4. Assertions:
- Ensure that the boss entity is correctly spawned.
- Verify that the text box with the correct message appears on screen.
- Confirm that the game exits after the specified delay of 20 seconds.
- Ensure that no zombie threads remain active after the game exit (
executor.shutdown()
should be correctly called).
Test Scenario: Raise End Cutscene
Objective: Test that the raise cutscene is triggered when the player exceeds the win condition.
1. Setup Condition:
- Simulate a situation where the player earns equal to or more than the winAmount (e.g., 55 or more gold).
- Ensure game reaches the "end of day" scenario.
2. Test Execution:
- After closing the bird screen and moral screen, press "M" to proceed.
3. Expected Behaviour:
- The raise cutscene should be triggered (
triggerRaiseEnd()
). - After 10 seconds, the boss entity should be spawned (
spawnBoss()
). - A text box should appear with the message: "You oink amazing critter! You're a master! Enjoy a 40c raise for your efforts!".
- After another 20 seconds, the game should automatically exit (
app.exit()
).
Test Scenario: Edge Case for Timing
Objective: Test how the system behaves when the timing between cutscene steps is altered.
1. Setup Condition:
- Adjust the
Thread.sleep()
values in the cutscene code to test for different timing scenarios (e.g., shorter or longer delays).
2. Test Execution:
- Trigger the fired and raise cutscenes with modified timing.
3. Expected Behaviour:
- The cutscene should adapt to the new timing without errors.
- The boss should spawn at the correct moment, the text box should appear, and the game should exit after the revised delay.
4. Assertions:
- Ensure that the game remains functional and does not crash or hang due to modified timing.
- Verify that no dangling threads remain and that the game exits cleanly.