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
28 changes: 14 additions & 14 deletions Game/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ def move_into(self, room_name):

def prompt(self):
#prints the prompt and returns the input
print "\nWhat do you want to do?"
action = raw_input("> ")
print("\nWhat do you want to do?")
action = input("> ")
return action


def menu_commands(self, command):
#handles straightforward, always-available commands like "quit" and "inv"
self.command = command
if "quit" in self.command:
print "Are you sure? Press Y to quit, any other key to keep playing."
confirmation = raw_input("> ")
print("Are you sure? Press Y to quit, any other key to keep playing.")
confirmation = input("> ")
if confirmation == "Y" or confirmation == "y":
exit(1)
else:
Expand All @@ -62,7 +62,7 @@ def parse_fail(self):
#this should be called as little as possible in favor of more specific errors
#in that vein: tracking of commands that get this response so that I can
#make better resposnes to common unrecognized phrases
print "I'm afraid I don't know what that means."
print("I'm afraid I don't know what that means.")

def inventory_parse(self, command):
#decides whether the command is to take, drop, or use an item and calls the appropriate
Expand All @@ -76,14 +76,14 @@ def inventory_parse(self, command):
self.item_to_try = self.mentioned_in(self.command, self.player.inventory.inv_list)
self.player.drop(self.item_to_try)
else:
print "Inventory parsing error" #should never happen
print("Inventory parsing error") #should never happen


def look_fail(self, command):
#called when a look command doesn't refer to anything
#could be made more interesting by referring to the command
self.command = command
print "You don't see anything like that."
print("You don't see anything like that.")

def parse(self, action):
#breaks commands into categories and then calls an appropriate function
Expand Down Expand Up @@ -114,7 +114,7 @@ def parse(self, action):

def use_words_lookup(self):
self.use_words = ['use']
for label, item in self.player.can_see().iteritems():
for label, item in self.player.can_see().items():
if item.use_words != "":
for word in item.use_words:
self.use_words.append(word)
Expand All @@ -133,7 +133,7 @@ def look_parse(self, command):
self.looked_at = self.mentioned_in(self.command, self.player.can_see())

if self.looked_at.label != 'not_found':
print self.looked_at.description
print(self.looked_at.description)
else:
self.look_fail()

Expand All @@ -148,7 +148,7 @@ def move_parse(self, command):
self.move_into(self.player.new_location)

def look_fail(self):
print "You don't see anything like that here."
print("You don't see anything like that here.")

def use_parse(self, command):
#this is triggered if the command starts with a possible use word
Expand All @@ -161,7 +161,7 @@ def use_parse(self, command):
self.player.use(self.use_item)

def use_fail(self):
print "You don't see any way to do that."
print("You don't see any way to do that.")

def mentioned_in(self, command, items_to_search):
#to use on both exits and items
Expand All @@ -176,7 +176,7 @@ def mentioned_in(self, command, items_to_search):
self.items_to_search = items_to_search
self.success = False

for i, item in self.items_to_search.iteritems():
for i, item in self.items_to_search.items():
for word in self.command:
if word in item.keywords:
self.exit_to_try = item
Expand All @@ -193,6 +193,6 @@ def simulate_play(self, command_list):
self.parse(command)

def victory(self):
print "With a touch of the ignition button, the snowmobile roars with way more power than it needs. You climb on and steer it out into the blinding snow, hoping you will reach civilization while you can still be described as civilized."
print "Congratulations! You are a winner!"
print("With a touch of the ignition button, the snowmobile roars with way more power than it needs. You climb on and steer it out into the blinding snow, hoping you will reach civilization while you can still be described as civilized.")
print("Congratulations! You are a winner!")
exit(1)
16 changes: 8 additions & 8 deletions Game/exits.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import items
from . import items
import csv

class Exit(items.Item):
Expand Down Expand Up @@ -63,7 +63,7 @@ def shall_pass(self, player):
if self.is_open == True:
return(True)
else:
print "The %s is closed." #shouldn't happen
print("The %s is closed.") #shouldn't happen
return(False)

#to create custom "shall pass" behavior, make a substitute method below
Expand All @@ -76,23 +76,23 @@ def main_portal_special(self, player):
self.is_open = True
return(True)
elif self.player.inventory.has('keycard'):
print """
print("""
The reader beeps as the light turns green, and the door swings open. Outside, a howling wind whips
across waist-deep drifts of snow. It's hard to see anything through the blizzard. You don't think
you'd survive long out there without some protection from the cold.
"""
""")
return(False)
else:
print "You think you'll need a keycard to open that door."
print("You think you'll need a keycard to open that door.")
return(False)

def reactor_special(self, player):
self.player = player
if self.player.injected == False:
print "You really don't think it's a good idea to go in there unprotected."
print("You really don't think it's a good idea to go in there unprotected.")
return False
else:
print "You step through the door. You're pretty sure that you wouldn't experience radiation exposure as a slight subdermal tingle, so that's probably your imagination."
print("You step through the door. You're pretty sure that you wouldn't experience radiation exposure as a slight subdermal tingle, so that's probably your imagination.")
return True

def create_exit(config):
Expand Down Expand Up @@ -151,7 +151,7 @@ def special_setup(all_exits):

def populate():
all_exits = {}
f = open('data/exits.csv', 'rb')
f = open('data/exits.csv', 'r')
reader = csv.DictReader(f)

for config in reader:
Expand Down
18 changes: 9 additions & 9 deletions Game/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,32 @@ def remove(self, item):

def has(self, label):
self.label = label
if self.label in self.inv_list.keys():
if self.label in list(self.inv_list.keys()):
return True
else:
return False

def describe(self, item):
self.item = item
if self.has(self.item.label):
print self.item.description
print(self.item.description)
else:
print "You are not carrying a %s.\n" % self.item.name
print("You are not carrying a %s.\n" % self.item.name)

def list(self):
#lists the contents of the inventory
if self.inv_list == {}:
print "You are not carrying anything."
print("You are not carrying anything.")
else:
print "You are carrying:\n"
for i, item in self.inv_list.iteritems():
print item.name
print("You are carrying:\n")
for i, item in self.inv_list.items():
print(item.name)

#these should probably never happen because of how add and remove are called
#as part of mobile.take/drop, which should only be called in pre-screened circumstances

def remove_error(self, item):
print "%s not found in inventory." % self.item.label
print("%s not found in inventory." % self.item.label)

def add_error(self, item):
print "%s already in inventory" % self.item.label
print("%s already in inventory" % self.item.label)
2 changes: 1 addition & 1 deletion Game/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def populate():
#and returns a dictionary of all the items
all_items = {}

f = open('data/items.csv', 'rb')
f = open('data/items.csv', 'r')
reader = csv.DictReader(f)

for row in reader:
Expand Down
8 changes: 4 additions & 4 deletions Game/map.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import items
import exits
import rooms
from . import items
from . import exits
from . import rooms

class Map(object):
def setup(self):
self.all_items = items.populate()
self.all_exits = exits.populate()
self.all_rooms = rooms.populate()

for label, room in self.all_rooms.iteritems():
for label, room in self.all_rooms.items():
room.add_items(self.all_items)
room.add_exits(self.all_exits)
38 changes: 19 additions & 19 deletions Game/map_old.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import items
import exits
import inventory
import mobiles
import rooms
from . import items
from . import exits
from . import inventory
from . import mobiles
from . import rooms

class MainPortal(Exit):
#seems like the best way to implement complicated exit behavior is by tacking on
#a function as part of a subclass. then i can check for the exitence of the
#move_special attribute, then run it.
def move_special(self, inventory):
self.inventory = inventory
if ("keycard" in self.inventory.inventory.keys()) and ("parka" in self.inventory.inventory.keys()):
if ("keycard" in list(self.inventory.inventory.keys())) and ("parka" in list(self.inventory.inventory.keys())):
self.is_open = True
return("outside")
if ("keycard" in self.inventory.inventory.keys()):
print """
if ("keycard" in list(self.inventory.inventory.keys())):
print("""
The reader beeps as the light turns green, and the door swings open. Outside, a howling wind whips
across waist-deep drifts of snow. It's hard to see anything through the blizzard. You don't think
you'd survive long out there without some protection from the cold.
"""
""")
return("central_hallway_east")
else:
print "You think you'll need a keycard to open that door."
print("You think you'll need a keycard to open that door.")
return("central_hallway_east")


Expand All @@ -43,7 +43,7 @@ def pick_up(self, item, room_items):
self.item = item
self.room_items = room_items

print "You pick up the %s." % self.item.name
print("You pick up the %s." % self.item.name)
self.inventory[self.item.label]= self.item
del self.room_items[self.item.label]

Expand All @@ -53,7 +53,7 @@ def drop(self, item, room_items):
self.item = item
self.room_items = room_items

print "You drop the %s." % self.item.name
print("You drop the %s." % self.item.name)

self.room_items[self.item.label]=self.item
del self.inventory[self.item.label]
Expand All @@ -65,23 +65,23 @@ def look(self, command):
if self.item_to_describe == "not_found":
return False
elif self.item_to_describe.look_special == True:
print self.item_to_describe.description
print(self.item_to_describe.description)
return True
self.look_special(self.item_to_describe.label)
#not necessary to pass the item label currently b/c there's only
#one special event per room, but that could change.
else:
print self.item_to_describe.description
print(self.item_to_describe.description)
return True

def list(self):
#lists the contents of the inventory, responds appropriately if inventory is empty
if self.inventory == {}:
print "You are not carrying anything."
print("You are not carrying anything.")
else:
print "You are carrying:"
for i, item in self.inventory.iteritems():
print item.name
print("You are carrying:")
for i, item in self.inventory.items():
print(item.name)


class Kitchen(Room):
Expand Down Expand Up @@ -151,7 +151,7 @@ def mentioned_in(command, items_to_search):
#the keyword list for each item

success = False
for i, item in items_to_search.iteritems():
for i, item in items_to_search.items():
for word in command:
if word in item.keywords:
exit_to_try = item
Expand Down
Loading