[go: up one dir, main page]

0% found this document useful (0 votes)
5 views2 pages

project

This document contains a Python script for a text-based adventure game called 'Escape the Haunted Island'. Players navigate through choices, encounter creatures, and explore treasure rooms to accumulate points, aiming to escape the island before sunset. The game includes options to play again after completion.

Uploaded by

ziadmosaed73
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

project

This document contains a Python script for a text-based adventure game called 'Escape the Haunted Island'. Players navigate through choices, encounter creatures, and explore treasure rooms to accumulate points, aiming to escape the island before sunset. The game includes options to play again after completion.

Uploaded by

ziadmosaed73
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import random

import time

def print_with_delay(text, delay=1.5):


print(text)
time.sleep(delay)

def get_valid_input(prompt, choices):


while True:
user_input = input(prompt).strip()
if user_input in choices:
return user_input
else:
print("Invalid choice. Please try again.")

def get_random_weather():
weather_list = ["foggy", "rainy", "stormy", "windy", "sunny", "cloudy"]
return random.choice(weather_list)

def creature_encounter(score):
creatures = ["a giant snake", "a ghost pirate", "a wild boar", "a talking
monkey", "a swarm of bats"]
creature = random.choice(creatures)
print_with_delay(f"You suddenly encounter {creature}!")

if creature == "a ghost pirate":


penalty = random.randint(5, 10)
print_with_delay(f"The ghost pirate curses you! You lose {penalty}
points.")
score -= penalty
else:
reward = random.randint(5, 15)
print_with_delay(f"You escape and find something useful. You gain {reward}
points.")
score += reward

return score

def explore_treasure_room(score):
outcome = random.choice(["reward", "penalty"])
if outcome == "reward":
amount = random.randint(10, 20)
print_with_delay(f"You found treasure worth {amount} points!")
score += amount
else:
amount = random.randint(5, 15)
print_with_delay(f"A trap activates! You lose {amount} points.")
score -= amount
return score

def play_game():
total_score = 0

print_with_delay("🌴 Escape the Haunted Island", 2)


print_with_delay("You wake up on a mysterious, haunted island after a
shipwreck.")
print_with_delay("Your goal is to explore the island, survive its strange
inhabitants, and find a way to escape before the sun sets.")
weather = get_random_weather()
print_with_delay(f"The weather is {weather} today...")

print_with_delay("\nYou see two paths ahead:")


print_with_delay("1. Head into the jungle")
print_with_delay("2. Follow the coastline")

choice1 = get_valid_input("Which path do you choose? (1 or 2): ", ["1", "2"])


if choice1 == "1":
print_with_delay("You venture into the thick jungle...")
total_score += 5
else:
print_with_delay("You walk along the coast and meet a talking parrot who
gives you advice.")
total_score += 5

print_with_delay(f"Your score is now {total_score}")

total_score = creature_encounter(total_score)
print_with_delay(f"Your score is now {total_score}")

print_with_delay("You find an ancient temple with two glowing doors:")


print_with_delay("1. Enter the red door")
print_with_delay("2. Enter the blue door")

choice2 = get_valid_input("Which door do you choose? (1 or 2): ", ["1", "2"])


total_score = explore_treasure_room(total_score)
print_with_delay(f"Your final score is {total_score}")

if total_score >= 30:


print_with_delay("🎉 You light a fire and a rescue boat sees you. You
survived the haunted island!")
else:
print_with_delay("🚫 Your signal was too weak... The boat leaves. You're
stuck another night.")

restart = input("Do you want to play again? (y/n): ").lower()


con = ("y"or"n")
if restart == "y":
print()
play_game()
elif restart == "n":
print_with_delay("Thanks for playing! 👋")
else:
print("invalid input ,retry again")
restart = input("Do you want to play again? (y/n): ").lower()
while restart != con:
print("invalid input ,retry again")
restart = input("Do you want to play again? (y/n): ").lower()
play_game()

You might also like