Initial commit: 4game.py
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
# Define Rooms
|
||||
rooms = {
|
||||
'start': {
|
||||
'name': 'Start',
|
||||
'description': "You find yourself in the dimly lit hallway. The walls are bare and you notice several doors leading to different rooms.",
|
||||
'north': 'hallway'
|
||||
},
|
||||
'hallway': {
|
||||
'name': 'Hallway',
|
||||
'description': "A long corridor with no visible exits."
|
||||
}
|
||||
}
|
||||
|
||||
# Define Player State
|
||||
player = {
|
||||
'current_room': 'start',
|
||||
'inventory': []
|
||||
}
|
||||
|
||||
def move(current_room, direction):
|
||||
return rooms[current_room][direction]
|
||||
|
||||
def look():
|
||||
print(f"Current Room: {player['current_room']]}\n")
|
||||
current_room_name = player['current_room']
|
||||
result = move(current_room_name, 'north')
|
||||
if isinstance(result, str):
|
||||
print(result)
|
||||
else:
|
||||
player['current_room'] = result
|
||||
look()
|
||||
|
||||
while True:
|
||||
action = input("What do you want to do? Type 'look', 'move north', or 'quit' to exit: ")
|
||||
|
||||
if action == 'look':
|
||||
look()
|
||||
elif action == 'move north':
|
||||
current_room_name = player['current_room']
|
||||
result = move(current_room_name, 'north')
|
||||
if isinstance(result, str):
|
||||
print(result)
|
||||
else:
|
||||
player['current_room'] = result
|
||||
look()
|
||||
elif action == 'quit':
|
||||
print("Goodbye!")
|
||||
break
|
||||
Reference in New Issue
Block a user