Text Adventure¶
Alright ya'll gather around the campfire, gramps will tell you about text adventure games... The dominion of text adventure games probably ended like 40 years ago but dialogue in modern games still more or less follows the same patterns. In this project we'll take a small look into how one would go through branching dialogue in a terminal program.
Program Flow¶
The program allows the player to go through one scene where dialogue progresses in text boxes, and includes branches where the player can make a choice.
- The program prints a text snippet
- If there are no options for the player to choose from, they simply press enter and this process starts from the beginning with the next snippet
- If there are choices, they are presented to the player as numbered options
- The player makes their choice by inputting the corresponding number, and the program fetches the corresponding branch from the dialogue tree
- Start this process from the beginning with the first snippet from the branch corresponding to the choice
- If the snippet indicates a new branch to go to, the program fetches the first snippet from that branch, and this process is started from the beginning
- If there are no choices or next branch, and there are no further snippets in the current branch, the conversation ends
Conversation Tree¶
Coming up with a suitable data structure for storing a branching conversation is regarded part of this task. The diagram below visualizes what kinds of conversations should be possible to present with the data structure. Each box is a text snippet shown to the player; each black dot denotes the start of a branch; and an empty circle denotes end of conversation.
Data Management¶
In a minimal implementation the program can only display one conversation that is hard-coded into its code. In a more useful implementation conversations are loaded from data files, and the user can choose which file to load by using command line arguments. This project does not involve saving data, only loading. The json module is highly recommend for handling files.