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
d3e0ca59
authored
Jul 30, 2022
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
9a581ef4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
9 deletions
diy1.py
diy1.py
View file @
d3e0ca59
# 英雄角色类
# 英雄角色类
import
time
import
random
class
Hero
(
object
):
class
Hero
(
object
):
def
__init__
(
self
,
name
):
def
__init__
(
self
,
name
,
hp
,
att
):
self
.
level
=
1
self
.
level
=
1
self
.
hp
=
250
self
.
type
=
'pc'
self
.
attack
=
40
self
.
hp
=
hp
self
.
att
=
att
self
.
name
=
name
self
.
name
=
name
def
combat
():
# 攻击
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}点暴击伤害,'
,
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
=
""
)
if
enemy
.
hp
<=
0
:
print
(
f
'{enemy.name}阵亡,游戏结束'
)
exit
()
else
:
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'
yase
=
Hero
(
"垭瑟"
)
while
True
:
houyi
=
Hero
(
"后羿"
)
yase
.
combat
(
houyi
)
yase
.
combat
(
houyi
)
houyi
.
combat
(
yase
)
\ No newline at end of file
print
(
"-"
*
30
)
time
.
sleep
(
1
)
\ 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