100 Days of Code: Day 3 - Cyber-Security-Breach Maze Game
Challenge: 100 Days of Code with Python
Day: 3
Introduction
Welcome to Day 3 of my 100 Days of Code challenge with Python! Today, I created an interactive and fun project: a Cyber-Security-Breach Maze Game. This text-based game challenges players to navigate through a server room maze to find a breached server while avoiding traps and obstacles. It's a great way to practice control flow and user input handling in Python.
Project: Cyber-Security-Breach Maze Game
The Cyber-Security-Breach Maze Game presents players with a series of choices that determine their path through a server room maze. Players must make the right decisions to find the breached server and win the game.
The Code
Here is the Python code for the Cyber-Security-Breach Maze Game:
print("Welcome to JB Corp.")
print("Your mission is to find the breach.")
# Maze art
maze = """
_________________________________________________________
| |
| ___ ___ ___ | ___ ___ ___ | |
| | | | | | | | | | | | | | | |
| | S |---| |---| |---|---| |--| |---| E | | |
| |___| | | |___| | |___| |___| |___| | |
| |
| ___ ___ ___ | ___ ___ ___ | |
| | | | | | | | | | | | | | | |
|---| E |---| |---| S |---|---| |--| |---| |---| |
| |___| | | |___| | |___| |___| |___| | |
| |
| ___ ___ ___ | ___ ___ ___ | |
| | | | | | | | | | | | | | | |
|---| S |---| |---| E |---|---| |--| |---| S |---| |
| |___| | | |___| | |___| |___| |___| | |
| |
|_________________________________________________________|
"""
print(maze)
# Story and choices
choice1 = input('You\'re in the server room. Where do you want to go? Type "left" or "right" \n').lower()
if choice1 == "left":
choice2 = input('You\'ve come to a server 404. There is a blinking light. Type "wait" to wait for it to turn green. Type "skip" to skip to next section. \n').lower()
if choice2 == "wait":
choice3 = input("You see three servers with blinking lights. One red, one yellow and one blue. Which colour do you choose? \n").lower()
if choice3 == "red":
print("It's a server full of malware. Game Over.")
elif choice3 == "yellow":
print("You found the breached server! You Win!")
elif choice3 == "blue":
print("This server is heavily encrypted. Game Over.")
else:
print("You chose a server that doesn't exist. Game Over.")
else:
print("You get detected by the security system. Game Over.")
else:
print("You fell into a trap. Game Over.")
Key Functions Explained
1. Maze Art
The game starts with a visual representation of the maze using ASCII art. This adds a visual element to the text-based game, making it more engaging for the player.
maze = """
_________________________________________________________
| |
| ___ ___ ___ | ___ ___ ___ | |
| | | | | | | | | | | | | | | |
| | S |---| |---| |---|---| |--| |---| E | | |
| |___| | | |___| | |___| |___| |___| | |
| |
| ___ ___ ___ | ___ ___ ___ | |
| | | | | | | | | | | | | | | |
|---| E |---| |---| S |---|---| |--| |---| |---| |
| |___| | | |___| | |___| |___| |___| | |
| |
| ___ ___ ___ | ___ ___ ___ | |
| | | | | | | | | | | | | | | |
|---| S |---| |---| E |---|---| |--| |---| S |---| |
| |___| | | |___| | |___| |___| |___| | |
| |
|_________________________________________________________|
"""
print(maze)
2. User Choices and Input Handling
The game uses a series of input
functions to get the player's choices. Each choice leads to a different outcome, and the game logic is implemented using if
and else
statements.
choice1 = input('You\'re in the server room. Where do you want to go? Type "left" or "right" \n').lower()
if choice1 == "left":
choice2 = input('You\'ve come to a server 404. There is a blinking light. Type "wait" to wait for it to turn green. Type "skip" to skip to next section. \n').lower()
if choice2 == "wait":
choice3 = input("You see three servers with blinking lights. One red, one yellow and one blue. Which colour do you choose? \n").lower()
if choice3 == "red":
print("It's a server full of malware. Game Over.")
elif choice3 == "yellow":
print("You found the breached server! You Win!")
elif choice3 == "blue":
print("This server is heavily encrypted. Game Over.")
else:
print("You chose a server that doesn't exist. Game Over.")
else:
print("You get detected by the security system. Game Over.")
else:
print("You fell into a trap. Game Over.")
Example
Let's say the player makes the following choices:
choice1
: leftchoice2
: waitchoice3
: yellow
The program will output:
You found the breached server! You Win!
Conclusion
This Cyber-Security-Breach Maze Game project was a great way to practice control flow and user input handling in Python. It also allowed me to incorporate some fun elements like ASCII art and interactive storytelling. I hope you enjoy playing the game as much as I enjoyed creating it. Stay tuned for more exciting projects in the upcoming days!
Stay Connected
Follow my progress and join me on this coding journey:
Happy coding!