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
49 changes: 48 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 Players

# Declare all the rooms

Expand All @@ -24,6 +25,7 @@

# Link rooms together


room['outside'].n_to = room['foyer']
room['foyer'].s_to = room['outside']
room['foyer'].n_to = room['overlook']
Expand All @@ -33,11 +35,16 @@
room['narrow'].n_to = room['treasure']
room['treasure'].s_to = room['narrow']

#



# #
# Main
#

# Make a new player object that is currently in the 'outside' room.
player = Players(input('Player name:'), room['outside'])
print(f"Hello {player.name}")

# Write a loop that:
#
Expand All @@ -49,3 +56,43 @@
# Print an error message if the movement isn't allowed.
#
# If the user enters "q", quit the game.

# LOOP
# READ
# EVAL
# PRINT

while True:
print(player.current_room.name)
print()
print(player.current_room.description)
cmd = input("\n~~> ")
if cmd == "q":
print('Goodbye!')
exit(0)
elif cmd == 'n':
if player.current_room.n_to is not None:
player.current_room = player.current_room.n_to
else:
print("----you cannot move in that direction----")
print()
elif cmd == 's':
if player.current_room.s_to is not None:
player.current_room = player.current_room.s_to
else:
print("----you cannot move in that direction----")
print()
elif cmd == 'e':
if player.current_room.e_to is not None:
player.current_room = player.current_room.e_to
else:
print("----you cannot move in that direction----")
print()
elif cmd == 'w':
if player.current_room.w_to is not None:
player.current_room = player.current_room.w_to
else:
print("----you cannot move in that direction----")
print()
else:
print("I did not understand the command")
13 changes: 13 additions & 0 deletions src/player.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
# Write a class to hold player information, e.g. what room they are in
# currently.


class Players:
def __init__(self, name, starting_room):
self.name = name
self.current_room = starting_room

def travel(self, direction):
if player.current_room.n_to is not None:
player.current_room = player.current_room.n_to
else:
print("----you cannot move in that direction----")
print()
15 changes: 14 additions & 1 deletion src/room.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
# Implement a class to hold room information. This should have name and
# description attributes.
# description attributes.


class 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 __str__(self):
return f"{self.name}"