私は MUD-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()
kill コマンドを試すと、このエラーが発生します。
if monster.hp >= 0:
AttributeError: 'unicode' object has no attribute 'hp'
これを行うためのより良い方法があるかどうかを知りたいです。