Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
lesson14_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
39a479e4
authored
Dec 20, 2025
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
97bb4995
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
12 deletions
diy.py
diy.py
View file @
39a479e4
import
random
class
Hero
:
def
__init__
(
self
,
name
,
hp
,
gjl
,
s
):
self
.
name
=
name
...
...
@@ -5,30 +6,74 @@ class Hero:
self
.
HP
=
hp
self
.
attack
=
gjl
self
.
speed
=
s
self
.
max_hp
=
self
.
HP
print
(
"成功创建英雄"
)
print
(
self
.
name
,
"的血量是: "
,
self
.
HP
,
"
\n
攻击力是: "
,
self
.
attack
)
def
combat
(
self
,
emy
):
emy
.
HP
=
emy
.
HP
-
self
.
attack
info1
=
self
.
name
+
"攻击了"
+
emy
.
name
+
"
\n
"
info2
=
"对"
+
emy
.
name
+
"造成了"
+
str
(
self
.
attack
)
+
"伤害
\n
"
info3
=
emy
.
name
+
"剩余血量"
+
str
(
emy
.
HP
-
self
.
attack
)
+
"
\n
"
print
(
info1
+
info2
+
info3
)
class
Player
(
Hero
):
def
ticle
(
self
):
pass
def
cure
(
self
):
self
.
HP
=
self
.
HP
+
10
if
self
.
HP
>
self
.
max_hp
:
self
.
HP
=
self
.
max_hp
def
jiasu
(
self
):
self
.
speed
+=
10
print
(
"你的速度增加了10"
)
print
(
"此时英雄是"
,
self
.
speed
)
def
yinshen
(
self
):
print
(
"我隐身起来了,可以偷袭别人"
)
def
shazhuipao
(
self
):
print
(
"我使用鲨嘴炮,可以击退别人"
)
def
dazhao
(
self
):
print
(
"我使用大招,可以免疫任何伤害"
)
print
(
self
.
name
,
"使用了治疗术,血量增加了1001,目前血量为:"
,
self
.
HP
)
class
Player
(
Hero
):
def
ticle
(
self
):
pass
def
yinshen
(
self
):
print
(
"我隐身起来了,可以偷袭别人"
)
jingke
=
Hero
(
"荆轲"
,
8000
,
1700
,
30
)
poi
=
Player
(
"鲁班"
,
6000
,
1000
,
20
)
jingke
.
combat
(
poi
)
#jingke.jiasu()
#jingke.yinshen()
#jingke.shazhuipao()
#jingke.dazhao()
\ No newline at end of file
poi
=
Player
(
"鲁班"
,
2000
,
1000
,
20
)
print
(
"-"
*
30
)
print
(
" 战斗开始"
)
print
(
"-"
*
30
)
while
1
:
a
=
int
(
input
(
"请选择技能:1、攻击;2、治疗;3、加速;4、鲨嘴炮;5、大招"
))
if
a
==
1
:
jingke
.
combat
(
poi
)
if
a
==
2
:
jingke
.
cure
()
if
a
==
3
:
jingke
.
jiasu
()
if
a
==
4
:
jingke
.
shazhuipao
()
if
a
==
5
:
jingke
.
dazhao
()
b
=
random
.
randint
(
1
,
6
)
if
b
==
1
:
print
(
1
)
poi
.
combat
(
jingke
)
if
b
==
2
:
print
(
2
)
poi
.
cure
()
if
b
==
3
:
print
(
3
)
poi
.
jiasu
()
if
b
==
4
:
print
(
4
)
poi
.
shazhuipao
()
if
b
==
5
:
print
(
5
)
poi
.
dazhao
()
if
b
==
6
:
print
(
6
)
poi
.
yinshen
()
if
jingke
.
HP
<
0
:
print
(
"荆轲输了"
)
exit
()
if
poi
.
HP
<
0
:
print
(
"鲁班输了"
)
exit
()
\ 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