In this chapter, we use branching to write a choose-your-own-adventure game that asks for user input at key moments to change the story.
Any good story needs a plot. The plot is the outline of events that happen over the course of the story. When writing a story where the user’s input influences the plot, the writer needs to pay close attention to managing the different plot lines. Each plot line has the same beginning, but the middle and ending are different based on input from the user.
Considering all of the different options — and planning for each possibility — in a branching program is a valuable skill to have as a programmer.
We’ll begin by creating a simple story that poses a question. This creates two branches. Each of these branches will have a question that creates two more branches. Eventually, every choice will lead back to one of two possible endings.
A useful tool for visualizing branches of a story ...