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
40 changes: 39 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 @@ -36,11 +37,48 @@
#
# Main
#

print('=====================================')
print('=====================================')
print("Welcome to the Lambda adventure game")
print('Directions: type "north", "south", "east" or "west" to move your character. Type "q" to quit at anytime')
print("Before we begin, please choose a character name.")
# Make a new player object that is currently in the 'outside' room.
player_name = input('Please choose a name: ')
player = Player(player_name, room['outside'])

# Write a loop that:
#
location = ''
while location != 'q':
print('=====================================')
print(player)
location = input("Please enter a direction: ")
try:
if location == 'north':
if hasattr(player.location, 'n_to'):
player.location = player.location.n_to
else:
print('You\'re not allowed to move there')
elif location == 'south':
if hasattr(player.location, 's_to'):
player.location = player.location.s_to
else:
print('You\'re not allowed to move there')
elif location == 'east':
if hasattr(player.location, 'e_to'):
player.location = player.location.e_to
else:
print('You\'re not allowed to move there')
elif location == 'west':
if hasattr(player.location, 'w_to'):
player.location = player.location.w_to
else:
print('You\'re not allowed to move there')
else:
print('Cannot travel there')
except ValueError:
print('Error, unrecognized input')

# * 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.
Expand Down
10 changes: 10 additions & 0 deletions src/player.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
# Write a class to hold player information, e.g. what room they are in
# currently.


class Player:
def __init__(self, name, location):
self.name = name
self.location = location

def __str__(self):
output = f'Hello {self.name}, you\'re currently located at {self.location}'
return output
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, name, description):
self.name = name
self.description = description

def __str__(self):
output = f'{self.name}, {self.description}'
return output