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: 19 additions & 1 deletion 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 @@ -33,7 +34,7 @@
room['narrow'].n_to = room['treasure']
room['treasure'].s_to = room['narrow']

#
#n
# Main
#

Expand All @@ -49,3 +50,20 @@
# Print an error message if the movement isn't allowed.
#
# If the user enters "q", quit the game.


shaolin = Player('Baloo', room["outside"]);
#print(shaolin.getCurrentRoom().name)
while True:
user_input = input('Enter a direction:\n')
# print("Name:", shaolin.current_room.name)
# print("Description:", shaolin.current_room.description)
if user_input == 'q'.lower():
break
if user_input == 'n' or user_input == 's' or user_input == 'e' or user_input == 'w':
newRoom = shaolin.current_room.getRoomDirection(user_input)
if newRoom == None:
print('No way there!')
else:
shaolin.setRoom(newRoom)
print(newRoom)
16 changes: 16 additions & 0 deletions src/player.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,18 @@
# Write a class to hold player information, e.g. what room they are in
# currently.

class Player:
"""docstring for Player."""

def __init__(self, name, current_room):
self.current_room = current_room
self.name = name

def getCurrentRoom(self):
return self.current_room

def getName(self):
return self.name

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

class Room:
"""docstring for Room."""

def __init__(self, name, description):
self.name = name
self.description = description
self.n_to = None
self.s_to = None
self.e_to = None
self.w_to = None

def getRoomName(self):
return self.name

def getRoomDescription(self):
return self.description

def getRoomDirection(self, direction):
if direction == 'n':
return self.n_to
elif direction == 's':
return self.s_to
elif direction == 'e':
return self.e_to
elif direction == 'w':
return self.w_to
else:
return None

def __str__(self):
return f"{self.name}\n{self.description}"