Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
bellcode
/
lesson15_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
3afe9f5e
authored
Feb 27, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
9a581ef4
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
7 deletions
diy1.py
hero
diy1.py
View file @
3afe9f5e
# 英雄角色类
class
Hero
(
object
):
def
__init__
(
self
,
name
):
def
__init__
(
self
,
name
):
self
.
level
=
1
self
.
hp
=
25
0
self
.
attack
=
4
0
self
.
hp
=
30
0
self
.
attack
=
5
0
self
.
name
=
name
def
combat
():
# 攻击
???
def
combat
(
self
,
enemy
):
enemy
.
hp
-=
self
.
attack
info1
=
self
.
name
+
"对"
+
enemy
.
name
+
"发起进攻,"
info2
=
"造成"
+
str
(
self
.
attack
)
+
"点伤害,"
if
enemy
.
hp
>
0
:
info3
=
enemy
.
name
+
"还剩下"
+
str
(
enemy
.
hp
)
+
"血量"
infoa
=
info1
+
info2
+
info3
print
(
infoa
)
else
:
info4
=
enemy
.
name
+
"阵亡,游戏结束"
infob
=
info1
+
info2
+
info4
print
(
infob
)
exit
()
yase
=
Hero
(
"垭瑟"
)
houyi
=
Hero
(
"后羿"
)
yase
.
combat
(
houyi
)
\ No newline at end of file
hero
0 → 100644
View file @
3afe9f5e
class Hero:
def __init__(self,name,hp,attack):
self.level = 1 #等级
self.name = name #名字
self.hp = hp #血量
self.attack = attack #攻击力
def upgrade():
#垭瑟升级
yase.level=yase.level+1
yase.hp=yase.hp+50
yase.attack=yase.attack+5
#后艺升级
houyi.level=houyi.level+1
houyi.hp=houyi.hp+50
houyi.attack=houyi.attack+5
#百里玄策升级
bailidi.level=bailidi.level+1
bailidi.hp=bailidi.hp+50
bailidi.attack=bailidi.attack+5
#百里守约升级
bailige.level=bailige.level+1
bailige.hp=bailige.hp+50
bailige.attack=bailige.attack+5
yase = Hero("垭瑟",300,20)
houyi = Hero("后艺",250,23)
bailidi = Hero("百里玄策",225,30)
bailige = Hero("百里守约",245,25)
upgrade()
print("垭瑟的血量为:",yase.hp,",垭瑟的攻击力为:",yase.attack)
print("后艺的血量为:",houyi.hp,",后艺的攻击力为:",houyi.attack)
print("百里玄策的血量为:",bailidi.hp,",百里玄策的攻击力为:",bailidi.attack)
print("百里守约的血量为:",bailige.hp,",百里守约的攻击力为:",bailige.attack)
\ 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