#Author - Rusiru Senarath
Date - 20/08/2024
welcome message and display story
import os,sys,time,msvcrt, random
def main():
os.system('cls')
hello ASCI art for make interested player
M=('██╗░░██╗███████╗██╗░░░░░██╗░░░░░░█████╗░\n'
'██║░░██║██╔════╝██║░░░░░██║░░░░░██╔══██╗\n'
'███████║█████╗░░██║░░░░░██║░░░░░██║░░██║\n'
'██╔══██║██╔══╝░░██║░░░░░██║░░░░░██║░░██║\n'
'██║░░██║███████╗███████╗███████╗╚█████╔╝\n'
'╚═╝░░╚═╝╚══════╝╚══════╝╚══════╝░╚════╝░\n')
for char in M:
sys.stdout.write(char)
sys.stdout.flush()
time.sleep(0.01)
input function for get name of the player
name =input("Please Enter your Name(this essential for game):")
Display=("#Hi Welcome!\n"
"Let's start the Game then\n"
"Here first We display story\n"
"Imagine Now you are rich businessman\n")
Message=("Once up on a time there was a billionaire businessman.\n"
"he had a lots of money."
"One day his father's lawyer gave him to his father's last letter for him.\n"
f"So, that businessman called {name} was very busy with his business works.\n"
"That day night he was very tired with his business work."
"By, working lots of time with his work he got mind from works to outside."
"Then, turn back and looked around."
"Suddenly, he saw that letter which was last letter from his father's to him.\n")
for char in Display:
sys.stdout.write(char)
sys.stdout.flush()
time.sleep(0.01)
print("======================================================================================")
for char in Message:
sys.stdout.write(char)
sys.stdout.flush()
time.sleep(0.01)
message_one=("So, he started to unpacking that letter and start reading\n"
"It 'was about a island it has a Treasure\n"
"there was a map in that island\n "
"after looking a map he realized it isn't really easy to achieving that treasure he taught\n")
for char in message_one:
sys.stdout.write(char)
sys.stdout.flush()
time.sleep(0.01)
message_three= ("So he decided to go that island \n"
"He wanted to more people join with him\n"
"Then he post some ads on his business website\n"
"And joined 4 more people go with him this journey\n"
"Each ones has different Abilities and skills\n"
"Finally all of these people started to travel towards that island\n")
for char in message_three:
sys.stdout.write(char)
sys.stdout.flush()
time.sleep(0.01)
message_two=("""""
___\n
\ ~-___\n
= = ==(AA____D\n
_____________,-~~~~~~~`-.._\n
/ o O o o o o O O o o o o o o O o |_\n
`~-. ___..----.. )\n
`---~~___________/------------`````\n
= ===(_________D\n""""")
for char in message_two:
sys.stdout.write(char)
sys.stdout.flush()
time.sleep(0.001)
message_four = ("Unfortunately The plane was crashed by birds stuck in the engine\n"
"But when that time they arrived to the island \n"
"Then they find each others and join together and started collect all of usable items in crashed plane \n"
"After all they all started their journey find the treasure and went out this island\n")
for char in message_four:
sys.stdout.write(char)
sys.stdout.flush()
time.sleep(0.01)
After tell the story to the player now clean the screen and display menu
time.sleep(2)
os.system('cls'if os.name =='nt'
else 'clear')
#Health bar display function
def display_health_bar(health):
bar_length = 20
health_ratio = health / 100
bar = '#' * int(bar_length * health_ratio) + '-' * (bar_length - int(bar_length * health_ratio))
print(f"Health: [{bar}] {health}%")
Now start the game really, after displaying the story
game_name = (
"██████ ██ ██ ███████ ██ ███ ██ ███████ ███████ ███████ ███ ███ ███████ ███ ██ ████████ ██████ ███████ █████ ███████ ██ ██ ██████ ███████ ██ ██ ██ ██ ███ ██ ████████\n"
"██ ██ ██ ██ ██ ██ ████ ██ ██ ██ ██ ████ ████ ██ ████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██ ██\n"
"██████ ██ ██ ███████ ██ ██ ██ ██ █████ ███████ ███████ ██ ████ ██ █████ ██ ██ ██ ██ ██████ █████ ███████ ███████ ██ ██ ██████ █████ ███████ ██ ██ ██ ██ ██ ██\n"
"██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██\n"
"██████ ██████ ███████ ██ ██ ████ ███████ ███████ ███████ ██ ██ ███████ ██ ████ ██ ██ ██ ███████ ██ ██ ███████ ██████ ██ ██ ███████ ██ ██ ██████ ██ ████ ██\n")
for char in game_name:
sys.stdout.write(char)
sys.stdout.flush()
time.sleep(0.01)
#Define Player class
class Player:
def init(self, name, health):
self.name = name
self.health = health
self.tools = set()
self.foods = set()
self.skills = {"Stealth": 0, "Strength": 0, "Intelligence": 0}
def add_tool(self, tool):
self.tools.add(tool)
def add_food(self, food):
self.foods.add(food)
def show_status(self):
print(f"Player: {self.name}")
print(f"Health: {self.health}")
print(f"Tools: {', '.join(self.tools) if self.tools else 'None'}")
print(f"Foods: {', '.join(self.foods) if self.foods else 'None'}")
print(f"Skills: {self.skills}")
def use_skill(self, skill):
if self.skills[skill] > 0:
self.skills[skill] -= 1
return True
return False
Function to clear the screen
def clear_screen():
os.system('cls' if os.name == 'nt' else 'clear')
Create function to display the game menu
def game_menu():
print("Businessman's Treasure Hunt")
print("===========================")
print("1. Start Game")
print("2. About")
print("3. Continue")
print("4. Quit game")
print("===========================")
Function to start the game
def start_game():
print("Starting the game.........")
time.sleep(2) # Add delay for effect
Sub-menu for the game
def print_game_sub_menu():
print("Island Adventure")
print("================")
print("1. Display Island Map")
print("2. Collect Foods")
print("3. Quit to Main Menu")
print("================")
Function to display the island map
def display_island_map(delay=5):
message_five = ("""""
Here this the map of island
_________________________________________________________________________________________
|~ ~ ~ ~ ~ B L L L L E b
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ |\n
| ~ ~ ~ ~ B L S * * * *
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ |\n | ~ ~ ~ B L S * *
L L ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ |\n | ~ ~ E B L L * * M *
L * ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ |\n
|~ ~ ~ p B L L M T M M
M M * L ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ |\n |~ ~ ~ ~ B L L M M + + S l S
* * * M * L ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ |\n |~
M + S l
l l * * * * * * L ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ |\n
|~
B L
S + l
l S l L ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ |\n | ~ ~ ~ ~ B L
+ l l
l S l L ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ |\n
| ~ ~ ~ B L
S S S S l L ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ |\n
| ``
``
```` L ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ |\n
|~ ~ ~ ~ ~ B L L +
L L ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ |\n | ~ ~ ~ ~ ~ ~ ~ B L + + L
L ~~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ |\n
| ~ ~ ~ ~ ~ ~ ~ B L L L L L L L ~ E ts
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ |\n __________________________________________________________________________________________|\n letter (\"B\") means : Beach\n letter (\"L\") means : Land\n letter (\"M\") means : Mountains\n letter (\"E\") means : Exit\n letter (\"b\") means : boat\n letter (\"S\") means : Snares\n letter (\"p\") means : plane\n letter (\"ts\") means : tourist ship\n Symbol (\"+\") means : way1 to go towards the treasure\n Symbol (\"*\") means : way2 to go towards the treasure\n letter (\"l\") means : way3 to go towards the treasure\n Symbol (\"~\") means : Sea\n Symbol (\"
") means : lake\n"]
hint If you go to the treasure, I warn you: if you are able to select near ways to go, don't do it.\n
""""")
time.sleep(delay)
for char in message_five:
sys.stdout.write(char)
sys.stdout.flush()
time.sleep(0.01)
time.sleep(0.02)
Function to collect foods
def collect_foods(player,delay=10):
available_foods = {"Coconuts", "Berries", "Fish", "Mangoes", "Bananas"}
while True:
print("Available foods on the island:")
for food in available_foods:
print(f"- {food}")
choice = input("Enter the name of the food you want to collect (or type 'done' to finish): ").capitalize()
if choice == 'Done':
break
elif choice in available_foods:
player.add_food(choice)
print(f"{choice} added to your collection.")
time.sleep(delay)
else:
print("Invalid choice. Please select a valid food item.")
time.sleep(delay)
print("You have collected the following foods:")
for food in player.foods:
print(f"- {food}")
Function to search for tools
def search_tools(player,delay=7):
tools = ["Axe", "Shovel", "Fishing Rod", "Knife"]
found_tool = random.choice(tools)
print(f"You have found a {found_tool}!")
time.sleep(delay)
player.add_tool(found_tool)
time.sleep(1) # Add delay to simulate time spent finding tools
Function to handle wild animal encounters
def encounter_wild_animals(player,delay = 7):
animals = ["Tiger", "Snake", "Bear"]
encounter = random.choice(animals)
print(f"A wild {encounter} appears!")
action = input("Do you want to (1) Fight or (2) Run? ")
if action == '1':
result = random.choice([True, False])
if result:
print(f"You successfully fought off the {encounter}!")
time.sleep(delay)
else:
print(f"The {encounter} injured you!")
time.sleep(delay)
player.health -= 20
elif action == '2':
print(f"You ran away from the {encounter} safely!")
time.sleep(delay)
else:
print("Invalid action. The animal attacked you!")
time.sleep(delay)
player.health -= 20
if player.health <= 0:
print("You have succumbed to your injuries. Game Over.")
time.sleep(delay)
return False # Player is dead
return True # Player is still alive
def face_snares(player,delay= 7):
snares = ["Trap", "Quicksand", "Poisonous Plant"]
snare = random.choice(snares)
print(f"You encountered a {snare}!")
action = input("Do you want to (1) Avoid or (2) Use Intelligence? ")
if action == '1':
player.health -= 10
print(f"The {snare} caused you to lose 10 health points.")
elif action == '2':
if player.use_skill("Intelligence"):
print(f"You used Intelligence to avoid the {snare}!")
time.sleep(delay)
else:
print("You don't have enough Intelligence skill points. The snare injured you!")
time.sleep(delay)
player.health -= 10
else:
print("Invalid action. The snare injured you!")
time.sleep(delay)
player.health -= 10
Function to display game about section
def show_about():
print("About Businessman's Treasure Hunt")
print("=================================")
print(
"In this game, you play as a wealthy businessman on a quest to find a hidden treasure on a mysterious island. "
"The goal is to survive and be rescued or escape the island. Your plane has crashed.")
print("You will need to navigate through various challenges, collect resources, and uncover secrets to succeed in your adventure.")
print("hint = if you can collect some foods before start the game it will be easy to get the treasure and win the games")
print("As you can see on the map, there are three exits:")
print("1. Exit with a plane.")
print("2. Exit with a boat.")
print("3. Exit with a tourist ship.")
print("Good luck!")
print("\nPress the space bar to return to the main menu.")
while True:
if msvcrt.kbhit() and msvcrt.getch() == b' ':
break
def start_game1():
player_name = input("Enter your character's name: ")
player = Player(name=player_name, health=100)
while True:
clear_screen()
display_health_bar(player.health)
player.show_status()
game_menu()
start_game()
gmchoice = input("Select an option (1-3):")
if gmchoice =='1':
print_game_sub_menu()
elif gmchoice =='2':
show_about()
clear_screen()
print(game_menu())
elif gmchoice =='3':
print("You can continue playing game\n")
print("There are no saved previous game played\n")
print("This game couldn't save history ")
print(game_menu())
else:
print("Invalid Choice Please Enter A Valied Choice:")
choice = input("Select an option (1-3): ")
if choice == '1':
display_island_map()
print("Now You have seen the map\n"
"Remember the map correctly and select the way to get treasure and exit the island\n")
clear_screen()
search_tools(player)
clear_screen()
way_choice = input("There are three ways to enter the treasure area (please survive and don't die)\n"
"Choose a way to the treasure (1, 2, or 3): ")
if way_choice in ['1', '2', '3']:
if random.choice([True, False]):
if not encounter_wild_animals(player):
break
else:
face_snares(player)
else:
print("Invalid choice. Please select a valid way.")
elif choice == '2':
collect_foods(player)
clear_screen()
search_tools(player)
clear_screen()
way_choice = input("There are three ways to enter the treasure area (please survive and don't die)\n"
"Choose a way to the treasure (1, 2, or 3): ")
if way_choice in ['1', '2', '3']:
if random.choice([True, False]):
if not encounter_wild_animals(player):
break
else:
face_snares(player)
else:
print("Invalid choice. Please select a valid way.")
elif choice == '3':
clear_screen()
search_tools(player)
clear_screen()
way_choice = input("There are three ways to enter the treasure area (please survive and don't die)\n"
"Choose a way to the treasure (1, 2, or 3): ")
if way_choice in ['1', '2', '3']:
if random.choice([True, False]):
if not encounter_wild_animals(player):
break
else:
face_snares(player)
else:
print("Invalid choice. Please select a valid way.")
elif choice == '4':
print("Exiting the game. Goodbye!")
break
else:
print("Invalid choice. Please select a valid option.")
# Check for player health
if player.health <= 0:
print("You have succumbed to your injuries. Game Over.")
break
if name == "main":
player = start_game1()
main()