Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
lesson16_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
bf90f925
authored
Jun 30, 2023
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
48a9a0bf
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
12 deletions
diy1.py
diy1.py
View file @
bf90f925
import
random
lantiao
=
10
hit
=
[
7000
,
8000
,
9000
,
10000
]
cint
=
random
.
choice
(
hit
)
class
Hero
(
object
):
def
__init__
(
self
,
name
):
self
.
name
=
name
self
.
level
=
1
self
.
hp
=
25
0
self
.
attack
=
40
self
.
hp
=
13500
0
self
.
attack
=
8888
self
.
max_hp
=
self
.
hp
def
cure
(
self
):
# 治疗
self
.
hp
+=
55
self
.
hp
+=
cint
if
self
.
hp
>
self
.
max_hp
:
self
.
hp
=
self
.
max_hp
print
(
self
.
name
+
"使用了治疗,血量增加:"
,
60
,
",目前的血量为:"
,
self
.
hp
)
print
(
self
.
name
+
"服用了一枚治疗丹,血量增加:"
,
cint
,
",目前的血量为:"
,
self
.
hp
)
lantiao
+=
1
def
combat
(
self
,
enemy
):
# 普通攻击
info1
=
self
.
name
+
"对"
+
enemy
.
name
+
"
发起进攻
,"
info1
=
self
.
name
+
"对"
+
enemy
.
name
+
"
扔出一把飞刀
,"
info2
=
"造成"
+
str
(
self
.
attack
)
+
"点伤害,"
enemy
.
hp
-=
self
.
attack
lantiao
+=
1
if
lantiao
>
10
:
lantiao
=
10
if
enemy
.
hp
>
0
:
info3
=
enemy
.
name
+
"还剩下"
+
str
(
enemy
.
hp
)
+
"血量"
info
=
info1
+
info2
+
info3
...
...
@@ -25,14 +32,39 @@ class Hero(object):
info3
=
enemy
.
name
+
"阵亡,游戏结束"
info
=
info1
+
info2
+
info3
print
(
info
)
print
(
'你干嘛啊~~'
)
if
enemy
.
hp
<=
0
:
print
(
"胜利"
)
if
self
.
hp
<=
0
:
print
(
"失败"
)
exit
()
def
qiang
(
self
,
enemy
):
self
.
huai
=
self
.
attack
+
5000
infu1
=
self
.
name
+
"对"
+
enemy
.
name
+
"发起攻击,"
infu2
=
"造成"
+
str
(
self
.
huai
)
+
"点伤害,"
enemy
.
hp
-=
self
.
huai
lantiao
+=
1
if
lantiao
>
10
:
lantiao
=
10
if
enemy
.
hp
>
0
:
infu3
=
enemy
.
name
+
"还剩下"
+
str
(
enemy
.
hp
)
+
"血量"
infu
=
infu1
+
infu2
+
infu3
print
(
infu
)
else
:
infu3
=
enemy
.
name
+
"阵亡,游戏结束"
infu
=
infu1
+
infu2
+
infu3
print
(
infu
)
if
enemy
.
hp
<=
0
:
print
(
"胜利"
)
if
self
.
hp
<=
0
:
print
(
"失败"
)
exit
()
class
Player
(
Hero
):
def
__init__
(
self
,
hero_type
,
name
):
super
()
.
__init__
(
name
)
self
.
hp
=
2
00
self
.
attack
=
50
self
.
hp
=
1400
00
self
.
attack
=
8688
self
.
max_hp
=
self
.
hp
self
.
hero_type
=
hero_type
print
(
"角色"
+
self
.
name
+
"创建成功,英雄类型为:"
,
self
.
hero_type
)
...
...
@@ -46,15 +78,21 @@ class Player(Hero):
self
.
hp
=
self
.
max_hp
print
(
self
.
name
+
"使用了治疗,血量增加:"
,
str
(
c
),
",目前的血量为:"
,
self
.
hp
)
houyi
=
Player
(
"
射手"
,
"后羿
"
)
yase
=
Hero
(
"
垭瑟
"
)
houyi
=
Player
(
"
初级战将"
,
"血影战神
"
)
yase
=
Hero
(
"
只因少将
"
)
while
True
:
print
(
'-'
*
30
)
a
=
input
(
"请选择技能:1攻击/2治疗"
)
a
=
input
(
"请选择技能:1攻击/2治疗
/3强化
"
)
if
int
(
a
)
==
1
:
houyi
.
combat
(
yase
)
elif
int
(
a
)
==
2
:
houyi
.
cure
()
elif
int
(
a
)
==
3
:
if
lantiao
>=
8
:
lantiao
-=
8
houyi
.
qiang
(
yase
)
else
:
print
(
"蓝条不够,不可使用"
)
elif
a
==
"q"
:
print
(
'游戏结束'
)
break
...
...
@@ -64,6 +102,8 @@ while True:
b
=
random
.
randint
(
1
,
3
)
if
b
==
3
:
yase
.
cure
()
if
b
==
2
:
yase
.
qiang
(
houyi
)
else
:
yase
.
combat
(
houyi
)
...
...
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