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
20 changes: 20 additions & 0 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 51 additions & 10 deletions src/adv.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from room import Room
from player import Player

# Declare all the rooms

room = {
'outside': Room("Outside Cave Entrance",
"North of you, the cave mount beckons"),
"North of you, the cave mount beckons"),

'foyer': Room("Foyer", """Dim light filters in from the south. Dusty
passages run north and east."""),
Expand Down Expand Up @@ -39,13 +40,53 @@

# Make a new player object that is currently in the 'outside' room.

# Write a loop that:
#
p1 = Player("Roger Wilco", 100, [], room['outside'])


# * 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.

#start game
print(f"\nYou have entered Matthew's Adventure. Only the strong will survive.\n \n{p1.room}")
# Write a loop that:
while True:
try:
# * Waits for user input and decides what to do.
user = input("[l] Look [n] Move North [s] Move South [e] Move East [w] Move West [q] Quit\n")

# If the user enters "q", quit the game.
if user == "q":
break

# * Prints the current description (the textwrap module might be useful here).
elif user == "l":
print(p1.room,'\n')
# If the user enters a cardinal direction, attempt to move to the room there.
# Print an error message if the movement isn't allowed.
elif user == "n":
p1.room = p1.room.n_to
print(p1.room)
continue

elif user == "s":
p1.room = p1.room.s_to
print(p1.room)
continue

elif user == "e":
p1.room = p1.room.e_to
print(p1.room)
continue
elif user == "w":
p1.room = p1.room.w_to
print(p1.room)
continue
else:
print(f"\n{user} is not a valid input\n\n")
print(p1.room)
continue

except AttributeError:
p1.room.wrong_way()
continue

print("\nThanks for playing!!\n")
7 changes: 7 additions & 0 deletions src/player.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
# Write a class to hold player information, e.g. what room they are in
# currently.

class Player:
def __init__(self, name, health, items, room):
self.name = name
self.health = health
self.items = items
self.room = room
13 changes: 12 additions & 1 deletion src/room.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
# Implement a class to hold room information. This should have name and
# description attributes.
# description attributes.

class Room:
def __init__(self, name, description, item="stuff"):
self.name = name
self.description = description
self.item = item

def __str__(self):
return f"\nYou are in the {self.name}. {self.description}\n"
def wrong_way(self):
print(f"The way is blocked. Try to go somewhere else.\n \n {self.description}\n")