Skip to content

Handling Choices and Dialogue Sections

Thomas edited this page Jul 30, 2023 · 1 revision
  1. Handling Choices and Dialogue Sections Choices and dialogue sections are fundamental components of interactive storytelling. Choices allow players to make decisions that impact the narrative, while dialogue sections present text-based conversations between characters.

In this section, we'll cover how to handle choices and dialogue sections using Audax Engine.

Step 1: Creating a Dialogue Section To create a dialogue section, create a new DialogueSection object. A dialogue section is a segment of a conversation that involves one or more characters speaking.

java Copy code String dialogueSectionId = "first-dialogue-section"; String dialogueText = "This is the first dialogue section."; List speakers = List.of(mainCharacter); // Replace 'mainCharacter' with the appropriate character.

DialogueSectionInformation dialogueSectionInformation = new DialogueSectionInformation(dialogueSectionId, dialogueText, speakers); Step 2: Defining Speeches in a Dialogue Section Inside a dialogue section, you can define the speeches made by the characters involved in the conversation.

java Copy code String characterSpeech = "This is my first line!"; HashMap<String, Character> speeches = new HashMap<>(); speeches.put(characterSpeech, mainCharacter); // Replace 'mainCharacter' with the appropriate character.

List<HashMap<String, Character>> speechesList = List.of(speeches); Step 3: Creating Choices Choices provide players with options to make decisions that affect the story. Each choice can have its dialogue section and consequences.

java Copy code String choiceId = "first-choice"; String choiceHeader = "First choice"; int selectedOptionIndex = 0; // Index of the selected choice option List choiceOptions = List.of("Choice 1", "Choice 2", "Choice 3"); // Replace with appropriate options Countdown countdown = new Countdown(10, () -> { System.out.println("Since you didn't choose a choice, the game will now shutdown."); onEnd(); });

ChoiceInformation choiceInformation = new ChoiceInformation(choiceId); DialogueSection dialogueSection = new DialogueSection(dialogueSectionInformation, choiceOptions, speechesList);

Choice choice = new Choice(choiceInformation, choiceHeader, dialogueSection, selectedOptionIndex, choiceOptions, countdown); Step 4: Handling Player Choice You can implement logic to handle the player's choice and execute the corresponding actions based on the selected option.

java Copy code int selectedOptionIndex = ...; // Get the player's choice option index if (selectedOptionIndex >= 0 && selectedOptionIndex < choiceOptions.size()) { // Execute actions based on the player's choice String selectedOption = choiceOptions.get(selectedOptionIndex); // ... } else { // Handle invalid choice System.out.println("Invalid choice selected."); } With these steps, you have successfully created and managed choices and dialogue sections using Audax Engine. You can now allow players to make decisions and engage in text-based conversations with characters in your interactive story.