Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
lesson14_1
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
12a9b18f
authored
Sep 12, 2022
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
cf4e99dd
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
10 deletions
diy3.py
diy3.py
View file @
12a9b18f
...
@@ -5,13 +5,13 @@ class Hero: # 类名,Hero表示英雄
...
@@ -5,13 +5,13 @@ class Hero: # 类名,Hero表示英雄
self
.
hp
=
hp
# 生命(类属性)
self
.
hp
=
hp
# 生命(类属性)
self
.
attack
=
attack
# 攻击力(类属性)
self
.
attack
=
attack
# 攻击力(类属性)
def
ypgrade
():
# 用关键字def定义方法名,封装函数
def
upgrade
(
self
):
# 函数封装
yase
.
level
=
yase
.
level
+
1
# 每升级一次等级+1
self
.
level
=
self
.
level
+
1
# 每升级一次等级+1
yese
.
hp
=
yase
.
hp
+
50
# 。。。。 血量+50
self
.
hp
=
self
.
hp
+
50
# 。。。。 血量+50
yase
.
attack
=
yase
.
attack
+
4
# 。。。。 攻击力+4
self
.
attack
=
self
.
attack
+
4
# 。。。。 攻击力+4
yase
=
Hero
(
"亚瑟"
,
300
,
20
)
# 括号内实参123分别对应形参123
houyi
=
Hero
(
"后羿"
,
240
,
23
)
# 括号内实参123分别对应形参123
print
(
"亚瑟的初始血量为: "
,
yase
.
hp
)
houyi
.
upgrade
()
# 用角色名的方法调用函数,下面依次查看属性值
upgrade
()
# 重复调用函数
print
(
"等级为: "
,
houyi
.
level
)
upgrade
()
# 重复调用函数
print
(
"血量为: "
,
houyi
.
hp
)
print
(
"升级2次后,亚瑟的血量为: "
,
yase
.
hp
)
print
(
"攻击力为: "
,
houyi
.
attack
)
\ No newline at end of file
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment