Skip to content

Daniel gipson #513

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 2 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
74 changes: 74 additions & 0 deletions src/adv.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
from room import Room
from player import Player
from item import Item
from secret import Secret
from writing import Writing

# Declare all the rooms

Expand All @@ -19,6 +23,10 @@
'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."""),

'hollow': Room("Secret Hollow", """A few dozen feet down the cliff you come upon
a hollow space in the face of the cliff. As the wind howls you see sitting on
an ancient altar is a solid gold monkey idol with diamond eyes""")
}


Expand All @@ -29,15 +37,37 @@
room['foyer'].n_to = room['overlook']
room['foyer'].e_to = room['narrow']
room['overlook'].s_to = room['foyer']
room['overlook'].c_to = room['hollow']
room['narrow'].w_to = room['foyer']
room['narrow'].n_to = room['treasure']
room['treasure'].s_to = room['narrow']
room['hollow'].c_to = room['overlook']

# Create items
sword = Secret('Sword', 3, 12)
diamond = Item('Diamond', 30)
wand = Secret('Wand', 30, 45)
shield = Item('Shield', 4)
note = Writing('Note', 0, '"Check out the Cliff to \ndiscover a secret treasure"')
idol = Item('Solid gold idol', 500)


# Add items to rooms
room['foyer'].secrets.append(sword)
room['narrow'].secrets.append(wand)
room['narrow'].items.append(shield)
room['overlook'].items.append(diamond)
room['treasure'].items.append(note)

# Add secrets to rooms


#
# Main
#

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

# Write a loop that:
#
Expand All @@ -49,3 +79,47 @@
# Print an error message if the movement isn't allowed.
#
# If the user enters "q", quit the game.

playing = None
menu = input(f'Welcome to Darkest Dungeons! To play press p to quit press q\n')
if menu == 'q':
print('Thanks For Playing!')
playing = False
elif menu == 'p':
print('\nEnter n, s, e, w to go in any of the cardinal directions available in each room!\nTo investigate a room enter i')
playing = True
while playing:
action = input(f'\n{player1.currentRoom}choose a direction or investigate!\n')

if action == 'n' and player1.currentRoom.n_to != None:
player1.currentRoom = player1.currentRoom.n_to

elif action == 's' and player1.currentRoom.s_to != None:
player1.currentRoom = player1.currentRoom.s_to

elif action == 'e' and player1.currentRoom.e_to != None:
player1.currentRoom = player1.currentRoom.e_to

elif action == 'w' and player1.currentRoom.w_to != None:
player1.currentRoom = player1.currentRoom.w_to

elif action == 'c' and player1.currentRoom.c_to != None:
player1.currentRoom = player1.currentRoom.c_to

elif action == 'i':
player1.investigate()

elif action == 'p':
item = input('Enter item\'s name ')
for thing in player1.currentRoom.items:
if item == thing.name and thing.hidden == False:
player1.get(item)
else:
print(f'There is no {item} to pick up')

elif action == 'q':
print('\nThanks For Playing')
playing = False

else:
print('\nPlease choose a valid direction!')
11 changes: 11 additions & 0 deletions src/item.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Item:
def __init__(self, name, value):
self.name = name
self.value = value
self.hidden = False

def __str__(self):
return f'\nname: {self.name} \nvalue: {self.value}'

def makeSecret(self):
self.hidden = True
27 changes: 27 additions & 0 deletions src/player.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,29 @@
# Write a class to hold player information, e.g. what room they are in
# currently.
import random

class Player:
def __init__(self, currentRoom):
self.currentRoom = currentRoom
self.inventory = []

def get(self, item):
if len(self.inventory) < 4 and item.hidden == False:
self.inventory.append(item)
self.currentRoom.items.remove(item)
print(f'Picked up {item.name}')
elif item.hidden == False:
print(f'There is no {item}')
elif self.inventory >= 4:
print(f'Can\'t pick up {item.name}, inventory full')

def drop(self, item):
self.inventory.remove(item)

def investigate(self):
search = random.randint(0, 100)

for secret in self.currentRoom.secrets:
if secret.difficulty <= search:
secret.hidden = False
print(f'Found: \n{secret} \nTo pick up enter "{secret.name}"')
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.

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

def __str__(self):
return f'Location: {self.name} \n{self.description}\n'
8 changes: 8 additions & 0 deletions src/secret.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from item import Item

class Secret(Item):
def __init__(self, name, value, difficulty):
self.name = name
self.value = value
self.hidden = True
self.difficulty = difficulty
10 changes: 10 additions & 0 deletions src/writing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from item import Item

class Writing(Item):
def __init__(self, name, value, text):
super().__init__(name, value)
self.text = text
self.hidden = False

def read(self):
print(self.text)