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
02bf88b3
authored
Aug 06, 2022
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
9a581ef4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
12 deletions
diy1.py
diy1.py
View file @
02bf88b3
# 英雄角色类
class
Hero
(
object
):
def
__init__
(
self
,
name
):
self
.
level
=
1
self
.
hp
=
250
self
.
attack
=
40
import
time
import
random
class
Hero
():
def
__init__
(
self
,
name
,
hp
,
att
,
heal
=
20
):
self
.
lv
=
1
self
.
name
=
name
self
.
hp
=
hp
self
.
att
=
att
self
.
heal
=
heal
# def upgrade(self):
# self.lv += 1
# self.hp += 50
# self.att += 4
def
combat
(
self
,
enemy
):
if
self
.
hp
>
40
:
if
random
.
randint
(
1
,
100
)
<=
33
:
# 暴击
enemy
.
hp
-=
self
.
att
*
2
print
(
f
'{self.name}对{enemy.name}发起了强攻,造成{self.att*2}点暴击伤害,'
,
end
=
""
)
else
:
# 普通攻击
enemy
.
hp
-=
self
.
att
print
(
f
'{self.name}对{enemy.name}发起了进攻,造成{self.att}点伤害,'
,
end
=
""
)
else
:
self
.
hp
+=
20
print
(
f
'{self.name}对自己使用了治疗,恢复20点生命'
,
end
=
""
)
def
combat
():
# 攻击
???
if
enemy
.
hp
<
0
:
print
(
f
'{enemy.name}阵亡,游戏结束。'
)
exit
()
else
:
print
(
f
'{enemy.name}还剩下{enemy.hp}点血量。'
)
yase
=
Hero
(
'yase'
,
300
,
25
)
houyi
=
Hero
(
'houyi'
,
260
,
30
)
while
True
:
houyi
.
combat
(
yase
)
yase
.
combat
(
houyi
)
print
(
'============================================================='
)
yase
=
Hero
(
"垭瑟"
)
houyi
=
Hero
(
"后羿"
)
yase
.
combat
(
houyi
)
\ No newline at end of file
time
.
sleep
(
2
)
# print(f'级别:{yase.lv} 血量:{yase.hp} 攻击力:{yase.att}')
\ 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