Hye what's up

Delhi(history) ∙ 
Permalink
class Game:
def __init__(self):
self.locations = {
'forest': {
'description': 'You are in a dark forest. Paths lead to the north and east.',
'north': 'cave',
'east': 'clearing'
},
'cave': {
'description': 'You find yourself in a damp cave. A treasure chest lies here.',
'south': 'forest'
},
'clearing': {
'description': 'You are in a sunny clearing. You can see a path leading back to the forest.',
'west': 'forest'
}
}
self.current_location = 'forest'

def move(self, direction):
if direction in self.locations[self.current_location]:
self.current_location = self.locations[self.current_location][direction]
print(self.get_location_description())
else:
print("You can't go that way.")

def get_location_description(self):
return self.locations[self.current_location]['description']

def play(self):
print("Welcome to the Adventure Game!")
while True:
print(self.get_location_description())
command = input("Enter a direction (north, south, east, west) or 'quit' to exit: ").strip().lower()
if command == 'quit':
print("Thanks for playing!")
break
self.move(command)

if __name__ == "__main__":
game = Game()
game.play()

What tools did you use to create your project?

  • python
0
0
0
0
 
Participation Certificate

Members

AG