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
4 changes: 3 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ name = "pypi"
[packages]

[dev-packages]
pylint = "*"
autopep8 = "*"

[requires]
python_version = "3"
python_version = "3"
122 changes: 120 additions & 2 deletions Pipfile.lock

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

116 changes: 70 additions & 46 deletions src/adv.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
from room import Room
from player import Player
from item import Item

#declare items

items = {
"The Eye of Agammoto": Item("The Eye of Agammoto", "The The Eye of Agammoto can maniputale time", 50),
"The Sword of a Thousand Truths": Item("The Sword of a Thousand Truths", "A sword made by Hatori Hanzo", 100),
"Torch": Item("Torch", "Lets you see in dark places", 10)
}

# Declare all the rooms

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", [items["Torch"]]),

'foyer': Room("Foyer", """Dim light filters in from the south. Dusty
passages run north and east."""),
passages run north and east.""", [items["The Sword of a Thousand Truths"]]),

'overlook': Room("Grand Overlook", """A steep cliff appears before you, falling
into the darkness. Ahead to the north, a light flickers in
Expand All @@ -18,8 +26,7 @@
to north. The smell of gold permeates the air."""),

'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."""),
chamber! You see something shiny in the corner. The only exit is to the south.""", [items["The Eye of Agammoto"]]),
}


Expand All @@ -37,56 +44,73 @@
#
# Main
#

# Make a new player object that is currently in the 'outside' room.

p1 = Player("Roger Wilco", 100, [], room['outside'])

player1 = Player("Roger Wilco", 100, [], room['outside'])



# * Prints the current room name
ui_display = ""
ui_display += "\n----------------\n"
ui_display += "\nActions: [look] [i]nventory [q]uit [h]elp\n"
ui_display += "\nMovement: [n]orth [s]outh [e]ast [w]est \n"

#start game
print(f"\nYou have entered Matthew's Adventure. Only the strong will survive.\n \n{p1.room}")
# Write a loop that:

directions = ("n", "s", "e", "w")

def err_msg():
print(f"\nThat is not a valid input\n")
print(player1.current_room)

# start game
print(
f"\nYou have entered Matthew's Adventure. Only the strong will survive. {player1.current_room}\n\n{ui_display}")
# REPL
while True:
try:
# * Waits for user input and decides what to do.
user = input("[l] Look [n] Move North [s] Move South [e] Move East [w] Move West [q] Quit\n")

# If the user enters "q", quit the game.
if user == "q":
user_input = input("~~>").split()

# * Waits for user_input input and decides what to do.

#one command logic
if len(user_input) == 1:
if user_input[0] == "i":
print(player1)

elif user_input[0] == "look":
print(player1.current_room, '\n')

# If the user_input enters a cardinal direction, attempt to move to the room there.
elif user_input[0] in directions:
player1.move(user_input[0])

# If the user_input enters "q", quit the game.
elif user_input[0] == "q":
print("\nThanks for playing!!\n")
break

elif user_input[0] == "h":
print(ui_display)
else:
err_msg()
continue


# * Prints the current description (the textwrap module might be useful here).
elif user == "l":
print(p1.room,'\n')
# If the user enters a cardinal direction, attempt to move to the room there.
# Print an error message if the movement isn't allowed.
elif user == "n":
p1.room = p1.room.n_to
print(p1.room)
continue

elif user == "s":
p1.room = p1.room.s_to
print(p1.room)
continue

elif user == "e":
p1.room = p1.room.e_to
print(p1.room)
continue
elif user == "w":
p1.room = p1.room.w_to
print(p1.room)
continue
elif len(user_input) == 2:
#action verb logic
if user_input[1] in items:
player1.action(user_input[0], items[user_input[1]])
else:
print(f"\n{user} is not a valid input\n\n")
print(p1.room)
continue
err_msg()
continue

else:
err_msg()
continue





except AttributeError:
p1.room.wrong_way()
continue

print("\nThanks for playing!!\n")
14 changes: 14 additions & 0 deletions src/item.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Item:
def __init__(self, name, description, points):
self.name = name
self.description = description
self.points = points

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

def look(self):
return f"{self.description}"

def on_take(self):
return f"You have picked up the {self.name}."
40 changes: 37 additions & 3 deletions src/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,42 @@
# currently.

class Player:
def __init__(self, name, health, items, room):
def __init__(self, name, health, inventory, starting_room):
self.name = name
self.health = health
self.items = items
self.room = room
self.inventory = inventory
self.current_room = starting_room

def __str__(self):
display_string = ""
display_string += f"\n----------------\n"
display_string += f"\nName:{self.name}\n"
display_string += f"\nHealth:{self.health}\n"
display_string += f"\nIventory:{[i.name for i in self.inventory]}"
return display_string

def move(self, direction):
next_room = self.current_room.get_room_by_direction(direction)
#check if move is valid
if next_room:
self.current_room = next_room
print(self.current_room)
else:
return self.current_room.wrong_way()

def action(self,action,item):
#check verb
# check verb and noun
if action == "get" and self.current_room.get_item(item):
self.inventory.append(item)
print(item.on_take())
elif action == "drop" and item in self.inventory:
self.inventory.remove(item)
self.current_room.items.append(item)

else:
print(f"Im sorry {self.name}, you can't do that.")
# remove item from inventory



28 changes: 24 additions & 4 deletions src/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,32 @@
# description attributes.

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

def get_room_by_direction(self,direction):
print(direction)
if hasattr(self, f"{direction}_to"):
return getattr(self, f"{direction}_to")
else:
return None

def get_item(self, item):
if item in self.items:
self.items.remove(item)
return True
else:
print("That item is not here.")
return False


def __str__(self):
return f"\nYou are in the {self.name}. {self.description}\n"
return f"\n{self.name}\n{self.description}\n\nRoom Items {[i.name for i in self.items]}"
def wrong_way(self):
print(f"The way is blocked. Try to go somewhere else.\n \n {self.description}\n")
print(f"\nThe way is blocked. Try to go somewhere else.\n\n{self.description}\n")