Commit fc071e39 by BellCodeEditor

auto save

parent dbe9bd4c
Showing with 44 additions and 0 deletions
class Hero:
def __init__ (self,name,hp,attack):
self.level=1
self.name=name
self.hp=hp
self.attack=attack
def upgrade(self):
self.level=self.level+1
self.hp=self.hp+100
self.attack=self.attack+10
jie=Hero("杰诺斯",200,30)
qiyu=Hero("琦玉",700,33)
jie.upgrade()
print("杰诺斯的等级为:",jie.level)
print("杰诺斯的血量为:",jie.hp)
print("杰诺斯的攻击值为:",jie.attack)
\ No newline at end of file
...@@ -6,4 +6,30 @@ class Hero(): ...@@ -6,4 +6,30 @@ class Hero():
self.attack = 20 self.attack = 20
#实例化英雄亚瑟 #实例化英雄亚瑟
yase = Hero() yase = Hero()
print(yase.hp)
# class Hero():
# def __init__(self):
# self.level=1
# self.hp=300
# self.attack=40
# yase=Hero()
# print(yase.hp)
class Hero():
def __init__(self):
self.level=1
self.hp=hp
self.attack=attack
def upgrade(self):
self.level=self.level+1
self.hp=self.hp+200
self.attack=self.attack+30
yase=Hero("亚瑟",300,20)
yase.upgrade()
print(yase.hp) print(yase.hp)
\ 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