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,5 +1,5 @@
from room import Room

from player import Player
# Declare all the rooms

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

options = '\nYour available options are:\n\n| [n] North | [e] East | [s] South | [w] West | ----- | [q] Quit |\n'
directions = {'n': 'north', 'e': 'east', 's': 'south', 'w': 'west'}
player1 = Player('Bob', room['outside'])

print('\n*.*.*. ADVENTURE GAME .*.*.*')
print(player1)
print(options)

selection = ''
while selection != 'q':

selection = input(
'Please choose which direction you would like to travel:')

try:
if selection == 'q':
print('Thank you for playing Adventure Game!')
elif selection == 'n':
if player1.room.n_to:
player1.room = player1.room.n_to
print(player1)
else:
print('Oh no! You can\'t go that way...')
elif selection == 'e':
if player1.room.e_to:
player1.room = player1.room.e_to
print(player1)
else:
print('Oh no! You can\'t go that way...')
elif selection == 's':
if player1.room.s_to:
player1.room = player1.room.s_to
print(player1)
else:
print('\nOh no! You can\'t go that way...\n')
elif selection == 'w':
if player1.room.w_to:
player1.room = player1.room.w_to
print(player1)
else:
print('Oh no! You can\'t go that way...')
else:
print('You didn\'t enter a valid option. Please try again.')
print(options)
except ValueError:
print('Please choose one of the available options')
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, room):
self.name = name
self.room = room

def __str__(self):
return f"\n----------\n{self.name} is currently in {self.room}\n----------\n"

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, n_to=None, e_to=None, s_to=None, w_to=None):
self.name = name
self.description = description
self.n_to = n_to
self.e_to = e_to
self.s_to = s_to
self.w_to = w_to

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