Skip to content

Chapter 5: Building Your Final Project

📖 Story Time

Last summer, I spent three whole days building the most epic, towering cardboard castle in my living room. I carefully measured the walls with a ruler, cut out little square windows, and used an entire roll of duct tape to make a drawbridge that actually went up and down. I thought I was done, but honestly? It wasn’t truly fun until my friends finally came over, crawled inside, and we started playing knights and dragons.

Today, you are at that exact same moment in your coding journey! You’ve learned the rules. You’ve practiced the commands. Now, you’ve reached the final step, and we aren’t just going to practice anymore—we are going to build a complete, interactive, playable text-adventure game called “The Dungeon Run.” And the best part is that you can invite your friends and family to play it when you are done!

So far, you’ve gathered all the ultimate tools for your coding inventory. Let’s look in your backpack to see what you’ve collected:

  • Sequences: You know how to put steps in the right order. (Remember: You can’t put on your shoes before your socks!)
  • Variables: You know how to create digital boxes that store information (like keeping track of your Health, your Name, and your Score).
  • Conditionals: You know how to teach the computer to make decisions using if, elif, and else statements.
  • Loops: You know how to make actions repeat automatically using for and while loops, so you don’t have to type the same code a million times.

These four tools are the exact same digital bricks used by professional game developers to build massive worlds like Minecraft, Roblox, and Fortnite. Let’s put them together!

Before placing the first block of a mega-build in Minecraft, you usually have an idea in your head—maybe a sky castle or a secret underwater base. If you just start randomly clicking, you usually end up with a messy dirt hut!

Programming is exactly the same. We need a plan. Professional coders call this a “Blueprint” or “ : .” It’s a way to write out the game’s rules in plain English before we translate them into Python.

The Game Plan:

  • Start: The player starts the game with 3 Hearts and 0 pieces of Gold.
  • The Loop: As long as the player still has hearts left, they keep walking deeper into the dark dungeon.
  • The Event: A monster suddenly appears to block the path!
  • The Choice: The game asks the player what they want to do. They get to type “fight” or “run.”
  • The Result: The computer uses a conditional (if/else) to decide what happens next. They either get loot and take damage, or escape safely but stay broke.

Phase 2: The “Input” Command (Talking to the Computer)

Section titled “Phase 2: The “Input” Command (Talking to the Computer)”

If we want the player to make a choice, we need a way for them to talk to the game. Up until now, our code has just talked to us using the print() command. Now, we are going to talk back.

We use a magical command called <VocabHover def="A command that pauses the program to let the user type an answer or make a choice.">input</VocabHover>(). It pauses the entire program, puts a blinking cursor on the screen, and waits for you to type something and hit Enter.

Real World Check-In: Think about the speaker at a fast-food drive-thru. The cashier says, “What would you like to order?” and then they completely pause. They wait in silence for you to answer before they push any buttons on their register. If you take five minutes to decide, they wait five minutes! That’s exactly how input() works in Python.

Try this simple test in your Python editor to see it in action:

name = input("What is your name, hero? ")
print("Welcome to the dungeon, " + name + "!")

When you run this, the computer stops and waits. If you type “Steve” and hit Enter, it saves “Steve” into the name variable, and then uses it in the next line to reply “Welcome to the dungeon, Steve!” It’s like playing a game of digital Mad Libs!

<CodingActivity title=“Build Your Text Adventure”> Let’s build the game step-by-step. Open a fresh, blank file in your Python editor and type along!

Step 1: Setting the Stats (Variables) First, we set up our character’s backpack, health, and welcome message. We will also ask the player for their name to make it personal!

print("--- THE DUNGEON RUN ---")
player_name = input("Enter your character's name: ")
print("Loading World for " + player_name + "...")
hearts = 3
gold = 0

Step 2: The Game Loop We want the game to keep going while we are still alive. This is where our trusty while loop comes in. As long as our hearts are greater than zero, the game keeps tossing monsters at us!

while hearts > 0:
# str() turns our numbers into text so we can print them in a sentence!
print("You have " + str(hearts) + " hearts and " + str(gold) + " gold.")
print("A wild, drooling Zombie appears!")
# We ask the player what they want to do and save it in the 'choice' variable!
choice = input("Do you want to 'fight' or 'run'? ")

Step 3: Making the Decision (Conditionals) Now we check what the player typed using if and elif. Add this code inside your loop. (Super Important: Make sure all of these lines are indented with the Tab key so the computer knows they belong inside the loop!) We are also going to add a secret hidden choice called “dance” just for fun!

if choice == "fight":
print("You swing your sword! You defeated the Zombie and found 2 gold!")
print("Ouch! The Zombie scratched you.")
gold = gold + 2
hearts = hearts - 1
elif choice == "run":
print("You ran away safely like a coward, but you got no gold.")
elif choice == "dance":
print("You do a silly dance. The Zombie is confused and gives you 1 gold!")
gold = gold + 1
else:
print("I don't understand that command! You stood still and the Zombie hit you!")
hearts = hearts - 1

Step 4: Game Over Finally, if the loop finishes (because the hearts variable finally reached 0), we tell the player the game is over. We will also use one final if statement to give them a different ending depending on how much gold they collected. Un-indent this part so it touches the left side of the screen. This makes sure it only happens after the loop is completely done.

print("--- GAME OVER ---")
print("You survived with " + str(gold) + " gold pieces!")
if gold >= 5:
print("You collected enough gold to buy a diamond sword! YOU WIN!")
else:
print("You didn't collect enough gold. Better luck next time!")

</CodingActivity>

Every coder makes mistakes. Even the people who built Roblox make mistakes every single day!

Real World Check-In: Imagine you are riding your bike down a hill, and suddenly the pedals just spin without moving the wheels. You don’t throw the whole bike in the trash! You just hop off, find the spot where the chain slipped off the gears, and pop it back on. <VocabHover def=“The process of finding and fixing errors (bugs) in your code to make it run correctly.”>Debugging</VocabHover> is just fixing the bike chain of your code.

The “Rubber Duck” Debugging Trick: Professional programmers actually use a trick called “Rubber Duck Debugging.” They keep a little yellow rubber duck on their desk. When their code breaks, they explain their code out loud, line-by-line, to the toy duck. Usually, by slowing down and reading it out loud, they hear their own mistake! Try it with a toy or pet at your house!

Common Bugs to Watch For:

  • IndentationError: Did you forget to press “Tab” inside your while loop or your if statement?
  • NameError: Did you name a variable gold but try to print Gold (with a capital G)? Python is completely case-sensitive, so it thinks those are two totally different words!
  • SyntaxError: Did you forget the colon : at the end of a while or if line? Did you forget to put quote marks "" around your words?

Now that the code works perfectly, you can “mod” it and make it entirely your own! This is where you get to be the Game Director.

  • Change the Theme: Change “Zombie” to “Creeper,” “Alien,” or “Evil Robot.”
  • Change the Loot: Change the gold reward to diamonds, robux, or pizza slices.

Level 2 Modding Challenge: Can you add a potions variable? Start the player with 1 potion. If they type “heal”, add a heart to their health, but subtract 1 from their potions!

Take a deep breath and look at what you just built. Think back to Chapter 1. You learned how to print a simple “Hello” on the screen. Now, you have written a complex program that takes real human input, tracks math data, makes smart logical decisions, and loops continuously until an epic game over.

You are no longer just a player wandering around in someone else’s Minecraft server or Roblox obby. You are a Creator. You can build your own worlds from scratch using nothing but your brain and a keyboard.

Your coding journey has just begun. Now that you know the basics of Python, you can:

  • Learn a library called Pygame to add real colorful graphics, jumping animations, and background music to your games.
  • Use Minecraft Education Edition to write Python scripts that instantly build giant glass domes or spawn 100 chickens inside the real 3D game!
  • Try learning Lua, the programming language used to make Roblox games. Since you already know about variables, loops, and conditionals, learning a new language will be incredibly easy!

Just like in Minecraft, where your first tiny dirt house eventually becomes a massive, glowing castle, every single line of code you write builds toward something greater. Keep experimenting, keep making mistakes, and keep building!

Ready to show off your awesome creation? Do these three things right now:

  1. Mod Your Game: Dive into your code and change the monster’s name, the winning treasure, and the starting hearts to match your absolute favorite video game or movie. Make it 100% yours.
  2. Host a Playtest: Ask a parent, sibling, or friend to sit at your computer and play “The Dungeon Run.” Do not help them! Just stand behind them and watch how they play. Did they find the secret “dance” move? Did they survive?
  3. Be a Game Designer: Grab a piece of paper and sketch a “Blueprint” for a brand new text adventure. Will it be set in deep space on a broken rocket? Inside a haunted mansion? Write down your starting variables and the monsters they will face!