Skip to content

Incomplete MVP Day 2 | Need verb and item commands to parser #507

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .idea/Intro-Python-II.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

87 changes: 68 additions & 19 deletions src/adv.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
from room import Room
from player import Player
from item import Item

# Declare all the rooms

sword = Item("Sword", "Sharp and dangerous!")
gold = Item("Gold", "Shiny!")

room = {
'outside': Room("Outside Cave Entrance",
"North of you, the cave mount beckons"),
'outside': Room("Outside Cave Entrance",
"North of you, the cave mount beckons", [sword]),

'foyer': Room("Foyer", """Dim light filters in from the south. Dusty
passages run north and east."""),
'foyer': Room("Foyer", """Dim light filters in from the south. Dusty
passages run north and east.""", []),

'overlook': Room("Grand Overlook", """A steep cliff appears before you, falling
into the darkness. Ahead to the north, a light flickers in
the distance, but there is no way across the chasm."""),
the distance, but there is no way across the chasm.""", []),

'narrow': Room("Narrow Passage", """The narrow passage bends here from west
to north. The smell of gold permeates the air."""),
'narrow': Room("Narrow Passage", """The narrow passage bends here from west
to north. The smell of gold permeates the air.""", [gold]),

'treasure': Room("Treasure Chamber", """You've found the long-lost treasure
chamber! Sadly, it has already been completely emptied by
earlier adventurers. The only exit is to the south."""),
earlier adventurers. The only exit is to the south.""", [sword, gold]),
}


# Link rooms together

room['outside'].n_to = room['foyer']
Expand All @@ -36,16 +40,61 @@
#
# Main
#

username = input("Please put in your name: ")
# Make a new player object that is currently in the 'outside' room.

player = Player(username, room['outside'], [])
# Write a loop that:
#
# * 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.
#
# If the user enters a cardinal direction, attempt to move to the room there.
# Print an error message if the movement isn't allowed.
#

while player.current_room:
# * Prints the current room name
print(f"Current room: {player.current_room.name}")
# * Prints the current description (the textwrap module might be useful here).
print(f"{player.current_room.description}")
ret = f"What's in the room? \n"
for i in player.current_room.storage:
ret += f"{i.name}\n"
names = i.name
if len(player.current_room.storage) == 0:
print("There's nothing in the room!\n")
else:
print(ret)
print("-------------------------------------------------------------------------")
# * Waits for user input and decides what to do.
if len(player.current_room.storage) != 0:
print("There's something in the room. Why not try to pick it up or drop whatever if you want to.")
selection = input("Please pick a direction to go in (North = n, South = s, West = w, East = e): ")
print('-------------------------------------------------------------------------')
# If the user enters a cardinal direction, attempt to move to the room there.
if selection == 'n':
if player.current_room.n_to is None:
print(f"There is nothing north of {player.current_room.name}. Please pick another direction.")
else:
player.current_room = player.current_room.n_to
elif selection == 's':
if player.current_room.s_to is None:
print(f"There is nothing south of {player.current_room.name}. Please pick another direction.")
else:
player.current_room = player.current_room.s_to
elif selection == 'w':
if player.current_room.w_to is None:
print(f"There is nothing west of {player.current_room.name}. Please pick another direction.")
else:
player.current_room = player.current_room.w_to
elif selection == 'e':
if player.current_room.e_to is None:
print(f"\nThere is nothing east of {player.current_room.name}. Please pick another direction.")
else:
player.current_room = player.current_room.e_to
# elif len(selection) == 2:
# verb = selection[0]
# item_name = selection[1]
# if (verb == 'get' or verb == 'take') and (item_name == names):
# player.current_room.pick_item(item_name)

elif selection == 'q':
print("Thank you for playing!")
player.current_room = False # Get out of game
# Print an error message if the movement isn't allowed.
else:
print(selection + " wasn't allowed. Please pick another valid direction.")
# If the user enters "q", quit the game.
8 changes: 8 additions & 0 deletions src/item.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Item:
def __init__(self, name, description):
self.name = name
self.description = description

def __str__(self):
return f"Name of item: {self.name}\n" \
f"Description of item: {self.description}"
17 changes: 17 additions & 0 deletions src/player.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,19 @@
# Write a class to hold player information, e.g. what room they are in
# currently.


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

def __str__(self):
return f"Name: {self.name}\n" \
f"Current room: {self.current_room}\n" \
f"Stuff on player: {self.storage}"


if __name__ == "__main__":
a = Player("Bob", "Bob's Room") # __repr__ works
print(a)
40 changes: 39 additions & 1 deletion src/room.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,40 @@
# Implement a class to hold room information. This should have name and
# description attributes.
# description attributes.
from player import Player

class Room:
def __init__(self, name, description, storage=[], n_to=None, w_to=None, e_to=None, s_to=None):
self.n_to = n_to
self.w_to = w_to
self.e_to = e_to
self.s_to = s_to
self.name = name
self.description = description
self.storage = storage

def


# def pick_item(self, item):
# for i in self.storage:
# if item == i:
# self.storage.remove(i)
# print(f"You picked up {item}")
# return self.storage
# else:
# print(f"There's no such thing as {item}.")



def __str__(self):
return f"Name of room: {self.name}\n" \
f"Description: {self.description}\n" \
f"Stuff that room has: {self.storage}\n" \
f"North: {self.n_to}\n" \
f"West: {self.w_to}\n" \
f"East: {self.e_to}\n" \
f"South: {self.s_to}"

if __name__ == "__main__":
a = Room("asdf", "asjd;kl;") # __str__ works
print(a)