Treasure island in python

Treasure island in python

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

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?


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?


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?

Leave a Reply

Your email address will not be published. Required fields are marked *