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
182 changes: 175 additions & 7 deletions src/adv.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,46 @@
import os
import time
from room import Room
from player import Player,Warrior
from item import Item


# Declare all the items
items = {
"gold":Item(
"gold",
"Shiny doubloons used to trade for other items"
),
"sword":Item(
"sword",
"A weapon that is used to destroy your enemies"
),
"health_potion":Item(
"healing potion",
"An elixer to increase one's health points"
)
}

# Declare all the rooms

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

'foyer': Room("Foyer", """Dim light filters in from the south. Dusty
'foyer': Room("Foyer", "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
'overlook': Room("Grand Overlook", "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.""", [items["health_potion"]]),

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

'treasure': Room("Treasure Chamber", """You've found the long-lost treasure
'treasure': Room("Treasure Chamber","treasure", """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.""",[items["gold"]]),
}


Expand All @@ -33,6 +55,90 @@
room['narrow'].n_to = room['treasure']
room['treasure'].s_to = room['narrow']

keybindings = {
"n":{
"name":"n_to",
"description":"Move North"
},
"s":{
"name":"s_to",
"description":"Move South"
},
"e":{
"name":"e_to",
"description":"Move East"
},
"w":{
"name":"w_to",
"description":"Move West"
},
"h":{
"name":"help",
"description":"List availble options"
},
"v":{
"name":"view",
"description":"View items in a room"
},
"p":{
"name":"pick",
"description":"Pick up and item in a room"
},
"i":{
"name":"inventory",
"description":"View inventory"
},
"d":{
"name":"drop",
"description":"Drop item from inventory"
}
}

def draw(position):
treasure = "*" if position=="treasure" else " "
outside = "*" if position=="outside" else " "
narrow = "*" if position=="narrow" else " "
foyer = "*" if position=="foyer" else " "
overlook = "*" if position=="overlook" else " "

print("\t\t\t","Overlook","|"," Treasure", "|")
print("\t\t\t | |")
print(f"\t\t\t {overlook} | {treasure} |")
print("\t\t\t | |")
print("\t\t\t-----------------------")
print("\t\t\t"," Foyer ","|"," Narrow ", "|")
print("\t\t\t | |")
print(f"\t\t\t {foyer} | {narrow} |")
print("\t\t\t | |")
print("\t\t\t-----------------------")
print("\t\t\t"," Outside","|"," ", "|")
print("\t\t\t | |")
print(f"\t\t\t {outside} | |")
print("\t\t\t | |")

def welcome():
print(
""" _______ _______ ______ ______ _______
| |_____| | | | |_____] | \ |_____|
|_____ | | | | | |_____] |_____/ | |

_______ ______ _ _ _______ __ _ _______ _ _ ______ _______
|_____| | \ \ / |______ | \ | | | | |_____/ |______
| | |_____/ \/ |______ | \_| | |_____| | \_ |______\n\n\n""")


def view_items(items):
if(len(items) == 0):
print("\nThis room doesn't have any items\n")
else:
[print(f"\n\n\tname: {i.name}\n\tdescription: {i.description}\n\n") for i in items]
input("Hit Return/Enter to continue the game\n\n")

def print_help():
print("Available options are:")
for binding,value in keybindings.items():
desc = value["description"]
print(f"\t{binding} = {desc}")
#
# Main
#
Expand All @@ -49,3 +155,65 @@
# Print an error message if the movement isn't allowed.
#
# If the user enters "q", quit the game.

def main():
os.system('clear')
player1 = Player()
welcome()
while True:
draw(player1.current_room)
user_input = input("\n\nWhat action would you like to do?\t")
user_input = user_input.strip().lower()

if(user_input=="n" or user_input=="s" or user_input=="e" or user_input=="w"):
direction = keybindings[user_input]["name"]
next_room = room[player1.current_room].neighbor(direction)
if(next_room):
if(next_room == "overlook" ):
player1 = Warrior.from_human(player1)
print(player1.type)
print("Congrats, your're a Warrior")
input("Hit Return/Enter to continue the game\n\n")
player1.current_room = next_room
os.system('clear')
continue
else:
print("There is no room available in that direction\n\tor the desired room is not avaible in that direction\n\n")
input("Hit Return/Enter to continue the game\n\n")
os.system("clear")
continue
elif(user_input=="q"):
print("\n\nThank You for playing Lamba Adventure\n\n")
time.sleep(.7)
os.system('clear')
break
elif(user_input == "v"):
view_items(room[player1.current_room].list_items())
os.system('clear')
elif(user_input == "p"):
player1.get_item(room[player1.current_room])
input("\nHit Return/Enter to continue the game")
os.system('clear')
elif(user_input == "d"):
player1.drop_item(room[player1.current_room])
input("\nHit Return/Enter to continue the game")
os.system('clear')
elif(user_input=="h" or user_input=="help"):
print_help()
input("\nHit Return/Enter to continue the game")
os.system("clear")
continue
elif(user_input=="i"):
player1.view_items()
input("\nHit Return/Enter to continue the game")
os.system("clear")
continue
else:
print("Input was not recognized")
print_help()
input("\nHit Return/Enter to continue the game")
os.system("clear")
continue

if __name__ == '__main__':
main()
7 changes: 7 additions & 0 deletions src/item.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## The item should have `name` and `description` attributes.
class Item:
def __init__(self,name,description):
self.name = name
self.description = description
def __str__(self):
return self.name
55 changes: 55 additions & 0 deletions src/player.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,57 @@
# Write a class to hold player information, e.g. what room they are in
# currently.
class Player:
def __init__(self,name="Player 1",current_room="outside"):
self.name = name
self.current_room = current_room
self.items = []

def get_item(self,room):
if(len(room.items) == 0):
print("\nThere are no items to pick up in this room")
else:
user_input = input("\nWhat item would like to pick up?\t")
for x in room.items:
if(x.name == user_input):
requested_item = x
room.remove_item(x)
self.items.append(x)
print(f"\n{requested_item.name} was picked up")
else:
print("\nThat item is not in the room")

def drop_item(self,room):
if(len(self.items) == 0):
print("\nThere are no items to drop")
else:
user_input = input("\nWhat item would like to drop?\t")
for i,x in enumerate(self.items):
if(x.name == user_input):
requested_item = x
room.add_item(x)
self.items.pop(i)
print(f"\n{requested_item.name} was dropped up")
else:
print("\nThat item is not in the room")

def view_items(self):
if(len(self.items) == 0):
print("\n\tYou have nothing in your inventory\n")
else:
print("\nInventory:")
[print(f"\n\t{x.name}\n") for x in self.items]

class Warrior(Player):
def __init__(self,newClass=None):
if(newClass is None):
print("if")
super().__init__()
else:
print("else")
super().__init__(name=newClass.name,current_room=newClass.current_room)

self.type = "Warrior"

@classmethod
def from_human(cls,obj):
return cls(obj)
44 changes: 43 additions & 1 deletion src/room.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,44 @@
# Implement a class to hold room information. This should have name and
# description attributes.
# description attributes.

class Room:
room_instances = 0

def __init__(self,name,nickname,description,items=None):
self.name = name
self.nickname = nickname
self.description = description
self.n_to = None
self.s_to = None
self.e_to = None
self.w_to = None
if(items==None):
self.items = []
else:
self.items = items

Room.room_instances +=1

def neighbor(self,direction):
next_room = getattr(self,direction)
if(next_room):
return next_room.nickname
else:
return None

def list_items(self):
return self.items

def add_item(self,item):
return self.items.append(item)

def remove_item(self,item):
return self.items.remove(item)


@classmethod
def room_amount(cls):
return cls.room_instances

def __str__(self):
print(f"Name {self.name}\nDescription {self.description}")