Beginner Python Project: Build a Text-Based Adventure Game

3D illustration of a fantasy adventure world emerging from an open book with decision signposts.

Before graphics, games were played entirely with text. You’d read a description and type what you wanted to do: “Go North”, “Take Sword”. Now, creating your own text adventure game in Python can be a great way to relive that classic experience.

Today, we’ll build a simple one. This project is fantastic because it forces you to structure your code using functions for each room.

Step 1: The Structure

We’ll use a separate function for every “room” in our game.

def start_room():
    print("\nYou are in a dark room. There is a door to your North and East.")
    choice = input("> ")
    
    if choice.lower() == "north":
        monster_room()
    elif choice.lower() == "east":
        treasure_room()
    else:
        print("I don't understand that.")
        start_room() # Loop back to the start of THIS room

Step 2: The Other Rooms

def monster_room():
    print("\nA hungry troll is here! He eats you.")
    print("GAME OVER.")
    # The function ends here, so the game ends.

def treasure_room():
    print("\nYou found a chest full of gold!")
    print("YOU WIN!")

Step 3: Start the Game

print("=== Welcome to the Dungeon ===")
start_room()

Challenge: Add Inventory

Can you add a global inventory = [] list?

  • Add a “sword_room” where the player can type “take sword” to add it to their list.
  • Change monster_room so that IF “sword” is in their inventory, they win instead of losing!

Similar Posts

Leave a Reply