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
63 changes: 63 additions & 0 deletions 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 @@ -33,12 +34,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 = Player("Rohith", room['outside'])


# Write a loop that:
#
# * Prints the current room name
Expand All @@ -49,3 +54,61 @@
# Print an error message if the movement isn't allowed.
#
# If the user enters "q", quit the game.

while True:
print("Your current room: ", player.room.name, player.room.description)

direction = input("Input a direction: ")

if direction.lower() == "q":
break
elif direction.lower() == "n":
if hasattr(player.room, "n_to"):
player.room = player.room.n_to
else:
print("A room doesn't exist there")
elif direction.lower() == "s":
if hasattr(player.room, "s_to"):
player.room = player.room.s_to
else:
print("A room doesn't exist there")
elif direction.lower() == "e":
if hasattr(player.room, "e_to"):
player.room = player.room.e_to
else:
print("A room doesn't exist there")
elif direction.lower() == "w":
if hasattr(player.room, "w_to"):
player.room = player.room.w_to
else:
print("A room doesn't exist there")








"""
Text based in every room ... command line ...
Several rooms, items to interact with ..
What are the objects involved here and what do they do?


* Create the input command parser in `adv.py` which allows the program to receive player input and commands to move to rooms
in the four cardinal directions.
* Fill out Player and Room classes in `player.py` and `room.py`


Player in the room... Player HAS a room ... Player has A ITEM

As we build out the objects... we have to figure out how to store relationships

Player Functions:
-Move (Change rooms)
-Pickup(Belongs to the class) (Method on the player)



"""
5 changes: 5 additions & 0 deletions src/player.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
# 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
8 changes: 7 additions & 1 deletion src/room.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
# Implement a class to hold room information. This should have name and
# description attributes.
# description attributes.
#super is for inheriting

class Room:
def __init__(self, name, description):
self.name = name
self.description = description