Making with Code

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 into the lab
cd lab_story_extended_YOUR-GITHUB-USERNAME
๐Ÿ’ป Enter the Poetry shell and install the requirements:
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 a Node is printed
  • __repr__(): defines how a Node is represented (this will help with debugging)
  • add_child(child_node): this apends child_node to its children
    • this is how the story pieces are connected to each other.
  • find(id) - searches through the Nodes to return the Node with the id

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 created
  • current_nodde - when a Story is created, holds first_note - this changes as the Story progresses
  • add_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() and Story() 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"
  • 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!