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

Code

This document contains a simple text-based adventure game implemented in Python. Players navigate between rooms, examine items, and can quit the game. The game features basic commands for movement and item examination.

Uploaded by

Harsh Durgude
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)
9 views2 pages

Code

This document contains a simple text-based adventure game implemented in Python. Players navigate between rooms, examine items, and can quit the game. The game features basic commands for movement and item examination.

Uploaded by

Harsh Durgude
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/ 2

Code:

def get_input(prompt):

"""Gets and validates user input."""

return input(prompt).lower()

def move_room(current_room, direction):

"""Moves the player to a new room."""

# Example room transitions

if current_room == "start" and direction == "north":

return "forest"

elif current_room == "forest" and direction == "south":

return "start"

else:

print("You can't go that way.")

return current_room

def examine_item(item):

"""Examines an item."""

if item == "tree":

print("It's a large, old tree.")

else:

print("You don't see that here.")

def play_game():

"""Main game function."""

current_room = "start"

inventory = []

print("Welcome to the Text Adventure!")

while True:

if current_room == "start":

print("You are at the start of a path. A forest lies to the north.")

action = get_input("What do you do? (north, examine tree, quit): ")

if action == "north":

current_room = move_room(current_room, "north")

elif action == "examine tree":

examine_item("tree")

elif action == "quit":

break
else:

print("Invalid command.")

elif current_room == "forest":

print("You are in a dark forest. A path leads south.")

action = get_input("What do you do? (south, quit): ")

if action == "south":

current_room = move_room(current_room, "south")

elif action == "quit":

break

else:

print("Invalid command.")

print("Game Over.")

play_game()

Output:

Welcome to the Text Adventure!

You are at the start of a path. A forest lies to the north.

What do you do? (north, examine tree, quit): north

You are in a dark forest. A path leads south.

What do you do? (south, quit): south

You are at the start of a path. A forest lies to the north.

What do you do? (north, examine tree, quit): examine tree

It's a large, old tree.

You are at the start of a path. A forest lies to the north.

What do you do? (north, examine tree, quit): quit

Game Over.

You might also like