Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 44 additions & 10 deletions src/adv.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from room import Room
from player import Player

# Declare all the rooms

Expand Down Expand Up @@ -38,14 +39,47 @@
#

# Make a new player object that is currently in the 'outside' room.
player = Player(room['outside'])

# Write a loop that:
#
# * Prints the current room name
# * Prints the current description (the textwrap module might be useful here).
# * Waits for user input and decides what to do.
#
# If the user enters a cardinal direction, attempt to move to the room there.
# Print an error message if the movement isn't allowed.
#
# If the user enters "q", quit the game.

welcome_message = "Welcome to the Adventure Game!"
wrong_way = "Nothing that way. You must turn back!"
success_message = "You found the treasure!"
quit_message = "Thanks for playing! Goodbye!"


print(welcome_message)
while True:

print(f"You're current location is: {player.room.location} {player.room.description}")

player_choice = input(
"Where will you go? [n] north [s] south [e] east [w] west [q] quit:")

if player.room.location == "Treasure Chamber":
print(success_message)
break

if player_choice == "n":
if player.room.n_to:
player.room = player.room.n_to
else:
print(wrong_way)
elif player_choice == "s":
if player.room.s_to:
player.room = player.room.s_to
else:
print(wrong_way)
elif player_choice == "e":
if player.room.e_to:
player.room = player.room.e_to
else:
print(wrong_way)
elif player_choice == "w":
if player.room.w_to:
player.room = player.room.w_to
else:
print(wrong_way)
elif player_choice == "q":
print(quit_message)
break
6 changes: 6 additions & 0 deletions src/player.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
# Write a class to hold player information, e.g. what room they are in
# currently.
class Player:
def __init__(self, room):
self.room = room

# def __str__(self):
# return f"{self.room}"
11 changes: 10 additions & 1 deletion src/room.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
# Implement a class to hold room information. This should have name and
# description attributes.
# description attributes.
class Room:
def __init__(self, location, description):
self.location = location
self.description = description
self.n_to = None
self.s_to = None
self.e_to = None
self.w_to = None