Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
bellcode
/
lesson15_3
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
3ef94634
authored
2 years ago
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
dfb5d1b6
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
0 deletions
diy2.py
diy2.py
0 → 100644
View file @
3ef94634
# 英雄角色类
import
time
import
random
class
Hero
(
object
):
def
__init__
(
self
,
name
,
hp
,
att
):
self
.
level
=
1
self
.
type
=
'pc'
self
.
hp
=
hp
self
.
att
=
att
self
.
name
=
name
def
combat
(
self
,
enemy
):
# 攻击
m
=
True
if
self
.
type
==
'pc'
:
m
=
self
.
hp
>
60
else
:
m
=
input
(
f
'{self.name}1:攻击,2:治疗'
)
==
'1'
if
m
:
if
random
.
randint
(
1
,
100
)
<
20
:
enemy
.
hp
-=
self
.
att
*
2
print
(
f
'{self.name}对{enemy.name}发起进攻,造成了{self.att*2}点暴击伤害,'
)
else
:
enemy
.
hp
-=
self
.
att
print
(
f
'{self.name}对{enemy.name}发起进攻,造成了{self.att}点伤害,'
)
else
:
self
.
hp
+=
20
print
(
f
'{self.name}发起治疗,恢复了20点血,'
)
if
enemy
.
hp
<=
0
:
print
(
f
'{enemy.name}阵亡,游戏结束'
)
exit
()
else
:
print
(
f
'{self.name}还剩{self.hp}点血'
)
print
(
f
'{enemy.name}还剩{enemy.hp}点血'
)
yase
=
Hero
(
"垭瑟"
,
300
,
50
)
houyi
=
Hero
(
"后羿"
,
250
,
60
)
ch
=
input
(
'请选择角色,1:垭瑟,2:后羿,3:观众'
)
if
ch
==
'1'
:
yase
.
type
=
'p'
elif
ch
==
'2'
:
houyi
.
type
=
'p'
huihe
=
1
while
True
:
print
(
f
'回合{huihe}'
)
print
(
'-'
*
30
)
yase
.
combat
(
houyi
)
houyi
.
combat
(
yase
)
print
(
"-"
*
30
)
huihe
+=
1
time
.
sleep
(
0.5
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
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