Introduction
Treasure Island is a classic story-based adventure game where players explore a fictional island, make decisions, and attempt to find hidden treasure.
Treasure Island is a text adventure where the player navigates through a sequence of rooms or locations. At each step, they are offered choices are usually doors or paths and depending on the choice, they may: continue the adventure, encounter a trap, face a dead end or discover the treasure. Text-based adventure games are one of the most effective ways to learn programming logic, user input handling, and conditional branching. It is built in python programming language.
Among the most famous beginner-friendly projects is Treasure Island, a simple yet engaging Python game where players move through different paths and choose doors at every step. Despite its simplicity, the game teaches essential programming concepts, helps develop problem-solving skills, and introduces the fundamentals of game design. The game uses user input, conditional statements ( if/ else/ elif ) print statements, and simple logic flow. For beginners, it’s a fun introduction to programming without needing graphics or advanced libraries.

Why built treasure island?
Building Treasure Island in Python is more than a beginner exercise it’s a practical method for understanding logic-based programming.
- You learn how branching paths work.
- The nested structure forces careful thinking.
- Enhances user interaction understanding
- You learn to create sequences users can follow.
- Builds a foundation for future game development
How the game works?
- The player starts at the island entrance.
- They came to the crossroad and chooses left or right.
- If they right game over, they are attacked.
- If they left you arrived at the island.
- You see a house with three doors red, green, blue, etc.
- Choose the door wisely.
- One luck door contains the treasures.
- The same pattern repeats at each stage.
Source code
print('''
*******************************************************************************
| | | |
_________|________________.=""_;=.______________|_____________________|_______
| | ,-"_,="" `"=.| |
|___________________|__"=._o`"-._ `"=.______________|___________________
| `"=._o`"=._ _`"=._ |
_________|_____________________:=._o "=._."_.-="'"=.__________________|_______
| | __.--" , ; `"=._o." ,-"""-._ ". |
|___________________|_._" ,. .` ` `` , `"-._"-._ ". '__|___________________
| |o`"=._` , "` `; .". , "-._"-._; ; |
_________|___________| ;`-.o`"=._; ." ` '`."\` . "-._ /_______________|_______
| | |o; `"-.o`"=._`` '` " ,__.--o; |
|___________________|_| ; (#) `-.o `"=.`_.--"_o.-; ;___|___________________
____/______/______/___|o;._ " `".o|o_.--" ;o;____/______/______/____
/______/______/______/_"=._o--._ ; | ; ; ;/______/______/______/_
____/______/______/______/__"=._o--._ ;o|o; _._;o;____/______/______/____
/______/______/______/______/____"=._o._; | ;_.--"o.--"_/______/______/______/_
____/______/______/______/______/_____"=.o|o_.--""___/______/______/______/____
/______/______/______/______/______/______/______/______/______/______/_____ /
*******************************************************************************
''')
print("Welcome to treasure island")
print("Your mission is to find the treasure")
choice1 = input('You are at the crossroad, where do you want to go? Type "left" or "right" \n').lower()
if choice1 == "left":
choice2 = input('You arrived at lake. There is an island in the middle. Do you want to "swim" or "wait" \n').lower()
if choice2 == "swim":
choice3 = input('You finally arrived at the Island. There is a house with three doors. "Red", "Green" and "Blue". Choose one door. \n').lower()
if choice3 == "red":
print("Game Over. You just fell into a dark hole...")
elif choice3 =="green":
print("Congratulation.. You Win. You found the treasure worth $5 million")
else:
print("Game Over! You entered the room with fire...")
else:
print("Game Over! You are attacked by wild dogs...")
else:
print("Game Over! You are attacked by beast...")
How to use this project?
- Copy the source code below.
- Paste the code in your working file
- Save with .py extension
- Execute the project.
- Play the game.
FAQs
1. What is the Treasure Island Python game?
The Treasure Island Python game is a beginner-friendly text adventure demonstrating decision-making with user input. It teaches branching logic, interactive storytelling, and simple control flow. It’s commonly used in introductory Python tutorials that focus on foundational programming skills.
2. How does user input work in this project?
The game uses Python’s built-in input() function to capture decisions and .lower() to normalize them. The program branches into different outcomes depending on the exact text entered. This mirrors standard practices in text-based interfaces where input validation and string handling are fundamental.
3. Why is the game structured with nested if-else statements?
Nested if-else statements create linear decision paths where each choice triggers a new block of logic. Although easy for beginners, the structure becomes harder to maintain at scale. Python developers typically avoid deep nesting by using modular functions or dictionaries.
4. Can I expand the Treasure Island game into a more complex project?
Yes. You can expand it with loops, alternative endings, inventory systems, state tracking, and modular scenes. Text adventures grow cleaner when you separate story data from game logic, a technique often used in interactive fiction and larger Python projects.
5. Why does the game end quickly for wrong inputs?
The script only checks for exact keywords, so unrecognized inputs fall into default failure outcomes. Beginners often see this in early exercises because validation isn’t introduced yet. Adding loops or error handling creates a smoother user experience.
6. Is this a good Python project for beginners?
Yes. It introduces conditional logic, user interaction, and step-by-step decision-making, which are core programming fundamentals. It’s ideal as a first project because it’s easy to build, test, and expand with new ideas.
