コード例 #1
0
ファイル: pandora.py プロジェクト: alex-games/a1
	def __init__(self, fileName):
		# iterate through the rooms in the database, creating an object for each room.
		self.rooms = {}
		for element in self.getElements(fileName, "room"):
			obj = Room()
			obj.id = element.get("id")
			obj.x = element.get("x")
			obj.y = element.get("y")
			obj.z = element.get("z")
			obj.region = element.get("region")
			obj.terrain = element.get("terrain", "UNDEFINED")
			obj.name = element.findtext("roomname")
			obj.desc = element.findtext("desc")
			obj.note = element.findtext("note")
			obj.exits = []
			for x in element.findall("./exits/exit"):
				newExit = Exit()
				newExit.dir = self.directionNames[x.get("dir")]
				newExit.to = x.get("to")
				newExit.door = x.get("door")
				obj.exits.append(newExit)
			obj.exits.sort(key=lambda k:self.directionNames.values().index(k.dir))
			obj.setCost(obj.terrain)
			# Add a reference to the room object to our self.rooms dict, using the room ID as the key.
			self.rooms[obj.id] = obj
コード例 #2
0
 def __init__(self, fileName):
     # iterate through the rooms in the database, creating an object for each room.
     self.rooms = {}
     for element in self.getElements(fileName, "room"):
         obj = Room()
         obj.id = element.get("id")
         obj.x = element.get("x")
         obj.y = element.get("y")
         obj.z = element.get("z")
         obj.region = element.get("region")
         obj.terrain = element.get("terrain", "UNDEFINED")
         obj.name = element.findtext("roomname")
         obj.desc = element.findtext("desc")
         obj.note = element.findtext("note")
         obj.exits = []
         for x in element.findall("./exits/exit"):
             newExit = Exit()
             newExit.dir = self.directionNames[x.get("dir")]
             newExit.to = x.get("to")
             newExit.door = x.get("door")
             obj.exits.append(newExit)
         obj.exits.sort(
             key=lambda k: self.directionNames.values().index(k.dir))
         obj.setCost(obj.terrain)
         # Add a reference to the room object to our self.rooms dict, using the room ID as the key.
         self.rooms[obj.id] = obj
コード例 #3
0
ファイル: mmapper.py プロジェクト: nstockton/mume-emu
def read_exit(version, infileobj):
	new_exit = Exit()
	if version >= 041:
		new_exit.exitFlags = exitflags.bits_to_flag_set(read_uint16(infileobj))
	else:
		new_exit.exitFlags = exitflags.bits_to_flag_set(read_uint8(infileobj))
	if version >= 040:
		new_exit.doorFlags = doorflags.bits_to_flag_set(read_uint16(infileobj))
	else:
		new_exit.doorFlags = doorflags.bits_to_flag_set(read_uint8(infileobj))
	new_exit.door = read_qstring(infileobj)
	if "door" in new_exit.exitFlags:
		new_exit.exitFlags.add("exit")
		if not new_exit.door:
			new_exit.door = "exit"
	# Inbound connections are unneeded.
	connection = read_uint32(infileobj)
	while connection != UINT32_MAX:
		connection = read_uint32(infileobj)
	outConnections = []
	connection = read_uint32(infileobj)
	while connection != UINT32_MAX:
		outConnections.append(str(connection))
		connection = read_uint32(infileobj)
	if not outConnections:
		new_exit.to = "undefined"
	else:
		# We want the last outbound connection.
		new_exit.to = outConnections[-1]
	return new_exit
コード例 #4
0
ファイル: mmapper.py プロジェクト: alex-games/a1
def read_exit(infileobj):
	new_exit = Exit()
	new_exit.exitFlags = exitflags.bits_to_flag_set(read_uint8(infileobj))
	new_exit.doorFlags = doorflags.bits_to_flag_set(read_uint8(infileobj))
	new_exit.door = read_qstring(infileobj)
	if "door" in new_exit.exitFlags:
		new_exit.exitFlags.add("exit")
		if not new_exit.door:
			new_exit.door = "exit"
	# Inbound connections are unneeded.
	connection = read_uint32(infileobj)
	while connection != UINT_MAX:
		connection = read_uint32(infileobj)
	outConnections = []
	connection = read_uint32(infileobj)
	while connection != UINT_MAX:
		outConnections.append(str(connection))
		connection = read_uint32(infileobj)
	if not outConnections:
		new_exit.to = "UNDEFINED"
	else:
		# We want the last outbound connection.
		new_exit.to = outConnections[-1]
	return new_exit
コード例 #5
0
        ('go to', '- go to "Room name" - you\'ll go through the exit that connects the current room with the "Room name" and will execute the \'location\' command. Each time you move, you lose health.'),
        ('items', '- items - prints out a list of items in the backpack'),
        ('pick up', '- pick up "item name" - you will pick up the item and execute the \'items\' command'),
        ('drop', '- drop "item name" - you will drop or unequip the item and execute the \'items\' command'),
        ('unlock', '- unlock "exit name" - unlocks the exit if you have the respective key'),
        ('eat', '- eat "item name" - you will eat the food, restore health and execute the \'items\' command'),
        ('equip', '- equip "item name" - you will equip the item and will be able to cause more damage to monsters'),
        ('monsters', '- monsters - prints out a list of alive monsters in the room'),
        ('attack', '- attack "monster name" - you will attack the monster'),
        ('quit', '- quit - exits the game'),
    ]
)

ROOMS = {
    'dark_room': Room(name='Dark room',
                      exits=[Exit(name='Wooden door', goes_to=None, is_locked=False)],
                      monsters=None,
                      items=[Food(name='Half-rotten apple', weight=1, health_points=1)]),
    'long_hall': Room(name='Long hall',
                      exits=[
                          Exit(name='Wooden door', goes_to=None, is_locked=False),
                          Exit(name='Prison cell door', goes_to=None, is_locked=True),
                          Exit(name='Rusty iron gate', goes_to=None, is_locked=True)
                      ],
                      monsters=[
                          Monster(name='Venomous spider', health=5, damage=1)
                      ],
                      items=[Key(name='Prison key', weight=1, unlocks_door=None)]),
    'prison_cell': Room(name='Prison cell',
                        exits=[Exit(name='Prison cell door', goes_to=None, is_locked=False)],
                        monsters=[