Issue
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):
self.scene_start()
def scene_b(self):
print_part(chapter.part_B)
choice = prompt.options('Choose 1, 2 or 3', chapter.B_options)
if choice == '1':
self.scene_c()
elif choice == '2':
self.scene_d()
elif choice == '3':
self.scene_e()
def scene_c(self):
print_part(chapter.part_C)
choice = prompt.options('Choose 1 or 2', chapter.C_options)
if choice == '1':
self.scene_f()
elif choice == '2':
self.scene_g()
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?
Solution
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.