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
51 changes: 49 additions & 2 deletions src/adv.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import sys
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 @@ -49,3 +51,48 @@
# Print an error message if the movement isn't allowed.
#
# If the user enters "q", quit the game.


######FORMATING#######
def spacing():
print('\n', end=' ')
def divider():
print('------------------------------------------------')
######################


#game intro
spacing()

print('Welcome!', end=' ')
playername = input('Please enter a name: ')

player = Player(playername, room['outside'])

spacing()

print(f'Hello {player.name}, are you ready for an adveture?')

spacing()

#game loop
while True:
##prints current location and description, prompts user for directions##
divider()
spacing()
print(player)
spacing()
direction = input('Which way? ').lower()
spacing()
########################################################################
if len(direction) == 1:
#quits loops with 'q'
if direction[0] == 'q':
sys.exit()
#sets direction reseting loop
elif direction[0] in ('n','s','e','w'):
player.travel(direction[0])
#corrects player resets loop
else:
print('That is not an option, try q to QUIT or n, s, e, or w to move around :)')
spacing()
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:
def __init__(self, name, current_room):
self.name = name
self.current_room = current_room

def __str__(self):
return f"You are in the {self.current_room.name}. \n {self.current_room.description}"

def travel(self, direction):
try:
self.current_room = getattr(self.current_room, f'{direction}_to')

except AttributeError:
print('\n', end='')
print(f'There is no path in that direction, {self.name}.')
print('\n', end='')
7 changes: 6 additions & 1 deletion src/room.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
# 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