Your job is to make a “Choose your own adventure” story, using Python and functions. Start by planning out your story with a Google Drawing or some other tool. Each ‘node’ of your story should have choices for the user, unless it an ending to the story. The story should be inside boxes, with choices as arrows.
Each box or ‘page’ will be a function in your program.
If you are going to use a global variable or two, indicate on the diagram how you will use them! Some examples of global variables you could use are objects (like “key” or “water”), hunger (you could use a number), hit_points, or a piece of knowledge (password).
Turn in your plan either as a google drawing or as a picture or pdf, if you used some other way of mapping the story.
Write your adventure story! You should have at least ten functions representing ‘pages’ in your story. At least seven of them should have a choice for the user (input). Bonus points for:
Fun use of a global variable or two
Appropriate use of randomness
Non-linear story (maybe use a parameter or global variable to modify a ‘page’)
Something else? Have the user solve a puzzle by exploring your story. You can be super creative if you focus on designing the story first, then on writing code to implement your vision!
Save your final story as story.py. If you make more than one version, save them as story1.py, story2.py, etc.
Follow these instructions to make your story program.
You’re going to make an adventure story, but first just make the beginning. Make a single function, start( ), that begins your story. Here is the start() function from my story. What happens if the user types “7”?
Then run the program. Every time you add a new function, run the program. Of course, when you run this program, it will crash. But it will crash only when it reaches a function we haven’t written yet.
Write Another Function
Next write one more function. I’d write sneak(). Then I’d run it again. You can see how useful the story map is now.
Once you get the hang of it, you’ll have a great story before you know it.
Global Variable (Optional – read this when you need to.)
In general, if you make or change a variable in a function, those changes are NOT global. Consider the following:
At first glance, it looks like running found_key() should make the value of key True for the whole program, but it does not. The change of key to True in found_key() is a local change. In fact, the key variable in the found_key( ) function is not the same variable as the key variable initially set to False. Try adding a line at the beginning of the found_key() function, like this:
Now the key variable in found_key( ) is the same one used elsewhere.
If you have a lot of player data in your story, try using a dictionary to keep in all in one place.