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.

97 changes: 82 additions & 15 deletions src/adv.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,55 @@
from room import Room
from player import Player
from item import Item

# Declare all the rooms

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

'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."""),

'narrow': Room("Narrow Passage", """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
'outside': Room(
"Outside Cave Entrance", "North of you, the cave mouth beckons", [
Item('shield', 'rotting wooden shield',
'who would protect themeselves with such a thing', 2, False)
], True),
'foyer': Room(
"Foyer", """Dim light filters in from the south. Dusty passages run north and east.""", [
Item('food', 'sweet roll',
'a rare dessert enjoyed in the north', 1, False),
Item('misc', 'silver chalice',
'suiteable for lords and thieves', 40, False),
Item('currency', 'coin purse', 'treat yo self 2019', 20, False)
], True),
'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.""", [
Item('weapon', 'sword of a thousand truths',
'razor sharp and vibrates in your hand', 10000, False),
Item('misc', 'pebble', 'a pebble', 0, False),
Item('utility', 'rusty lantern',
'the light is dim but it works', 5, True)
], True),
'narrow':
Room(
"Narrow Passage", """The narrow passage bends here from west
to north. The smell of gold permeates the air.""", [
Item(
'misc', 'human skull', 'looks like they had good dental hygiene at least', 5, False)
], False),
'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.""", [
Item(
'currency', 'gold coin', 'a single coin', 1, False),
Item(
'misc', 'tuft of fur', 'from an animal.. probably', 5, False)
], False),
}

# room['outside'].items = ['rotting wooden shield']
# room['foyer'].items = ['sweet roll', 'silver chalice', 'coin purse']
# room['overlook'].items = ['sword of a thousand truths', 'pebble']
# room['narrow'].items = ['human skull']
# room['treasure'].items = ['gold coin', 'tuft of fur']

# Link rooms together

Expand All @@ -39,6 +68,18 @@

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

player = Player(
input('\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n what is your name?\n--> '), room['outside'], [Item(
'clothing', 'thick wool tunic', 'a good tunic for daily needs', 15, False), Item(
'weapon', 'steel sword', 'a good sword, for a peasant', 10, False)])

welcome_message = f'\n\n----\n |WELCOME, {(player.name).upper()}, TO THE THING|'
welcome_message += '\n----\n\n '
welcome_message += 'cmds: n, e, s, w, ln, le, ls, lw, ri, pi, pu [item], d [item]'
welcome_message += '\n\n press q to quit\n\n'
welcome_message += f'{player.current_room}\n\n'
print(welcome_message)

# Write a loop that:
#
# * Prints the current room name
Expand All @@ -49,3 +90,29 @@
# Print an error message if the movement isn't allowed.
#
# If the user enters "q", quit the game.


def start_game(player):
while True:
cmd = input('\n\n--> ')
if cmd is 'q':
break
elif cmd in ['n', 'e', 's', 'w']:
player.traverse(cmd)
elif cmd in ['ri', 'room items']:
player.current_room.print_items()
elif cmd in ['i', 'inventory']:
player.print_inventory()
elif cmd[:8] == 'pick up ' or cmd[:3] == 'pu ':
if cmd[:7] == 'pick up':
player.pick_up(cmd[8:])
else:
player.pick_up(cmd[3:])
elif cmd[:5] == 'drop ' or cmd[:2] == 'd ':
if cmd[:4] == 'drop':
player.drop(cmd[5:])
else:
player.drop(cmd[2:])


start_game(player)
7 changes: 7 additions & 0 deletions src/item.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Item:
def __init__(self, item_type, name, description, value, gives_light):
self.item_type = item_type
self.name = name
self.description = description
self.value = value
self.gives_light = gives_light
46 changes: 46 additions & 0 deletions src/player.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,48 @@
# Write a class to hold player information, e.g. what room they are in
# currently.
from datetime import datetime


class Player:
created_at = datetime.now()

def __init__(self, name, current_room, items):
self.name = name
self.current_room = current_room
self.items = items

def print_inventory(self):
for x in self.items:
print(f'\n - {x.name}')

def traverse(self, cmd):
next_room = self.current_room.get_room_directions(cmd)
if next_room is not None:
self.current_room = next_room
print(self.current_room)
else:
print('\n cant go there')

def pick_up(self, item):
result = None
for x in self.current_room.items:
if x.name == item:
result = x
if result is not None:
self.current_room.items.remove(result)
self.items.append(result)
print(f'\n {item} was added to your inventory')
else:
print(f'\n there is no {item} in here')

def drop(self, item):
result = None
for x in self.items:
if x.name == item:
result = x
if result is not None:
self.items.remove(result)
self.current_room.items.append(result)
print(f'\n {item} was removed from your inventory')
else:
print(f'\n there is no {item} in your inventory')
50 changes: 49 additions & 1 deletion src/room.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,50 @@
# Implement a class to hold room information. This should have name and
# description attributes.
# description attributes.


class Room:

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

def __repr__(self):
return_string = f'\n\n----------------\n\n {self.name}\n\n {self.description}'
return_string += f'\n\n [{self.get_exits()}]'
return return_string

def get_room_directions(self, cmd):
if cmd == 'n':
return self.n_to
if cmd == 'e':
return self.e_to
if cmd == 's':
return self.s_to
if cmd == 'w':
return self.w_to

def get_exits(self):
exits = []
if self.n_to is not None:
exits.append('n')
if self.e_to is not None:
exits.append('e')
if self.s_to is not None:
exits.append('s')
if self.w_to is not None:
exits.append('w')
return ', '.join(exits)

def print_items(self):
if len(self.items) == 0:
print('\n there is nothing in here')
else:
for x in self.items:
print(f'\n - {x.name}')