您可以使用一个怪物类来记住所有怪物参数,以供以后使用。您需要至少记住某个地方的附件数量,以便决定使用哪种附件。
(非常基本)
import random
class Monster(object):
def __init__(self):
self.attitude = random.choice(["An excited", "An angry", "A rabid",
"A sadistic", "A depressed"])
self.nouns = random.choice(["dog", "cat", "rabbit", "snake", "bird"])
self.material = random.choice(["flame.", "wood.", "ash.", "glass.",
"flesh.", "metal."])
self.attribute = random.choice(["has large mandibles,", "has a gaunt appearance,",
"has no eyes or mouth,", "is invisible,",
"breathes fire,", "screams endlessly,"])
self.numbers = random.choice(["has 1", "has 2", "has 3", "has 4",
"has 5", "has 6", "has 7", "has 8",
"has 9", "has 10"])
# you use either one of the lists, dependingf on the result of self.numbers
# this is the "ternary operator" that was mentioned in the comments
self.attachments = random.choice(["arms", "legs", "tentacles", "heads",
"mouths"]) if self.numbers != "has 1" else \
random.choice(["arm", "leg", "tentacle", "head", "mouth"])
self.features = random.choice(["has an unquenchable thirst for blood.",
"wants to destroy all living creatures.",
"is incredible lusty.",
"wants to control the human race.",
"has an interest in sentient life.",
"hates silence."])
def __str__(self):
return ' '.join([self.attitude, self.nouns, "composed of", self.material, "It",
self.attribute, "and it", self.numbers, self.attachments ,
"and it", self.features])
# create 5 unique monsters
M1 = Monster()
M2 = Monster()
M3 = Monster()
M4 = Monster()
M5 = Monster()
# print the descriptions (`__str__()` - output) of each:
print M1
print M2
print M3
print M4
print M5
输出(重新格式化):
A rabid rabbit composed of flesh. It screams endlessly, and it has
3 heads and it is incredible lusty.
A depressed dog composed of flame. It has a gaunt appearance, and it
has 6 legs and it has an unquenchable thirst for blood.
A rabid bird composed of flesh. It is invisible, and it has 8 heads
and it wants to destroy all living creatures.
A depressed snake composed of wood. It has a gaunt appearance, and it
has 4 mouths and it has an unquenchable thirst for blood.
A depressed cat composed of ash. It is invisible, and it has 6 mouths
and it wants to control the human race.
优点:如果他们也受到HP或攻击,您也可以将其“脚本化”到类实例中,并根据这些记忆值进行计算:
print "You chop up one ", M3.attachments, " of ", M3.attitude, M3.nouns
输出:
You chop up one arm of An excited dog