300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > 奥特曼打小怪兽python代码简单版_奥特曼打小怪兽

奥特曼打小怪兽python代码简单版_奥特曼打小怪兽

时间:2020-05-28 08:31:30

相关推荐

奥特曼打小怪兽python代码简单版_奥特曼打小怪兽

from random import randint # 导入randint函数

class Monster(object):

def __init__(self, name, energy):

self.name = name

self.energy = energy

if self.energy >= 100:

print(self.name + "满血战斗")

else:

print(self.name + "目前有" + str(self.energy) + "的血量")

print("警告:" + self.name + "需要补血")

def eat(self, energy):

if self.energy <= 100:

for i in range(10, 100, 10):

self.energy += energy # 执行吃的语句,吃就+10,如果>100,就不吃了

print("正在补血.....")

print(self.name + "现在有" + str(self.energy) + "的血量")

class Ultraman(object):

def __init__(self, name, alk):

self.name = name

self.alk = alk

return

def beat(self, other, c):

other.energy = other.energy - c * self.alk

if other.energy <= 0:

print(self.name + "攻击" + other.name + str(c) + "次")

print("恭喜" + self.name + "成功打死" + other.name)

else:

print(self.name + "攻击" + other.name + str(c) + "次")

print("很遗憾" + self.name + "没有打死" + other.name)

M1 = Monster('月月', 10)

M1.eat(10)

U1 = Ultraman('水水', 999)

U1.beat(M1, 1)

原文链接:/qq_53806297/article/details/112345655

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。