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
42 changes: 42 additions & 0 deletions src/adv.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from room import Room
from player import Player
import time


# Declare all the rooms

Expand Down Expand Up @@ -49,3 +52,42 @@
# Print an error message if the movement isn't allowed.
#
# If the user enters "q", quit the game.
directions={
'w': 'north',
's': 'south',
'a': 'west',
'd': 'east'
}


def start_game():
name=input('Enter your name here: ')
player_1=Player(name,room['outside'])
print(f'''
Welcome to Treasure Hunting,{name}!
Press w,s,d,a,q to go north,south,east,west or to q to quit''')
time.sleep(1)
while True:
cmd=input(f'''
You\'re in {player_1.location.name}.
{player_1.location.description}\n ''')
if cmd in directions:
if (player_1.location.n_to==None and cmd=='w' or
player_1.location.s_to==None and cmd=='s' or
player_1.location.w_to==None and cmd=='a' or
player_1.location.e_to==None and cmd=='d'):
print (f'Sorry! You can\'t go {directions[cmd]} from here')
time.sleep(1)
continue
else:
player_1.change_location(cmd)
continue
elif cmd == 'q':
print('Thank you for playing. Goodbye!!')
quit()
else:
print('Please enter a valid direction')
continue

start_game()

28 changes: 28 additions & 0 deletions src/player.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,30 @@
# 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 change_location(self,direction):
if direction =='w':
self.location=self.location.n_to
elif direction=='s':
self.location=self.location.s_to
elif direction=='a':
self.location=self.location.w_to
elif direction =='d':
self.location=self.location.e_to

# location=['outside','foyer','narrow']
# for place in location:
# if self.location == place:
# if self.location=='outside':
# print('Outside yall')
# elif self.location=='foyer':
# self.location='overlook'
# elif self.location=='narrow':
# self.location='treasure'
# else:
# pass
19 changes: 18 additions & 1 deletion src/room.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,19 @@
# 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,s_to=None,w_to=None,e_to=None,direction=None):
self.name=name
self.description=description
self.n_to=n_to
self.s_to=s_to
self.e_to=e_to
self.w_to=w_to
self.direction=direction