[SOLVED] Mapping story flow in a choose your own adventure game


This Content is from Stack Overflow. Question asked by Julio Arellano

I’ve been writing my own ‘choose your own adventure’ game. This is an example of how I did the intro class:

from Text import introText as chapter
from clint.textui import prompt

class Introduction:

  def __init__(self):

  def scene_b(self):
    choice = prompt.options('Choose 1, 2 or 3', chapter.B_options)
    if choice == '1':
    elif choice == '2':
    elif choice == '3':

  def scene_c(self):
    choice = prompt.options('Choose 1 or 2', chapter.C_options)
    if choice == '1':
    elif choice == '2':

It works, but as a I finished the intro I realized I have 5 chapters, each over 8 ‘parts’. I don’t want to add more classes and hard-code the scenes, ideas on how I would have 1 or 2 classes that would run the choices (maybe following a json) for the whole game?


Your comment about running choices in JSON would be the best approach. That way you could write a function that essentially just grabs the scene that you want to return to the player. You could nest specific choices in the same way your leaves of the story cascade down.

This Question was asked in StackOverflow by Julio Arellano and Answered by Brady R It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?