Story Lab [extended] #
In this lab, you are introduced to the structure for writing a branching story. You will use this in your unit project.

[0] Setup #
๐ป Start by going into your
unit02_games
folder.
cd ~/desktop/making_with_code/unit02_games
๐ป Clone your starter code.
Be sure to change YOUR-GITHUB-USERNAME
to your actual Github username.
git clone https://github.com/the-isf-academy/lab_story_extended_YOUR-GITHUB-USERNAME
cd lab_story_extended_YOUR-GITHUB-USERNAME
poetry shell
poetry install
This repo includes the following files:
game.py
story_setup.py
view.py
model_node.py
model_story.py
[1] How do you write a story? #
Stories are made up of connected connected Node()
objects.
Node #
Let’s start by looking at the Node
class:
classDiagram class Node { +id: str +option_title: str +description: str +children: [] Node +Node(id, option_title, description) +__ str __(): str +__ repr __(): str +add_child(Node) +find(id): Node }
A few things to take note of:
- The
Node()
method is to describe how to create a Node - it requires 3 arguements __str__()
: defines how aNode
is printed__repr__()
: defines how aNode
is represented (this will help with debugging)add_child(child_node)
: this apendschild_node
to itschildren
- this is how the story pieces are connected to each other.
find(id)
- searches through the Nodes to return the Node with theid
Story #
Now, let’s look at the Story()
class. This is the primary class you will be interacting with when writing your story.
classDiagram class Story { +title: str +first_node: Node +current_node: Node +Story(title, first_id,first_option_title, first_description) +get_current_node(): Node +get_current_children(self): [] Node +chosen_node(current_node) +add_new_children(parent_id, child_title, child_option_title, child_description) +is_running(): Boolean }
A few things to take note of:
first_node
- is a Node created from the arguements when a Story is createdcurrent_nodde
- when a Story is created, holdsfirst_note
- this changes as the Story progressesadd_new_children()
is used to to add new paths to your story
Setting up a Story #
๐ Let’s start taking a look at story_setup.py
As you can see, the current story has only has 4 unique Node()
objects and it calls .add_new_child()
to build the story.
[3] Implementing the Game Loop #
Now that we have a simple story, let’s create the game loop so a user can play through it.
๐ป
Implement the game loop flow chart in game.py
so it properly plays through the story.

๐ง Consider…:
- Try testing the classes before you implement the game
- What methods exist in the
View()
andStory()
that you should use? - How do you loop until a condition is met?
๐พ Be sure to play test the game to ensure it works as expected: python game.py
Continue the Story #
Now that you’ve gotten a working game.py
, let’s build out the story.
Come up with your own options to continue the story! We’ll share out at the end of class.
๐ป
Continue the story, add at least 3 unique Node()
objects. Some ideas…
- add additional lunch options in ISF A Block Cafeteria
- add options at the basketball court
- add other places to go for recess
๐พ Be sure to play test the game to ensure your story additions work as expected: python game.py
[3] Deliverables #
โกโจOnce you’ve successfully completed the game be sure to fill out this Google form.
๐ป Push your work to Github:
- git status
- git add -A
- git status
- git commit -m “describe your drawing and your process here”
be sure to customize this message, do not copy and paste this line
- git push
[4] Extensions #
For your project, you will need to build out one additional feature to this Story
framework. Here are a few suggested features:
- looping stories with the ability to set an Node as a existing Node’s child
- e.g. player can go back to a previous area
- a
Player
class with unique properties- e.g. hunger, money, health
- variable messaging in the story
- e.g.
"you have visited this store 5 times"
- e.g.
- a special
Node
child-class that gives items or status effects- e.g. a locked door where you need to first collect the key in a certain room.
๐ป Use this time to experiment with of these features! If you have your own ideas, feel free to experiment with that!