Choose Your Own Adventure Game | Python

PLAY THE GAME HERE

The project I tackled next is a ‘choose your own adventure’ game. When opened via the terminal, you are greeted with a welcome message and the ability to choose between two doors. One of the doors successfully brings you to the next prompt, while the other traps you in. For this quick project, there are only three levels. However, it is built to easily be expanded further and I may do so in the future.

The main topic covered in preparation for this project was control flow. The code itself is just a series of nested if/elif/else statements that prints one of two messages to the console depending on the input of the user. Although the logic is simple, I did use diagrams.net to create a flow chart for even easier reference to the proper logic flow.

I also incorporated themed ASCII art in a print statement above each prompt or ‘Game Over’ notice for a little flair. Here is a walk through of level one’s code. Be warned that there will be spoilers as to the correct choice for this level. So, if you intend on trying the game out, I would do so before reading further.

First, the terminal prints ASCII art of two doors and asks the user to select which door to enter. The user’s choice is stored in the 'level_one_choice' variable. Next, an ‘if’ statement compares the user’s input against the hardcoded ‘2’, which is the correct choice. As long as the player has chosen door two, they will be brought to the next prompt for level two, where again a nested ‘if’ statement compares the user’s choice against the hardcoded correct answer. This process repeats once more for level three, where choosing the correct answer prints that you have escaped successfully and all others print a different loss message based on the selection.

This was a very fun project to make and admittedly, I did struggle a bit to get the ASCII art to display correctly in the terminal window. But, persistence is key and I ended up with a project that I am happy to put my stamp of approval on!


You can view and download the source code for this project on my GitHub by clicking here. I have also included a GIF of the gameplay, in the documentation if you are interested in seeing what that looks like without downloading the file and running it locally.

Thank you for your time!

Previous
Previous

Rock-Paper-Scissors Game | Python

Next
Next

Tip Calculator | Python