GITHUB REPO | FOLLOW ME ON -> TWITTER | LINKEDIN
Secret Tunnel Game — A Python Project for Fun and Learning
The Secret Tunnel game is a fun project developed with the Python programming language that challenges players to navigate a tunnel without dying. In this game, the player must make a set of decisions that decide whether or not they win. Let’s dive deeper into the game’s code and explore its features.
Step-by-step code explanation
The first thing we need to do is set up our Python Secret Tunnel Game. Open up your preferred code editor, create a new file, and save it with a descriptive name such as “secret_tunnel.py.
”
The code begins with a print statement that shows the game’s title in ASCII visuals. It then welcomes the gamer and informs them of their objective.
print(''' _ _
| | | |
| |_ _ _ _ __ _ __ ___| |
| __| | | | '_ \| '_ \ / _ \ |
| |_| |_| | | | | | | | __/ |
\__|\__,_|_| |_|_| |_|\___|_|''')
print("\nWelcome To The Secret Tunnel Game!")
print("\nYour mission is to pass the tunnel without losing your life.")
The game gives the player three options to pick from: left, middle, or right. If the player selects the Left option, they will go to the next level, where they will find a matchbox on the floor. Here, the player must choose whether to light the match or wait.
print("There are three ways in front of you?")
first_option = input('In which way you wanna go? "Left", "Mid" or "Right"?\n').lower()
if first_option == 'left':
print("\nNice! You made it to the next level.")
print("There are no light inside the tunnel, but you can see that a matchbox is on the floor.")
second_option = input('Type "light" to light the match or type "wait" if you want to wait for some time.\n').lower()
If the player chooses to wait, they will come across three different coloured doors: red, blue, and green. To progress, the player must select one of the doors. They will fall into a hole and lose the game if they select Red or Green. If they select Blue, they will successfully cross through the tunnel and win the game.
if second_option == 'wait':
print("\nAfter waiting sometime, \out of nowhere you are seeing doors with three different colors in front of you.")
third_option = input('Which door you wanna go? "Red", "Blue" or "Green"\n').lower()
if third_option == "red" or third_option == "green":
print("You fall into a hole.")
print("OOPS! You DIED!! Game over!!!")
elif third_option == "blue":
print("You successfully passed the tunnel!")
print("CONGRATULATIONS! YOU WIN!!")
else:
print("Wrong selection.")
print("OOPS! You DIED!! Game over!!!")
If the player decides to light the match, they will die due to the gas contained within the tunnel. Similarly, if the player chooses Mid or Right, they lose the game.
else: (# second_option!="wait")
print("There were gas inside the tunnel, when you light the mactch it blasts.")
print("You DIED!! Game over!!!")
else: (# first_option!="left")
print("OOPS! You DIED!! Game over!!!")
Here is the full code.
Test Run
Features
Program’s Features
- The game challenges the player’s decision-making skills and offers multiple paths to the end.
- The game provides an engaging user interface through print statements and ASCII art.
Python Concepts and Techniques Used
- Basic ASCII art printing
- User input and output using
input()
andprint()
function - Lower user input using
lower()
function - Nested
if/else
conditional statements
Finally, the Secret Tunnel game is an enjoyable project that allows beginner Python programmers to exercise their abilities. It makes use of basic programming concepts including conditional statements, input/output, and string manipulation. Beginners can improve their decision-making and problem-solving abilities by participating in this project.
This article is a part of my Python Project Journal. Please have a visit to my journal. Thank you!