0% found this document useful (0 votes)
27 views12 pages

Linux Control Base

Uploaded by

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

Linux Control Base

Uploaded by

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

import random

# Initialize player attributes

players = {

'Player 1': {'name': '', 'lives': 3, 'energy': 100, 'backpack': []},

'Player 2': {'name': '', 'lives': 3, 'energy': 100, 'backpack': []}

# Function to display player status

def display_status(player):

print(f"{player['name']}'s Status - Lives: {player['lives']}, Energy: {player['energy']}")

# Function to update and display player status

def update_status(player):

display_status(player)

# Function to write results to a text file

def write_results(winner):

with open("game_results.txt", "w") as file:

for player_key in players:

file.write(f"{players[player_key]['name']}\n")

file.write(f"Winner: {winner}\n")

# Initialize the game

def game_intro():

print("Welcome, brave adventurers, to the ultimate survival quest!")


print("After a harrowing plane crash, you find yourselves stranded on a remote, uncharted island.")

print("The island is teeming with dangers and mysteries, and your only hope of escape is to find the
airstrip.")

print("Your goal is to navigate through the wilderness, overcome obstacles, and locate the airstrip
where a new plane awaits.")

print("The first to reach the airstrip and secure the escape will be victorious.")

print("Choose your path wisely, for every decision will bring you closer to safety or deeper into peril.")

print("The fate of your adventure and your escape from this island lies in your hands. Let the journey
begin!")

# the introduction at the start of the game

game_intro()

def initialize_game():

for player_key in players:

name = input(f"{player_key}, enter your name: ")

players[player_key]['name'] = name

players[player_key]['backpack'] = ['lunchbox', 'spear', 'hand grenade', 'notebook', 'knife']

display_status(players[player_key])

# Decision functions for pre-pathway

def decision_1(player):

while True:

print(f"\n{player['name']}, it's your turn for Decision 1:")

print("1. Gather Supplies")

print("2. Start Moving")

choice = input("Choose an option (1-2): ")

if choice == '1':
print(f"{player['name']} decides to gather supplies. This will increase survival odds but costs
time.")

player['backpack'] = ['lunchbox', 'spear', 'hand grenade', 'notebook', 'knife']

break

elif choice == '2':

print(f"{player['name']} decides to start moving.")

break

else:

print("Invalid choice. Please select 1 or 2.")

def decision_2(player):

while True:

print(f"\n{player['name']}, it's your turn for the next decision. Do you dare venture through the
jungle or take the easy route around the jungle?:")

print("1. Navigate through a Dense Jungle")

print("2. Navigate Around the Jungle")

choice = input("Choose an option (1-2): ")

if choice == '1':

print(f"OH NO {player['name']} encounters wild animals! To survive an attack, you must throw a
random object at them, but only a hand grenade, a knife, or a spear can save you!")

item = random.choice(player['backpack'])

print(f"{player['name']} throws a {item} at the wild animals!")

if item in ('hand grenade', 'spear', 'knife'):

print("It's your lucky day! The animals are defeated. Proceeding to Decision 3.")

return 'proceed'

else:

print(f"That item was not enough to scare the animals! The animals attack! You lose a life.")

player['lives'] -= 1

update_status(player)

if player['lives'] <= 0:
print("You have lost all your lives. Game over.")

return 'game_over'

print("You are redirected back to Decision 2.")

return 'retry_decision_2'

elif choice == '2':

print(f"{player['name']} navigates around the jungle but loses 10 energy points.")

player['energy'] -= 10

update_status(player)

print("Proceeding to Decision 3.")

return 'proceed'

else:

print("Invalid choice. Please select 1 or 2.")

def decision_3(player):

while True:

print(f"\n{player['name']}, it's your turn for Decision 3. Take the shortcut by climbing the mighty
mountains or stay on course?:")

print("1. Climb a Mountain for a Better View")

print("2. Stay on Course")

choice = input("Choose an option (1-2): ")

if choice == '1':

print(f"{player['name']} climbs the mountain and slips, losing a life.")

player['lives'] -= 1

update_status(player)

if player['lives'] <= 0:

print("You have lost all your lives. Game over.")

return 'game_over'

print("You are redirected back to Decision 3.")

elif choice == '2':


print(f"{player['name']} stays on course and comes across a river.")

print("Proceeding to Decision 4.")

return 'proceed'

else:

print("Invalid choice. Please select 1 or 2.")

def decision_4(player):

while True:

print(f"\n{player['name']}, it's your turn for Decision 4:")

print("1. Cross the River")

print("2. Build a Raft")

choice = input("Choose an option (1-2): ")

if choice == '1':

result = random.choice(['crossed', 'not_crossed'])

if result == 'crossed':

print("You crossed the river safely. Proceeding to Decision 5.")

else:

print("You failed to cross the river and lose 5 energy points and some supplies.")

player['energy'] -= 5

update_status(player)

break

elif choice == '2':

print("You build a raft, which costs 15 energy points but crosses the river safely.")

player['energy'] -= 15

update_status(player)

break

else:

print("Invalid choice. Please select 1 or 2.")


print("Proceeding to Decision 5.")

def decision_5(player):

while True:

print(f"\n{player['name']}, it's getting dark and you need to decide whether you are going to camp
the night or go on? What choice do you make? :")

print("1. Camp for the Night")

print("2. Keep Moving")

choice = input("Choose an option (1-2): ")

if choice == '1':

print("You camp for the night, regaining 10 energy points but losing time.")

player['energy'] += 10

update_status(player)

break

elif choice == '2':

print("You keep moving, saving time but losing 5 energy points due to exhaustion.")

player['energy'] -= 5

update_status(player)

break

else:

print("Invalid choice. Please select 1 or 2.")

print("Alas, a great storm approaches your way and your only map gets damaged in the process! All
that is left for you to navigate yourself is the leftover bits of a half-torn map and your instincts... What do
you choose?")

def decision_6(player):

while True:

print(f"\n{player['name']}, it's time for Decision 6:")

print("1. Follow the Incomplete Torn Map")


print("2. Trust Your Instincts")

choice = input("Choose an option (1-2): ")

if choice == '1':

print("You decide to follow the incomplete torn map. Proceeding to Decision 7.")

outcome = 'map'

break

elif choice == '2':

print("You decide to trust your instincts. Proceeding to Decision 7.")

outcome = 'instincts'

break

else:

print("Invalid choice. Please select 1 or 2.")

print("A new day has arrived. You are tired but determined to leave the island.")

print("Ahead of you, you have 3 paths. Only one path will lead you to the airstrip.")

print("What do you choose?")

return outcome

def decision_7(player):

while True:

print(f"\n{player['name']}, it's your turn for Decision 7:")

print("1. Pathway 1")

print("2. Pathway 2")

print("3. Pathway 3")

choice = input("Choose a pathway (1-3): ")

if choice == '1':

return decision_8(player, 'pathway_1')

elif choice == '2':


return decision_10(player, 'pathway_2')

elif choice == '3':

return decision_8(player, 'pathway_3')

else:

print("Invalid choice. Please select 1, 2, or 3.")

def decision_8(player, pathway):

while True:

print(f"\n{player['name']}, you chose {pathway}.")

print("1. To the Left")

print("2. To the Right")

choice = input("Choose an option (1-2): ")

if choice == '1':

print("Alas! You end up near the beach and not at the airstrip. This was the wrong path.")

return 'retry_decision_6'

elif choice == '2':

return decision_9(player, 'marshy_land')

else:

print("Invalid choice. Please select 1 or 2.")

def decision_9(player, location):

while True:

print(f"\n{player['name']}, you are in {location}.")

print("1. Proceed Through the Marshy Land")

print("2. Go Back")

choice = input("Choose an option (1-2): ")

if choice == '1':

print("You pass through the marshy land but suffer a snake bite and lose 1 life.")

player['lives'] -= 1
update_status(player)

if player['lives'] <= 0:

print("You have lost all your lives. Game over.")

return 'game_over'

return 'retry_decision_6'

elif choice == '2':

player['energy'] -= 5

update_status(player)

return 'retry_decision_6'

else:

print("Invalid choice. Please select 1 or 2.")

def decision_10(player, pathway):

while True:

print(f"\n{player['name']}, you chose {pathway}.")

print("1. Keep Moving Forward")

print("2. Turn Around")

choice = input("Choose an option (1-2): ")

if choice == '1':

print(f"{player['name']} finally reaches the airstrip and finds the plane waiting for them!")

print("Congratulations, you have escaped the island!")

print(f"{player['name']} is the winner! The results of the game will be recorded in a text file")

write_results(player['name'])

return 'victory'

elif choice == '2':

print("You turn around and waste time.")

return 'retry_decision_6'
else:

print("Invalid choice. Please select 1 or 2.")

def decision_11(player, direction):

print(f"\n{player['name']}, you are heading {direction}.")

print("1. Proceed")

print("2. Go Back")

choice = input("Choose an option (1-2): ")

if choice == '1':

print("Congratulations! You have reached the airstrip ! YOU CAN NOW FLY A PLANE BACK HOME and
escape! WELL DONE SOLDIER ! Your results will be stored in a text file.")

return 'win'

elif choice == '2':

return 'retry_decision_7'

else:

print("Invalid choice. Please select 1 or 2.")

return 'retry_decision_11'

def decision_12(player, direction):

print(f"\n{player['name']}, you are heading {direction}.")

print("1. Proceed")

print("2. Go Back")

choice = input("Choose an option (1-2): ")

if choice == '1':

print("You get caught in a sandstorm and get lost. You lose 1 life and 10 energy points.")

player['lives'] -= 1

player['energy'] -= 10

update_status(player)
if player['lives'] <= 0:

print("Oops! You have lost all your lives. Game over. The other player has won! Your result will be
stored in a text file")

return 'retry_decision_7'

elif choice == '2':

player['energy'] -= 5

update_status(player)

return 'retry_decision_7'

else:

print("Invalid choice. Please select 1 or 2.")

return 'retry_decision_12'

# Main game loop

def main_game():

initialize_game()

winner = None

# Pre-pathway decisions

for decision in [decision_1, decision_2, decision_3, decision_4, decision_5]:

for player_key in players:

result = decision(players[player_key])

if result == 'game_over':

write_results(" won by loss of lives")

return
# Post-pathway decisions

for _ in range(2): # Each player will make decisions for the remaining rounds

for player_key in players:

result = decision_6(players[player_key])

if result == 'game_over':

write_results("won by loss of lives")

return

result = decision_7(players[player_key])

if result == 'game_over':

write_results("No winner")

return

# Determine the winner

if players['Player 1']['lives'] > 0 and players['Player 2']['lives'] <= 0:

winner = players['Player 1']['name']

elif players['Player 2']['lives'] > 0 and players['Player 1']['lives'] <= 0:

winner = players['Player 2']['name']

elif players['Player 1']['lives'] > 0 and players['Player 2']['lives'] > 0:

winner = "Both players survived"

print("All decisions are complete. Checking final status.")

write_results(winner)

if __name__ == "__main__":

main_game()

You might also like