Commit 3e1b4f6d by BellCodeEditor

save project

parent 98db3cea
Showing with 21 additions and 39 deletions
# class hero:
# def __init__(self,name,hp,attack):
# self.level = 1
# self.name = name
# self.hp=hp
# self.attack=attack
# def shenji(self):
# self.hp=self.hp+50
# self.level=self.level+1
# self.attack=self.attack+4
# yase=hero("yase",300,200)
# yase.shenji()
# print(yase.hp)
# houyi = hero("后裔",200,400)
# houyi.shenji()
# print(houyi.hp)
# 创建一个cat类 每一只猫都有名字(name),年龄(age),性别(sex)
# 每一只猫都有吃东西的行为(print("猫在吃饭")).实例化出一只名字为aa,年龄为10,性别为男的猫 并在控制台打印猫在吃饭
class cat:
def __init__(self,name,age,sex,hungry):
self.name=name
self.age = age
self.sex = sex
self.hungry = hungry
def eat(self):
self.hungry=self.hungry-1
a = cat("cat1",11,"man",5)
b = cat("cat2",11,"man",5)
a.eat()
a.name = "a猫"
print(a.name)
print(b.hungry)
class Hero(object):
def __init__(self,name):
self.level = 1
self.hp = 3500
self.name = name
self.attack = 388
def combat(self,enemy):
enemy.hp-=self.attack
info1= self.name + '对' + enemy.name +"造成了伤害"
info2 = '造成了'+str(self.attack) + "真实伤害"
if enemy.hp<0:
info3=enemy.name+'阵亡'
else:
info3=enemy.name+'剩下'+str(enemy.hp)+"点生命值"
print(info1+"\n"+info2+"\n"+info3)
yase = Hero("亚瑟")
houyi = Hero("后羿")
junming = Hero("俊明")
yase.combat(houyi)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment