PJ01 - Choose Your Own Adventure


In this open-ended project you will implement a text-driven, “choose your own adventure” experience.

Background on Globals and Named Constants

The conceptual purpose of the game is to help you practice the concepts you have learned up to this point and to explore some of the nuances of working with global variables and named constants. Before beginning, please read through and follow along with the lesson on global variables and named constants found here.

Specifications

There are a few requirements to the game you produce:

  1. In your comp110 > projects directory, create a file named cyoa.py for this Choose Your Own Adventure experience.

  2. It should have a main procedure defined that serves as the “entrypoint” to the program. As in the most recent exercise, the call to main should be found at the end of your program and follow Python’s idiom:

Note: We will soon demystify the purpose of this idiom! The short story is when you run your program as you have been so far in the course, there is a special global variable named __name__ that is set to the value "__main__" so the conditional will evaluate to True. Soon we will dicuss the scenario where __name__ is not set to "__main__" (the spoiler is it has to do with importing functions from files).

  1. It should have a procedure named greet that prints 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 from your main procedure.

  2. You should also establish a global variable named points to track “adventure points”. How you choose to use these adventure points is up to you. Initialize your global points variable from within your main function.

  3. After greeting the player, your main function should enter the main game loop. Inside the loop you should present the player with their current points total and then 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 game and print a goodbye message. 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 two directions.

  4. One of the possible directions the player is set off in from main should be a procedure call. It should lead to textual interaction(s) that make use of players name and ask the player for additional input. Somehow the user’s decision should reassign to the global points 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!

  5. One of the other possible directions the player can choose to set off in from main should be a call to a function that takes an integer as a parameter and returns an integer. Rather than accessing and assigning the global points variable, as you did in the previous procedure, the call to this function from main should pass the player’s points value as an argument to the function call. Like the previous procedure, you should make use of the player name 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 main function should use the returned value to update the global variable points.

  6. You should make use of f-strings (formatted string literals) described in the strings lesson to produce any output that would otherwise require concatenation.

  7. You are encouraged to make liberal use of Emoji throughout your adventure and are required to use at least one non-ASCII character in your printed output or prompts. Make use of global NAMED_CONSTANTS that are initialized to escaped unicode strings "\U00000000" for any Emoji you use. Strings such as these can be considered “magic numbers”, too!

  8. At least one path in your adventure must incorporate some element of randomness and the random library.

  9. The “final 5 points” of the project are reserved for going above and beyond these requirements by introducing additional adventuring functions or procedures your player can explore and interact with than just the two required.

Rubric

  • 5 points - main function game loop allows player to both continue playing
  • 5 points - main function game loop exits based on its boolean test condition becoming false (see 8-Ball example)
  • 10 Points - player and score global variables correctly declared
  • 10 Points - greet function 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 conventionally named constant for it
  • 5 Points - Used f-strings for building string outputs
  • 5 Points - Incorporated randomness
  • 5 Points - Went above and beyond per specification #10
  • 15 Points - Static Type Check
  • 15 Points - Linting

Ideas

If you’re not feeling particularly creative here are a few possible ideas on adventure paths:

  1. 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.
  2. 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.
  3. 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.
  4. A “buzzfeed quiz” that determines what character from Hamilton you are (or anything else).
  5. A coinflip guessing game where you have to choose heads or tails and see how many you can guess in a row correctly.
  6. Some kind of mystery that involves searching a sequence of rooms.
  7. Something heavily emoji based, perhaps as surprising as a Japanese Game Show
  8. A parody of something that is poignant satire (a student once made a ConnectCarolina registration parody that was golden)

Hopefully some of these ideas may spark ones of your own! Two straightforward games to implement would be numbers 3 and 5 above, but they’re not particularly creative. That’s totally ok, but it’s more fun to see your own ideas come to life!

Submission Instructions

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.

If you are attempting the final 5% of the project, describe what to look for in your program per the instructions above in your top-level docstring. Remember, between the """’s docstrings can span multiple lines.

Run python -m tools.submission comp110/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.