Skip to content
Open
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.vscode
*.pyc
__pycache__
__pycache__
*.dat
*.numbers
28 changes: 0 additions & 28 deletions examples/guessing_game.py

This file was deleted.

1 change: 0 additions & 1 deletion examples/history.txt

This file was deleted.

79 changes: 0 additions & 79 deletions examples/rock_paper_scissors.py

This file was deleted.

192 changes: 153 additions & 39 deletions src/adv.py
Original file line number Diff line number Diff line change
@@ -1,51 +1,165 @@
from room import Room
import textwrap
import os.path as path
from datamanager import DataManager, Reporter
from vars import synonyms, opposites, directions
import pcolors as p
from item_functions import sb
from npc_controller import NPCController

# 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."""),
class Adventure:
def __init__(self, data_manager):
self.player = data_manager.data['player']
self.data = data_manager.data
self.data_manager = data_manager
sb.set_datamanager(data_manager)
self.npc_controller = NPCController(data_manager)
self.reporter = Reporter(self.player)
sb.set_reporter = self.reporter
for npc in self.data.get('npcs'):
self.data['npcs'][npc].reporter = self.reporter

'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."""),
def mainLoop(self):
self.show_room()
self.get_input()
self.npc_controller.step()

'narrow': Room("Narrow Passage", """The narrow passage bends here from west
to north. The smell of gold permeates the air."""),
def show_room(self):
current_room = self.player.current_room
if current_room.is_lit(self.player):
p.prGreen('\n{}\n'.format(current_room.name))
if current_room.first_visit:
print(textwrap.fill(current_room.description))
# current_room.first_visit = False
if len(current_room.contents) > 0:
p.prYellow('You see here:')
for item in current_room.contents:
print(item.long_name)
if len(current_room.characters) > 1:
p.prYellow('Also here:')
for char in current_room.characters:
if char is not self.player:
print(char.name)
if len(current_room.visible_exits) > 0:
string = ', '.join(current_room.visible_exits)
p.prYellow('Visible exits: {}'.format(string))

'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."""),
}
else:
p.prGrey('\nIt is dark here.\n')

def rm_extra_words(self, split):
if len(split) > 1:
for word in split:
if word in synonyms['-']:
split.remove(word)
return split

# Link rooms together
def god_commands(self,entry,split,spRaw):
if split[0] == '@TEL':
target = self.data['rooms'].get(split[1].lower())
if target is not None:
self.player.current_room.characters.remove(self.player)
self.player.current_room = target
target.characters.append(self.player)
else:
print("That location is unknown to me.")
elif entry == '@COLORS':
p.show_colors()
elif split[0] == '@CLONE':
target = self.data['items'].get(split[1].lower())
if target is not None:
self.player.current_room.add_item(target)
else:
print("I can't find that.")
elif split[0] == '@SUMMON':
target = self.data['npcs'].get(split[1].lower())
if target is not None:
target.current_room.characters.remove(target)
target.current_room = self.player.current_room
self.player.current_room.characters.append(target)
p.prGreen('Summoned {}'.format(target.long_name))
else:
print("I don't know who you mean.")
elif split[0] == '@DESTROY':
target = self.player.has_item(split[1])
if target is not None:
p.prRed('Destroyed {}'.format(target.long_name))
self.player.inventory.remove(target)
else:
target = self.player.current_room.has_item(split[1])
if target is not None:
p.prRed('Destroyed {}'.format(target.long_name))
self.player.current_room.contents.remove(target)
else:
print("I can't find that.")
elif split[0] == '@FORCE':
target = self.data['npcs'].get(split[1].lower())
if target is not None:
target.force(spRaw)
else:
print("I don't know who you mean.")

room['outside'].n_to = room['foyer']
room['foyer'].s_to = room['outside']
room['foyer'].n_to = room['overlook']
room['foyer'].e_to = room['narrow']
room['overlook'].s_to = room['foyer']
room['narrow'].w_to = room['foyer']
room['narrow'].n_to = room['treasure']
room['treasure'].s_to = room['narrow']
def get_input(self):
raw = p.inNiceBlue('\nWhat do you do now? ')
if raw == '':
return
entry = raw.upper()
split = self.rm_extra_words(entry.split(' '))
spRaw = raw.split(' ')
if entry[0] == '@':
self.god_commands(entry, split, spRaw)
elif entry in synonyms['Q']:
self.data_manager.store_data()
exit()
elif entry in synonyms['I']:
self.player.pack()
elif split[0] in synonyms['GET']:
self.player.take(split[-1])
elif split[0] in synonyms['DROP']:
self.player.drop(split[-1])
elif split[0] in synonyms['USE']:
self.player.use(split[-1])
elif split[0] in synonyms['SAY']:
self.player.say(spRaw)
elif split[0] in synonyms['L']:
if len(split) > 1 and split[-1] not in synonyms['ROOM']:
self.player.look(split[-1])
else:
self.player.current_room.first_visit = True
else:
for direction in directions:
if entry in synonyms[direction]:
self.player.go(direction)
return()
print('\nI don\'t know what you mean.')

#
# Main
#

# Make a new player object that is currently in the 'outside' room.
def adventure():
data = {}
loaded = False
name = input("What is your name, adventurer? ")
if name == '':
name = 'an adventurer'
print('Welcome, adventurer.')
else:
print('Welcome, {}.'.format(name))
data_manager = DataManager(name)
if path.exists(data_manager.get_filename()):
entry = input('I see you have a saved game. Would you like to load it? (Y/n)').upper()
if entry in synonyms['YES']:
data_manager.load_data()
loaded = True
else:
data_manager.load_defaults()
else:
data_manager.load_defaults()
if not loaded:
data_manager.data['player'].name = name
game = Adventure(data_manager)
while True:
game.mainLoop()

# Write a loop that:
#
# * Prints the current room name
# * Prints the current description (the textwrap module might be useful here).
# * Waits for user input and decides what to do.
#
# If the user enters a cardinal direction, attempt to move to the room there.
# Print an error message if the movement isn't allowed.
#
# If the user enters "q", quit the game.

if __name__ == '__main__':
adventure()
11 changes: 11 additions & 0 deletions src/data/items.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Name,Long Name,Description,Rooms,ILF,On,
crystal,a glowing purple crystal,"This little crystal glows with a pleasant purple light. It’s not bright enough to light up the room, but it is very soothing to look at.",crystal,I,N,
stream,the stream,"The stream is small, but swift. It looks shallow enough to cross, but the cliff on the other side is unclimbable.",streambed bottom beach,F,N,
beach,the beach,"A little strip of sand by the stream, it’s generous to call this a beach. The sun barely makes its way down here, so there is no sunbathing either.",beach,F,N,
lantern,a lantern,An old miner’s lantern,foyer,L,Y,
knife,a rusty knife,It's an old rusty knife. You don't think it would cut very well.,foyer,I,N,
rope,an old rope,"It looks like someone used this a very long time ago. It is worn and fraying. It might just hold your weight, but it could give out any moment.",bottom cliffside overlook,F,N,
flashlight,a flashlight,It's a flashlight.,outside,L,N,
cave,the cave,"Jagged stalactites hang from the roof of the cave, reminding you of some grotesque beast's fangs.",outside foyer second,F,N,
cliff,the edge of the cliff,The edge of the cliff is frightening. The cliff descends many meters. A length of rope dangles down into the depths.,overlook,F,N,
key,a key,It's a simple brass key. I wonder what lock it belongs to.,beach,I,N,
2 changes: 2 additions & 0 deletions src/data/npcs.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Tag,Name,Long Name,Description,Starting Room,Inventory,Mobile,Fence,Sayings,Talkative,Poses,Actions,,
alfred,Alfred,Lord Alfred,"A tall, slender man, Lord Alfred somewhat resembles a hawk. His eyes scan over you like a predator. His long, pointed nose resembles the beak of a raptor.",outside,lantern,5,0,I wonder where I put that key.|There’s always somebody snooping about around here.,5,frowns.|clears his throat.,10 take key|5 steal key|4 drop key,,
22 changes: 22 additions & 0 deletions src/data/rooms.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Tag,Name,Description,Lit,Paths,,
narrow2,A Narrow Passageway,This part of the cave is a tight squeeze. You can barely breathe from the closeness of the rock walls and the smell of something long dead. The narrow path leads north and west.,N,w.second.h n.narrow3,,
narrow3,A Narrow Passageway,"Narrow and dark, it’s spooky in here, especially because you can’t see what’s around the bend. It’s hot, too. The passageway forks here, and tight openings lead north, south, and east. A bubbling sound can be heard to the north.",N,s.narrow2 n.pools,,
pools,The Hot Pools,Hot steam bubbles up from the three geothermal xi[pools]x in this room.,N,s.narrow3,,
ncavern,North Cavern,The path opens into a huge cavern. You can hear your movements echo among the pillars and stalactites. The path winds through the middle of this chamber into the other half of the cavern to the south. A small opening leads west.,N,w.narrow3 s.scavern,,
scavern,South Cavern,"The cave features on this half of the cavern display layers of colors, all slightly muted but amazing all the same. The path winds through the middle of the cavern to the northern half of the chamber. Another small opening leads to the southeast.",N,se.narrow,,
outside,Outside Cave Entrance,"The breeze blows through the trees. Birds chirp and squabble in the canopy. North of you, the xi[cave]x mouth beckons. An unpleasant odor emanates from it.",Y,n.foyer,,
foyer,Just Inside the Cave,Dim light filters in from the south. The cave continues north.,Y,s.outside n.second,,
overlook,Grand Overlook,"A steep xi[cliff]x 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. An old xi[rope]x is tied to a tree and dangles down into the ravine.",Y,d.cliffside,,
narrow,Narrow Passage,The narrow passage bends here from northwest to north. The smell of gold permeates the air.,N,,,
treasure,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.",Y,,,
cliffside,On the Side of the Cliff,"You've found an old, fraying xi[rope]x to climb the cliff. The winds buffet you and make the climb difficult.",Y,u.overlook d.bottom,,
bottom,Bottom of the Canyon,"Here at the bottom of the canyon, everything is peaceful. A xi[stream]x runs through the canyon. You might be able to follow it west. The cliff on the opposite side looks unclimbable. There is an old, fraying xi[rope]x here, leading up.",Y,u.cliffside w.streambed,,
streambed,Along the Stream,"Following the xi[stream]x is a bit tricky, with all the rocks here. The path leads east and west.",Y,e.bottom w.beach,,
beach,Beach,A small xi[beach]x at the side of the xi[stream]x. A path follows the stream east.,Y,e.streambed,,
second,Further Into the Cave,Dark shadows hide all the pits in the floor. You had better stick to the path if you don't want to twist an ankle. The path goes north and south.,N,n.third,,
third,In the Cave,The dark path twists and winds between stalagmites. You see openings to the west and south.,N,w.forth,,
forth,In the Cave,"The cave is worn smooth here, as if from the passage of some great beast. The path exits to the northwest and east.",N,nw.fifth,,
fifth,In the Cave,"The cave is tight here, and it's tough to move. A gentle purple light comes from the south. Sounds of water trickling come from the north. You can see exits to the north, south, and southeast.",N,s.crystal n.sixth,,
crystal,The Crystal Cavern,"A gentle purple light envelopes you as hundreds of thousands of crystals in the walls, floor, and ceiling glow violet. A sense of peace settles on you. The only exit is to the north, but why would anyone want to leave this beautiful place.",Y,n.fifth,,
sixth,In the Cave,The cave is worn smooth here. The sound of trickling water comes from the chamber to the northeast. Another opening leads to the south.,N,ne.seventh,,
seventh,In the Cave,Light and the smell of fresh air filter in from the north. A deep darkness and an unpleasant odor emanate from the cave to the southwest.,Y,n.overlook,,
Loading