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
20 changes: 20 additions & 0 deletions Pipfile.lock

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

136 changes: 131 additions & 5 deletions src/adv.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,36 @@
from room import Room
from player import Player
from money import Money
from weapon import Weapon
from armor import Armor
import random

# Declare all the rooms

gold_outside = random.randint(1, 50)
gold_foyer = random.randint(1, 50)
gold_overlook = random.randint(1, 50)
gold_narrow = random.randint(1, 50)
gold_treasure = random.randint(100, 500)

room = {
'outside': Room("Outside Cave Entrance",
"North of you, the cave mount beckons"),
"North of you, the cave mount beckons",
[Money("Coins", f"A sack of {gold_outside} [Coins]", gold_outside), Weapon("Sword", "A Rusted Iron [Sword]", 5)]),

'foyer': Room("Foyer", """Dim light filters in from the south. Dusty
passages run north and east."""),
passages run north and east.""", [Money("Coins", f"A sack of {gold_foyer}[Coins]", gold_foyer), Armor("Shield", "A rusty iron [Shield].", 5)]),

'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.""", [Money("Coins", f"A sack of {gold_overlook}[Coins]", gold_overlook), Armor("Chestplate", "A rusty iron [Chestplate]", 10)]),

'narrow': Room("Narrow Passage", """The narrow passage bends here from west
to north. The smell of gold permeates the air."""),
to north. The smell of gold permeates the air.""", [Money("Coins", f"A sack of {gold_narrow}[Coins]", gold_narrow), Armor("Helm", "A rusty iron [Helm]et", 3)]),

'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.""", [Money("Coins", f"A sack of {gold_treasure}[Coins]", gold_treasure), Armor("Boots", "A pair of moldy [Boots]", 2)]),
}


Expand All @@ -38,6 +50,7 @@
#

# Make a new player object that is currently in the 'outside' room.
player = Player(room['outside'])

# Write a loop that:
#
Expand All @@ -49,3 +62,116 @@
# Print an error message if the movement isn't allowed.
#
# If the user enters "q", quit the game.
game = True
print(f'\n\nYou are in the {player.current_room.name}. \n {player.current_room.desc}\n')

while game == True:
direction = input("\nPlease enter direction ([n]orth [s]outh [e]ast [w]est [search] [i]nventory [eq]uipment [st]atus [q]uit):\n")

if direction == 'n':
player.move(direction)

elif direction == 'e':
player.move(direction)

elif direction == 's':
player.move(direction)

elif direction == 'w':
player.move(direction)

elif direction == 'search':
interact = True
while interact == True:
if len(player.current_room.items) == 0:
print("\nThere is nothing of importance")
interact = False

else:
player.look()
x = [str(x) for x in input("\nWhich loot would you like to take? ([take] [item] or [all] [none]): \n").split()]

if len(x) == 2:
if x[0] != 'take':
print("\n***Please choose from available commands***\n")
else:
player.take(x[1])

elif len(x) == 1:
if x[0] == 'all':
print("\nYou put all the items in your inventory")
for i in player.current_room.items:
if i.__class__.__name__ == "Money":
player.gold += i.amount
del player.current_room.items[0:0]
if i.__class__.__name__ == "Weapon":
player.inv.append(i)
if i.__class__.__name__ == "Armor":
player.inv.append(i)
del player.current_room.items[:]

interact = False

elif x[0] == 'none':
interact = False

else:
print("\n***Please choose from available commands***\n")

elif direction == 'i':

inventory = True

while inventory == True:

print(f"\nGold: {player.gold}")

print(f"Inventory:")
for i in player.inv:
print(f'[{i}]')

x = [str(x) for x in input("\n([drop/equip] [item] or [c]lose)\n").split()]

if len(x) == 2:

if x[0] == 'equip':
player.equip(x[1])

elif x[0] == 'drop':
player.drop(x[1])

else:
print("\n***Please choose from available commands***\n")

elif len(x) == 1:

if x[0] != 'c':
print("\n***Please choose from available commands***\n")
else:
inventory = False

else:
print("\n***Please choose from available commands***\n")

elif direction == 'eq':
equipment = True
while equipment == True:
if len(player.equipment) == 0:
print("You have nothing equipped")
equipment = False
else:
for i in player.equipment:
if i.__class__.__name__ == "Weapon":
print(f"{i.iname}: attack({i.rating})")
elif i.__class__.__name__ == "Armor":
print(f"{i.iname}: armor({i.rating}")

elif direction == 'st':
print(f"Name: {player.name}\nHealth: {player.hp}\nAttack: {player.att}\nDefense: {player.defense}")


elif direction == 'q':
game = False

else:
print("\n***Please choose from available commands***\n")
9 changes: 9 additions & 0 deletions src/armor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from item import Item

class Armor(Item):

def __init__(self, iname, idesc, rating):
super().__init__(iname, idesc)
self.iname = iname
self.idesc = idesc
self.rating = rating
6 changes: 6 additions & 0 deletions src/attributes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Attributes:

def __init__(self, att, hp, defense):
self.att = att
self.hp = hp
self.defense = defense
9 changes: 9 additions & 0 deletions src/enemy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from attributes import Attributes

class Enemy(Attributes):

def __init__(self, name, att, hp):
super().__init__(att, hp)
self.name = name
self.att = att
self.hp = hp
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, iname, idesc):
self.iname = iname
self.idesc = idesc

def __str__(self):
return "{}".format(self.iname)
10 changes: 10 additions & 0 deletions src/money.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from item import Item
import random

class Money(Item):

def __init__(self, iname, idesc, amount):
super().__init__(iname, idesc)
self.iname = iname
self.idesc = idesc
self.amount = amount
77 changes: 77 additions & 0 deletions src/player.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,79 @@
# Write a class to hold player information, e.g. what room they are in
# currently.
from attributes import Attributes
from weapon import Weapon
from armor import Armor
from money import Money

class Player(Attributes):
def __init__(self, current_room, inv=None, equipment=None, gold=0, att=1, hp=20, defense=0):
super().__init__(att, hp, defense)
self.name = "Player"
self.current_room = current_room
if inv is None:
self.inv = []
else:
self.inv = inv
if equipment is None:
self.equipment = []
else:
self.equipment = equipment
self.gold = gold
self.att = att
self.hp = hp
self.defense = defense

def move(self, direction):
next_room = getattr(self.current_room, f'{direction}_to')
if next_room == None:
print("\n***You cannot go in that direction***\n")
elif next_room is not None:
self.current_room = next_room
print(f'\nYou enter the {self.current_room.name}. \n {self.current_room.desc}\n')

def look(self):
if len(self.current_room.items) > 0:
print("\nYou look around and see: ")
for i in self.current_room.items:
print(f'{i.idesc}')
else:
print("\nThere is nothing of importance")


def take(self, item):
for i in self.current_room.items:
if i.iname != item:
print("\n***You do not see that here***\n")
elif i.__class__.__name__ == "Money":
self.gold = self.gold + i.amount
self.current_room.items.remove(i)
else:
print(f"You put the {i.iname} in your inventory")
self.inv.append(i)
self.current_room.items.remove(i)

def drop(self, item):
for i in self.inv:
if i.iname != item:
print("You do not have that item in your inventory")
else:
print(f"You drop your {i.iname}")
self.inv.remove(i)
self.current_room.items.append(i)

def equip(self, item):
for i in self.inv:
if i.iname != item:
print(f"You do not have a {item}")
elif i.__class__.__name__ == "Weapon":
print(f"You equip the {i.iname}")
self.equipment.append(i)
self.inv.remove(i)
self.att += i.rating
elif i.__class__.__name__ == "Armor":
print(f"You equip the {i.iname}")
self.equipment.append(i)
self.inv.remove(i)
self.defense += i.rating
else:
print("You cannot equip that")
17 changes: 16 additions & 1 deletion src/room.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
# Implement a class to hold room information. This should have name and
# description attributes.
# description attributes.
from item import Item

class Room(Item):
def __init__(self, name, desc, items=None):
self.name = name
self.desc = desc
self.n_to = None
self.e_to = None
self.s_to = None
self.w_to = None

if items is None:
self.items = []
else:
self.items = items
9 changes: 9 additions & 0 deletions src/weapon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from item import Item

class Weapon(Item):

def __init__(self, iname, idesc, rating):
super().__init__(iname, idesc)
self.iname = iname
self.idesc = idesc
self.rating = rating