Skip to content

Adding Chapters and Episodes

Thomas edited this page Jul 30, 2023 · 1 revision
  1. Adding Chapters and Episodes Chapters and episodes form the backbone of your story's structure. Chapters represent major sections of the story, and episodes represent smaller sub-sections within chapters. Each episode typically corresponds to a specific scene or event in the narrative.

In this section, we'll cover how to create chapters and episodes and integrate them into your story.

Step 1: Create a Chapter Class To create a chapter, create a new class that extends the Chapter class provided by Audax Engine. For example:

java Copy code package me.adversing.story.chapters;

import me.adversing.engine.story.structure.chapter.Chapter; import me.adversing.engine.story.structure.chapter.info.ChapterInformation; import me.adversing.story.chapters.episodes.FirstEpisode;

import java.util.List;

public class FirstChapter extends Chapter {

public FirstChapter() {
    super(new ChapterInformation("chapter-1", "Capitolo 1", "Test"), List.of(new FirstEpisode()));
}

@Override
public void onStart() {
    // Start the first episode when the chapter begins.
    getEpisodes().get(0).onStart();
}

@Override
public void onEnd() {
    // Perform any actions when the chapter ends.
}

} Step 2: Create an Episode Class To create an episode, create a new class that extends the Episode class provided by Audax Engine. For example:

java Copy code package me.adversing.story.chapters.episodes;

import me.adversing.engine.dialogue.section.DialogueSection; import me.adversing.engine.dialogue.section.info.DialogueSectionInformation; import me.adversing.engine.logic.Choice; import me.adversing.engine.logic.info.ChoiceInformation; import me.adversing.engine.obj.entities.character.Character; import me.adversing.engine.story.structure.episode.Episode; import me.adversing.engine.story.structure.episode.info.EpisodeInformation; import me.adversing.engine.utils.time.countdown.Countdown; import me.adversing.story.characters.MainCharacter;

import java.util.ArrayList; import java.util.HashMap; import java.util.List;

public class FirstEpisode extends Episode { public FirstEpisode() { super(new EpisodeInformation("episode-1", "Episode 1", "Test"), new ArrayList<>()); }

@Override
public void onStart() {
    System.out.println("If you see this, I'm working with AudaxEngine!");
    MainCharacter mainCharacter = new MainCharacter();
    System.out.println("Character name: " + mainCharacter.getCharacterInformation().getName());
    System.out.println("Character age: " + mainCharacter.getCharacterInformation().getAge());

    // Create a choice with a dialogue section and choices.
    ChoiceInformation choiceInformation = new ChoiceInformation("first-choice");
    String header = "First choice";
    DialogueSectionInformation dialogueSectionInformation = new DialogueSectionInformation(
            "first-dialogue-section",
            "This is the first dialogue section.",
            List.of(mainCharacter)
    );
    HashMap<String, Character> speeches = new HashMap<>();
    speeches.put("This is my first line!", mainCharacter);
    List<HashMap<String, Character>> speechesList = List.of(speeches);
    DialogueSection dialogueSection = new DialogueSection(dialogueSectionInformation, List.of("Choice 1", "Choice 2", "Choice 3"), speechesList);
    Countdown countdown = new Countdown(10, () -> {
        System.out.println("Since you didn't choose a choice, the game will now shutdown.");
        onEnd();
    });
    Choice choice = new Choice(choiceInformation, header, dialogueSection, dialogueSection.getChoices().size(), dialogueSection.getChoices(), countdown);
    System.out.println("Choice header: " + choice.getHeadTitle());
    System.out.println("Choice dialogue section: " + choice.getDialogueSection());
    System.out.println("Choice dialogue section information: " + choice.getDialogueSection().getInformation());
    System.out.println("Choice dialogue section speeches: " + choice.getDialogueSection().getSpeeches());
    choice.getChoices().forEach(System.out::println);
}

@Override
public void onEnd() {
    System.exit(0);
}

} Step 3: Configure Chapters and Episodes In the chapter's constructor, add the episodes that belong to that chapter using the getEpisodes() method. In the episode's onStart method, you can implement the scene or event associated with that episode.

java Copy code public class FirstChapter extends Chapter {

public FirstChapter() {
    super(new ChapterInformation("chapter-1", "Capitolo 1", "Test"), List.of(new FirstEpisode()));
}

@Override
public void onStart() {
    // Start the first episode when the chapter begins.
    getEpisodes().get(0).onStart();
}

@Override
public void onEnd() {
    // Perform any actions when the chapter ends.
}

} java Copy code public class FirstEpisode extends Episode { public FirstEpisode() { super(new EpisodeInformation("episode-1", "Episode 1", "Test"), new ArrayList<>()); }

@Override
public void onStart() {
    // Your episode's logic goes here.
}

@Override
public void onEnd() {
    // Perform any actions when the episode ends.
}

} Step 4: Starting the Story In the onStart method of your MainStory class, start the first chapter to begin the story.

java Copy code @Override public void onStart() { // Start the first chapter when the story begins. getChapterById("chapter-1").onStart(); } With these steps, you have successfully created chapters and episodes and integrated them into your story. The chapters and episodes will be executed sequentially, following the flow defined in your code.