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
72 changes: 36 additions & 36 deletions advent.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
# vim: et sw=2 ts=2 sts=2

# for Python3, use:
# import urllib.request as urllib2
import urllib2
import urllib.request as urllib2
#import urllib2

import random
import string
Expand Down Expand Up @@ -530,7 +530,7 @@ def print_output(self, text, message_type = 0):
if self.http_output:
self.http_text += self.style_text(text, message_type) + "\n"
else:
print self.style_text(text, message_type)
print(self.style_text(text, message_type))

# checks to see if the inventory in the items list is in the user's inventory
def inventory_contains(self, items):
Expand Down Expand Up @@ -619,7 +619,7 @@ def run_step(self, cmd = None):
# get input from the user
try:
self.output("") # add a blank line
user_input = raw_input("> ")
user_input = input("> ")
except EOFError:
return False

Expand Down Expand Up @@ -661,9 +661,9 @@ def run_step(self, cmd = None):
if words[0].lower() == 'tell' and len(words) > 2:
(target_name, words) = get_noun(words[1:], actor.location.actors.values())

things = actor.inventory.values() + \
actor.location.contents.values() + \
actor.location.exits.values() + \
things = list(actor.inventory.values()) + \
list(actor.location.contents.values()) + \
list(actor.location.exits.values()) + \
list(actor.location.actors.values()) + \
[actor.location] + \
[actor]
Expand Down Expand Up @@ -1079,7 +1079,7 @@ def go(self, actor, way):

def debug(self):
for key in self.exits:
print "exit: %s" % key
print("exit: %s" % key)


# A "connection" connects point A to point B. Connections are
Expand Down Expand Up @@ -1420,7 +1420,7 @@ def start_running(self):
def start_checking(self):
assert self.running
assert not self.recording
print "check_responses on"
print("check_responses on")
self.check_responses = True
self.current_response = ""

Expand Down Expand Up @@ -1513,10 +1513,10 @@ def set_next_response(self, response):
def print_script(self):
i = 0
for command in self.commands:
print "> " + command
print("> " + command)
if command == "end":
break
print self.responses[i]
print(self.responses[i])
i = i + 1

def save_file(self):
Expand Down Expand Up @@ -1606,11 +1606,11 @@ def act_start_recording(self, actor, noun, words):

def act_run_script(self, actor, noun, words):
if self.current_script:
print "You must stop \"%s\" first." % (self.current_script.name)
print("You must stop \"%s\" first." % (self.current_script.name))
script_name = self.parse_script_name(noun)
if not script_name in self.scripts:
print "%s can't find script \"%s\" in its memory." % (self.name,
script_name)
print("%s can't find script \"%s\" in its memory." % (self.name,
script_name))

return True;

Expand All @@ -1631,30 +1631,30 @@ def act_check_script(self, actor, noun, words):
def act_print_script(self, actor, noun, words):
script_name = self.parse_script_name(noun)
if not script_name in self.scripts:
print "%s can't find script \"%s\" in its memory." % (self.name,
script_name)
print("%s can't find script \"%s\" in its memory." % (self.name,
script_name))
return True

print "----------------------8<-------------------------\n"
print "# Paste the following into your game code in order"
print "# to be able to run this script in the game:"
print "%s_script = Script(\"%s\"," % (script_name, script_name)
print "\"\"\""
print("----------------------8<-------------------------\n")
print("# Paste the following into your game code in order")
print("# to be able to run this script in the game:")
print("%s_script = Script(\"%s\"," % (script_name, script_name))
print("\"\"\"")
self.scripts[script_name].print_script()
print "\"\"\")"
print "\n# Then add the script to a player, or a robot"
print "# with code like the following:"
print "player.add_script(%s_script)" % script_name
print "\n# Now you can run the script from within the game"
print "# by typing \"run %s\"" % script_name
print "\n---------------------->8-------------------------"
print("\"\"\")")
print("\n# Then add the script to a player, or a robot")
print("# with code like the following:")
print("player.add_script(%s_script)" % script_name)
print("\n# Now you can run the script from within the game")
print("# by typing \"run %s\"" % script_name)
print("\n---------------------->8-------------------------")
return True

def act_save_file(self, actor, noun, words):
script_name = self.parse_script_name(noun)
if not script_name in self.scripts:
print "%s can't find script \"%s\" in its memory." % (self.name,
script_name)
print("%s can't find script \"%s\" in its memory." % (self.name,
script_name))
return True
self.scripts[script_name].save_file()
return True
Expand All @@ -1676,31 +1676,31 @@ def set_think_time(self, actor, noun, words):
self.script_think_time = t
return True

print "\"think\" requires a number of seconds (0.0000-60.0000) as an argument"
print("\"think\" requires a number of seconds (0.0000-60.0000) as an argument")
return True

def get_next_script_command(self):
if not self.current_script or not self.current_script.running:
return None
line = self.current_script.get_next_command()
if not line:
print "%s %s done running script \"%s\"." % (self.name,
print("%s %s done running script \"%s\"." % (self.name,
self.isare,
self.current_script.name)
self.current_script.name))
self.current_script = None
return None
if self.script_think_time > 0:
time.sleep(self.script_think_time)
line = self.name + ": " + line
print "> %s" % line
print("> %s" % line)
return line

def set_next_script_command(self, command):
if not self.current_script:
return True
if not self.current_script.set_next_command(command):
print "%s finished recording script \"%s\"." % (self.name,
self.current_script.name)
print("%s finished recording script \"%s\"." % (self.name,
self.current_script.name))
self.current_script = None
return False
return True
Expand Down
34 changes: 17 additions & 17 deletions bwx-game.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def reception_description(self):
# function. "def" defines a function in Python.
def scream(self, actor, noun, words):
all_words = [noun] + words
print "You hear a scream '%s'." % ' '.join(all_words)
print("You hear a scream '%s'." % ' '.join(all_words))
return True

sidewalk.add_verb(Verb(scream, 'scream'))
Expand Down Expand Up @@ -159,10 +159,10 @@ def scream(self, actor, noun, words):
# add a custom actor verb (in this case for the hero)
def throw(self, actor, noun, words):
if noun and actor.get_verb('drop').act(actor, noun, words):
print 'The %s bounces and falls to the floor' % noun
print('The %s bounces and falls to the floor' % noun)
return True
else:
print 'You hurt your arm.'
print('You hurt your arm.')
return False

hero.add_verb(Verb(throw, 'throw'))
Expand Down Expand Up @@ -207,7 +207,7 @@ def useless_hit_with_object(self, actor, noun, words):
# SESSION: available to the specific palyer in the specific adventure in the specific session
def scribble(self, actor, noun, words):
if not noun or words:
print "You can only scrible a single word."
print("You can only scrible a single word.")
return False
share.put(share.ADVENTURE, 'crumb.' + actor.location.name, noun.strip())
return True
Expand All @@ -218,9 +218,9 @@ def scribble(self, actor, noun, words):
def peek(self, actor, noun, words):
v = share.get(share.ADVENTURE, 'crumb.' + actor.location.name)
if not v:
print 'Nothing here.'
print('Nothing here.')
return False
print 'Someone scribbled "%s" here.' % v
print('Someone scribbled "%s" here.' % v)
return True

hero.add_verb(Verb(peek, 'peek'))
Expand All @@ -229,19 +229,19 @@ def peek(self, actor, noun, words):
def more(self, actor, noun, words):
loc_name = "_".join(actor.location.name.split(' '))
share.increment(share.ADVENTURE, 'count.' + loc_name)
print 'The count is %s!' % share.get(share.ADVENTURE, 'count.' + loc_name)
print('The count is %s!' % share.get(share.ADVENTURE, 'count.' + loc_name))
return True

def fewer(self, actor, noun, words):
loc_name = "_".join(actor.location.name.split(' '))
share.decrement(share.ADVENTURE, 'count.' + loc_name)
print 'The count is %s!' % share.get(share.ADVENTURE, 'count.' + loc_name)
print('The count is %s!' % share.get(share.ADVENTURE, 'count.' + loc_name))
return True

def reset(self, actor, noun, words):
loc_name = "_".join(actor.location.name.split(' '))
share.delete(share.ADVENTURE, 'count.' + loc_name)
print 'The count is reset!'
print('The count is reset!')
return True

hero.add_verb(Verb(more, 'more'))
Expand All @@ -256,7 +256,7 @@ def flip(self, actor, noun, words):
self.unset_flag('switch_on')
else:
self.set_flag('switch_on')
print "You flip the switch."
print("You flip the switch.")
return True

vestibule.add_verb(Verb(flip, 'flip'))
Expand Down Expand Up @@ -307,7 +307,7 @@ def push(self, actor, noun, words):
return False
w = "_".join(words)
share.push(share.ADVENTURE, 'reception_messages', w)
print "You left a message on the stack of messages."
print("You left a message on the stack of messages.")
return True

reception.add_verb(Verb(push, 'push'))
Expand All @@ -317,10 +317,10 @@ def pop(self, actor, noun, words):
return False
w = share.pop(share.ADVENTURE, 'reception_messages')
if not w:
print "There are no messages on the stack."
print("There are no messages on the stack.")
return False
words = w.split('_')
print "You pull the top message from the stack and read '%s'." % " ".join(words)
print("You pull the top message from the stack and read '%s'." % " ".join(words))
return True

reception.add_verb(Verb(pop, 'pop'))
Expand All @@ -346,19 +346,19 @@ def top(self, actor, noun, words):
return False
w = share.ztop(share.ADVENTURE, 'highscore', 10)
if w:
print "Top Players"
print("Top Players")
for x in w:
print " %s" % x
print(" %s" % x)
return True

def scores(self, actor, noun, words):
if (noun and noun != "scoreboard") or words:
return False
w = share.ztop_with_scores(share.ADVENTURE, 'highscore', 10)
if w:
print "High Scores"
print("High Scores")
for x in w:
print " %s %s" % (x[0], x[1])
print(" %s %s" % (x[0], x[1]))
return True

reception.add_verb(Verb(top, 'top'))
Expand Down
8 changes: 4 additions & 4 deletions graphviz_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def write_as_dot (game, file_name=None):
# define helper for printing to the .dot file
f = open(file_name, 'w') if file_name else None
def _dot (line):
print >> f, line
print(line, file=f)
# get node names by munging loc names (bail if any are dups)
node_name_set = set()
node_name_by_loc = {}
Expand Down Expand Up @@ -95,7 +95,7 @@ def _dot (line):
f.close()

def dump_node_name_by_loc (node_name_by_loc):
print "node_name_by_loc = {"
print("node_name_by_loc = {")
for (loc, node_name) in node_name_by_loc.items():
print ' Location("%s") : "%s"' % (loc.name, node_name)
print "}"
print(' Location("%s") : "%s"' % (loc.name, node_name))
print("}")