Introduction to Programming

Lesson 7 of 7

Build Your First Project

Combine variables, loops, conditions, and functions to create a playable text adventure game!

🟡 Intermediate 120 XP

Learn it

Congratulations! You now understand all the core building blocks of programming: variables for memory, loops for repetition, conditions for choices, and functions for organisation.

In this capstone project, you will combine all four superpowers together to build your very own interactive, playable text adventure game in Python!

Key terms

Game Loop
A central loop that repeatedly updates game state and processes user actions.
State
The complete set of variable values that represent the current status of a program.
Debugging
The methodical process of finding and correcting mistakes or bugs in software.
Refactoring
Restructuring existing code to improve readability and design without altering behavior.

Game Project Architecture

Follow these four architectural stages to build your text-based dungeon explorer.

  1. 1Initialise State: Declare starting variables for hero_health, gold, and current_room.
  2. 2Define Action Functions: Create modular functions for exploring rooms, fighting monsters, and resting.
  3. 3Main Game Loop: Use a while loop that continues prompting choices as long as hero_health > 0.
  4. 4Win/Loss Evaluation: Check conditions at the end of every loop turn to trigger victory or game over messages.

Mini Quest Engine

pythondef explore_cave(player_gold):
    print("You explore the glowing cave...")
    return player_gold + 10

gold = 0
turns = 3

for turn in range(1, turns + 1):
    print("Turn:", turn)
    gold = explore_cave(gold)
    if gold >= 20:
        print("Pocket is getting heavy!")

print("Adventure finished! Total gold:", gold)

This project integrates functions, loops, conditions, and variables into a mini adventure loop.

Build it in MakeCode

Code along right here — the real Microsoft MakeCode editor is embedded below.

Live MakeCode studio

Full block/JavaScript/Python editor for 160×120 retro games.

New tab

This is the real Microsoft MakeCode editor running inside CodeQuest. Your project saves in the MakeCode editor itself — use Share or Download in MakeCode to keep or hand in your game. If your school network blocks embedded frames, hit New tab.

Try it

Arrange the software development stages for building your first project in the correct order.

  • 1Write reusable helper functions for core actions like battle and exploration
  • 2Test edge cases and debug errors to polish the final experience
  • 3Construct the main game while loop to handle turns and player input
  • 4Plan the game concept, player choices, and victory conditions on paper
  • 5Declare variables for tracking player health, inventory, and game state

Challenge

Build a complete mini text game in Python where the player has 3 health points and chooses between left and right doors across 3 rounds.

Pick whichever way suits you — every mode earns the same bonus XP.

Write at least 40 more characters to submit.

Mark your own work

Guided walkthrough — 0/5 clues revealed

  1. Clue 1 locked — reveal it only if you get stuck.
  2. Clue 2 locked — reveal it only if you get stuck.
  3. Clue 3 locked — reveal it only if you get stuck.
  4. Clue 4 locked — reveal it only if you get stuck.
  5. Clue 5 locked — reveal it only if you get stuck.

Each clue costs 6 XP (never below 30 XP). You'd earn 60 XP right now.

Extension: Add an inventory list variable that stores items found behind lucky doors.

Quiz time

Question 1 of 4Score 0

What is the role of the game loop in an interactive text adventure?