Example #1
0
	def do_look(self):
		game.output(self.get_name())
		game.output(self.get_description())
		
		need_desc = filter(lambda t:	isinstance(t, Thing) and 
										t.vars["visible"] and 
										t not in self.vars["described"]
									, self.inside)
		if need_desc:
			game.output("There is %s here." % english.format_list([thing.name.indefinite() for thing in need_desc]))
		
		exits = self.get_exits()
		if exits:
			game.output("Exits: %s" % english.format_list([exit.get_name() for exit in exits]))
Example #2
0
	def do_command(self, cmd):
		def try_cmd(object):
			for command in object.commands.values():
				m = command.get_regex().match(cmd)
				if m is not None:
					if command(*m.groups()): return True
			return False
		
		# Attempt to match the command in the following order:
		# The player, the player's location, items in the player's inventory, items in the player's location.
		listeners = [self, self.location] + self.inventory + self.location.inside
		if self.globalcommands:
			listeners.append(self.globalcommands)
		for thing in listeners:
			if try_cmd(thing): return
		
		# If no match has been found, look for and try do_huh methods on the player and the player's location
		if hasattr(self, "do_huh") and self.do_huh(cmd): return
		if hasattr(self.location, "do_huh") and self.location.do_huh(cmd): return
		
		# As a last ditch, output the player's huh message.
		game.output(self.messages["huh"])
Example #3
0
		def drop():
			if self.location == game.world.protagonist:
				self.move_to(game.world.protagonist.location)
				game.output(self.messages["drop"](thing=self.name))
			else:
				game.output(self.messages["missing"](thing=self.name))
Example #4
0
		def get():
			if self.vars["heavy"]:
				game.output(self.messages["heavy"])
			else:
				self.move_to(game.world.protagonist)
				game.output(self.messages["get"](thing=self.name))
Example #5
0
	def do_look(self):
		game.output(self.get_description())
Example #6
0
		def go():
			game.output(self.messages["go"](direction=self.name) + "\n")
			game.world.protagonist.move_to(self.dest)
			game.world.protagonist.commands["look"]()
Example #7
0
	def tell(self, msg):
		game.output(msg)
Example #8
0
	def do_huh(self, cmd):
		if self.vars["quips"] and cmd.lower() in self.vars["quips"]:
			game.output(self.vars["quips"][cmd])
			return True
Example #9
0
		def die():
			game.output("You die.")
			game.game_over()
Example #10
0
		def inventory():
			if self.inventory:
				game.output("You have: %s" % english.format_list([thing.get_name() for thing in self.inventory]))
			else:
				game.output(self.messages["empty_handed"])
Example #11
0
		def say(msg):
			# If the last character is a quote, remove it.
			if msg[-1] == "\"":
				msg = msg[:-1]
			game.output(self.messages["say"](msg=msg))
			self.location.announce(self, msg)