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
82575b8f
authored
Oct 06, 2022
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
db2ed9b7
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
12 deletions
diy.py
diy.py
View file @
82575b8f
class
Hero
:
def
__init__
(
self
,
name
,
level
,
HP
,
attack
):
def
__init__
(
self
,
name
):
self
.
name
=
name
self
.
level
=
level
self
.
HP
=
HP
self
.
attack
=
attack
def
upgrade
(
self
):
self
.
level
+=
1
self
.
HP
+=
50
self
.
attack
+=
4
yase
=
Hero
(
"亚瑟"
,
1
,
300
,
20
)
yase
.
upgrade
()
print
(
yase
.
level
)
\ No newline at end of file
self
.
level
=
1
self
.
HP
=
250
self
.
attack
=
40
# def upgrade(self):
# self.level+=1
# self.HP+=50
# self.attack+=4
def
combat
(
self
,
enemy
):
enemy
.
HP
-=
self
.
attack
info1
=
self
.
name
+
"对"
+
enemy
.
name
+
"发起进攻
\n
"
info2
=
"造成了"
+
str
(
self
.
attack
)
+
"点伤害
\n
"
if
enemy
.
HP
>
0
:
info3
=
enemy
.
name
+
"剩余血量为"
+
str
(
enemy
.
HP
)
info
=
info1
+
info2
+
info3
print
(
info
)
else
:
info3
=
enemy
.
name
+
"阵亡"
info
=
info1
+
info2
+
info3
print
(
info
)
exit
()
print
(
"-"
*
30
)
class
Player
(
Hero
):
def
__init__
(
self
,
name
,
hero_type
):
super
(
Player
,
self
)
.
__init__
(
name
)
self
.
HP
=
200
self
.
attack
=
50
self
.
hero_type
=
hero_type
print
(
"角色"
+
self
.
name
+
"已经创建成功"
+
"角色职业为"
+
self
.
hero_type
)
print
(
"角色"
+
self
.
name
+
"的等级、血量、攻击力分别为:"
+
str
(
self
.
level
)
+
"、"
+
str
(
self
.
HP
)
+
"、"
+
str
(
self
.
attack
)
+
"、"
)
houyi
=
Player
(
"后羿"
,
"射手"
)
# print(yase.HP)
# print(houyi.HP)
yase
.
combat
(
houyi
)
houyi
.
combat
(
yase
)
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