In the first open-ended programming project, you will create a text-driven, “Choose Your Own Adventure” experience.
Your project will need to satisfy many specifications, so before you begin programming be sure to read this project’s write-up in full.
You are free to use your imagination to design and implement any experience you would like, as long as it meets the requirements. For some inspiration, here are some example ideas the UTA team and I came up with, if you are not feeling the spark of creativity:
- Taking care of a virtual pet like a tamagotchi. You are free to introduce additional variables, global or otherwise, for keeping track of a pet’s health.
- Some kind of role playing game where you choose what kinds of attacks or defenses to use and the opposing creature randomly chooses theirs. Points could be health or damage inflicted.
- A number guessing game such as the generating a random number and asking the user to guess it and counting the number of attempts it takes them to guess it correctly.
- A “buzzfeed quiz” that determines which Disney Princess character are (or anything else).
- A coinflip guessing game where you have to choose heads or tails and see how many you can guess in a row correctly.
- Some kind of mystery that involves searching a sequence of rooms.
- Something heavily emoji based, perhaps as surprising as a Japanese Game Show
- A parody of something that is poignant satire (a student once made a ConnectCarolina registration parody that was pure, comedic gold)
Again, feel encouraged to come up with an idea that is uniquely your own!
The conceptual purpose of the game is to help you practice the concepts you have learned up to this point and explore some additional, related topics, including:
- String Escape Sequences (for Emoji!)
- String Interpolation (better than concatenation!)
- Named Constants
- Global Variables
As background preparation for this project, you should first complete the following lessons:
These are the requirements for your project. Please read them in full and have a rough plan for how you will satisfy them all, before you begin working on your project:
It must have a
mainfunction, that returns
None, and follows the Python idiom for calling
mainat the end of the program based on the dunderscore variable
__name__being equal to
It should have a procedure, meaning a function that returns
greetfunction must print a welcome message to give some context to your game and asks the player for their name. The name given should be assigned to the global variable named
player. You should call this procedure at the beginning of your
You should also establish a global variable named
pointsto track “adventure points”. How you choose to use these adventure points is up to you. Initialize your global
pointsvariable from within your
After greeting the player, your
mainfunction should enter your experience. You should present the player with at least three options of where to go next and ask them to choose one. One of the three options should be to end the experience and print a goodbye message that includes the number of “adventure points” they accumulated in the experience. The other options should result in function calls which set the user off in different directions on the adventure. You will need to define appropriate functions for these distinct paths.
One of the possible directions the player is set off in from
mainmust be a procedure call. It should lead to textual interaction(s) that make use of players name and ask the player for additional
input. The user’s decision should reassign the
pointsglobal variable directly. At a minimum, increase the adventure’s points each time the player makes a choice. What happens within this procedure is up to you and you are free for this procedure call to lead to others, make use of loops, and so on. Get creative!
One of the other possible directions the player can choose to set off in from
mainshould be a call to a function that takes an integer as a parameter and returns an integer. Rather than accessing and assigning the global
pointsvariable, as you did in the previous procedure, the call to this function from
mainshould pass the player’s
pointsvalue as an argument to the function call. Like the previous procedure, you should make use of the
playername in some output and have the user make at least one interaction choice that results in the points parameter (local variable) changing. Ultimately, this function should return the player’s total points after any interactions it leads to. Finally, the
mainfunction should use the returned value to update the global variable
Note: Requirements 4 and 5 are intentionally asking you to implement the same kinds of behavior but using two very different strategies in code for achieving them. The strategy in #4 relies on global variables shared between the main procedure and the function(s) you write. The strategy in #5 avoids the function(s) from directly accessing or reassigning the
pointsglobal variable. There are trade-offs to each strategy. It is valuable to think through the trade-offs of both!
You must make use of f-strings (formatted string literals) described in the strings lesson to produce any output that would otherwise require concatenation. No concatenation in this project!
You are encouraged to make liberal use of Emoji throughout your adventure and required to use at least one Unicode character in your printed output or prompts. You must define at least one global
NAMED_CONSTANTand assign it the unicode escape sequence
"\U00000000"for each Emoji you use. Strings such as these are considered “magic numbers”, too!
At least one path in your adventure must incorporate some element of randomness from the
5 points of “above and beyond” are reserved for introducing a “game loop” in your
mainfunction. The game loop should allow the user to continue your experience and choose the same initial branch, or another branch, or to stop playing. Before looping, each time, you should update the user on their total number of points. We will cover loops on Tuesday 2/23.
5 points of “above and beyond” are reserved for going above and beyond these requirements by introducing additional adventuring functions or procedures your player can explore and interact with beyond the two required.
If you are attempting either or both of the “above and beyond” points, please describe what we should look for in your program per the instructions above in your top-level docstring. Remember, between the
"""’s docstrings can span multiple lines.
In your workspace’s
projects directory, create a file named
cyoa.py for this Choose Your Own Adventure experience.
Begin by defining a
main procedure that serves as the “entrypoint” to the program. The initial call to
main should be found at the end of your program, following Python’s idiom:
if __name__ == "__main__": main()
- 15 Points - Static Type Checks
- 15 Points - Linting
- 5 points -
mainfunction allows user to choose one of three options
- 10 Points -
pointsglobal variables correctly declared
- 10 Points -
greetfunction meets specification #2 above
- 10 Points - Procedure meeting specification #5 above
- 10 Points - Function meeting specification #6 above
- 5 Points - Used at least one emoji and setup a named constant for it
- 5 Points - Used f-strings for building string outputs rather than concatenation
- 5 Points - Incorporated randomness
- 5 Points - Went above and beyond per specification #9
- 5 Points - Went above and beyond per specification #10
To prepare your scene for submission, be sure to add a docstring to your module (at the top of the file) and a global
__author__ variable set to a string which contains your 9-digit PID. Linting will also look for docstrings in your function definitions, per usual. 45 points of this assignment will be autograded, and the remaining 55 hand-granded.
python -m tools.submission projects/cyoa.py to build your submission zip for upload to Gradescope. Don’t forget to backup your work by creating a commit and pushing it to GitHub. For a reminder of this process, see the previous exercises.