Commit 493a67b1 by BellCodeEditor

auto save

parent d4ac94c7
Showing with 19 additions and 19 deletions
class hero: class hero:
def __init__(self,hp,attack): def __init__(self,hp,attack):
self.level=1 self.level=1
#self.name=name
self.hp=hp self.hp=hp
self.attack=attack self.attack=attack
#yase=hero(200,300)
#yase.hp=250 #变量里的数值取决于最后一次赋值内容
def upgrade(self):
self.level=self.level+1
self.hp=self.hp+50
self.attack=self.attack+20
daji=hero(300,200) yase=hero(200,300)
yase.upgrade()
for i in range(1,10): print(yase.attack)
daji.level=i
daji.attack=daji.attack+100
daji.hp=daji.hp+50
print(daji.hp)
\ No newline at end of file
...@@ -3,13 +3,11 @@ class hero: ...@@ -3,13 +3,11 @@ class hero:
self.level=1 self.level=1
self.hp=hp self.hp=hp
self.hk=hk self.hk=hk
ye=hero(100,12)
ye.hp=300 def upgrade(self):
print(ye.hp) self.level=self.level+1
self.hp=self.hp+50
def upgrade(self): self.hk=self.hk+30
self.level=self.level+1 ye=hero(100,20)
self.hp=self.hp+50 upgrade(ye)
self.hk=self.hk+30 print(ye.hp)
upgrade(ye) \ No newline at end of file
print(ye.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