我一直试图写一个多用户的地牢,使用泥巴-PI和我被困在一个战斗命令,我希望它是某种类似于杀死怪物,一个例子,就像杀死巨魔。
下面是命令的代码
elif command == "kill":
mn = params.lower()
rm = rooms[players[id]["room"]]
if rm["enemy"] == 'yes':
if mn in rm["monsterName"]:
monster = mn
if monster.hp >= 0:
mud.send_message(id,"You attack %s for %d damage" % (rm["monsterName"], players[id]["ATK"]))
monster.hp -= players[id]["ATK"]
else:
monster.death()
else:
mud.send_message(id, "you dont see a %s" % mn)
else:
mud.send_message(id, "you dont see an enemy")这是我的房间代码。
#Rooms
import sys, random, os
#import monsters
from Monsters import *
# structure defining the rooms in the game. Try adding more rooms to the game!
rooms = {
"Tavern": {
"description": "You're in a cozy tavern warmed by an open fire.",
"exits": { "outside": "Outside" },
},
"Outside": {
"description": "You're standing outside a tavern. there is a troll.",
"exits": { "inside": "Tavern" },
"enemy": "yes",
"monsterName": {"troll": troll },
}
}还有我的怪物密码。
#monsters
import sys,random,os,time
#Troll
class Troll():
def __init__(self):
self.name = "Troll"
self.ATK = 2
self.hp = 10
self.max_hp = 10
def death(self):
mud.send_message(id,"you killed the troll")
self.hp = self.max_hp
troll = Troll()当我尝试杀死命令时,我会得到这个错误。
if monster.hp >= 0:
AttributeError: 'unicode' object has no attribute 'hp'我想知道是否有更好的方法来做到这一点,如果是,如何,如果不是,我可以在这里解决我的问题。
发布于 2016-02-20 20:37:38
你确定要接电话吗?
monster = mn它将怪物的名称指定给monster而不是它的对象。我想它应该看起来更像
monster = rm["monsterName"][mn]https://stackoverflow.com/questions/35526912
复制相似问题