-
Notifications
You must be signed in to change notification settings - Fork 1
Dialogue Box Programming Guide
The Dialogue Box is a sophisticated feature, involving multiple assets that must be dynamically updated to maintain a visually appealing experience. To manage this complexity, the Dialogue Box follows the Facade design pattern in conjunction with the Dialogue Box Service. While it's highly recommended to use this service for efficient interaction, this guide will also outline how to use the Dialogue Box independently.
The initialisation of a dialogue box has been overloaded to serve multiple purposes. This method initialises the dialogue box to be hidden but loads all the appropriate assets onto the specified stage.
DialogueBox dialogueBox = new DialogueBox(stage);
This initialisation with labelText
as a String[][]
:
public DialogueBox(labelText)
Initialises the dialogue box to show immediately with the given text.
In order to resize the assets to fit the screen, a method has been provided to dynamically adjust the elements:
public void resizeElements()
This is done automatically for dialogue boxes on the main screen through the DialogueBoxService
; however, it may be useful to call this method if the dialogue box is added to additional game screens.
The minigameCheck()
method processes specific flags within the dialogue text to trigger mini-games. Below is a table outlining the flags and their respective mini-games:
Flag | Mini-Game Triggered | Description |
---|---|---|
/ms |
Snake | Launches the Snake mini-game |
/mb |
Birdie Dash | Launches the Birdie Dash mini-game |
/mu |
Underwater Maze | Launches the Underwater Maze mini-game |
This example shows how to trigger a mini-game using the /ms
flag for Snake.
// Example dialogue triggering the Snake mini-game
String[][] dialogueText = {
{"/msYou are about to start the Snake mini-game!"}
};
DialogueBox dialogueBox = new DialogueBox(dialogueText);
dialogueBox.showDialogueBox(dialogueText);
In this case, the /ms
flag is used to trigger the Snake mini-game. The player sees the message "You are about to start the Snake mini-game!" and can launch the game by clicking the play button.
The optionsCheck()
method checks for options in the dialogue text that allow the player to make choices. Below is a table outlining the flags and their purposes:
Flag | Function | Description |
---|---|---|
/c |
Start Options | Indicates that the dialogue contains options |
/s00 |
Option Navigation | Player can select this option (index 0) |
/s01 |
Option Navigation | Player can select this option (index 1) |
This example demonstrates a dialogue with player options using the /c
flag.
// Example dialogue with player options
String[][] dialogueText = {
{"/cYou see two paths. Which do you take?/s00Left Path/s01Right Path"}
};
DialogueBox dialogueBox = new DialogueBox(dialogueText);
dialogueBox.showDialogueBox(dialogueText);
Here, the /c
flag indicates the presence of options. The player sees "You see two paths. Which do you take?" along with two buttons to choose "Left Path" or "Right Path."
The Left and Right arrow keys are used for navigation and are set up through the Input Factory. For more details on how these controls are implemented, refer to the UML diagram below.
The UML diagram below illustrates the relevant dependencies for the Dialogue Box. It includes the Dialogue Box Service to help determine whether using the service is suitable for your implementation.
Since the Dialogue Box was specifically designed to work in parallel with the Dialogue Box Service, they are tested together. These unit tests provide over 80% coverage of the Dialogue Box class, ensuring its reliability. It's important to maintain this level of coverage. You can refer to the testing guide for more details.