Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
lesson14_4
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
6acb995d
authored
Apr 09, 2023
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
4b940ba8
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
15 deletions
diy2.py
diy2.py
View file @
6acb995d
class
Hero
:
#创建类
class
Hero
:
#创建类
def
__init__
(
self
,
name
,
hp
,
attack
):
#定义一个方法
def
__init__
(
self
,
name
):
#定义一个方法
self
.
level
=
1
#等级为1
self
.
level
=
1
#等级为1
self
.
name
=
name
#英雄的名字
self
.
name
=
name
#英雄的名字
self
.
hp
=
hp
#英雄的血量
self
.
hp
=
250
#英雄的血量
self
.
attack
=
attack
#英雄的攻击力
self
.
attack
=
40
#英雄的攻击力
def
combat
(
self
,
enemy
):
def
uprade
(
self
):
#定义一个升级函数
info1
=
self
.
name
+
'对'
+
enemy
.
name
+
'发起攻击,'
self
.
level
+=
1
#等级+1
info2
=
'造成'
+
str
(
self
.
attack
)
+
'点伤害,'
self
.
hp
+=
50
#血量+50
enemy
.
hp
-=
self
.
attack
self
.
attack
+=
5
#攻击力+5
if
enemy
.
hp
>
0
:
info3
=
enemy
.
name
+
'还剩下'
+
str
(
enemy
.
hp
)
+
'血量'
houyi
=
Hero
(
'后羿'
,
240
,
23
)
#创建houyi英雄
info
=
info1
+
info2
+
info3
houyi
.
uprade
()
#houyi升级
print
(
info
)
print
(
'等级:'
,
houyi
.
level
)
#等级为...
else
:
print
(
'血量:'
,
houyi
.
hp
)
#血量为...
info3
=
enemy
.
name
+
'阵亡,游戏失败'
print
(
'攻击力:'
,
houyi
.
attack
)
#攻击力为...
info
=
info1
+
info2
+
info3
\ No newline at end of file
print
(
info
)
exit
()
houyi
=
Hero
(
'后羿'
)
#创建houyi英雄
yase
=
Hero
(
'垭瑟'
)
yase
.
combat
(
houyi
)
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