Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
lesson16_4
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
025df798
authored
May 05, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
d9cfa316
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
26 deletions
diy1.py
diy1.py
View file @
025df798
import
time
import
random
class
Hero
(
object
):
def
__init__
(
self
,
name
):
self
.
name
=
name
...
...
@@ -6,14 +7,7 @@ class Hero(object):
self
.
hp
=
250
self
.
attack
=
40
self
.
max_hp
=
self
.
hp
self
.
gp
=
0
self
.
max_gp
=
self
.
level
*
100
def
upgrade
(
self
):
self
.
level
+=
1
self
.
max_hp
*=
1.2
self
.
attack
*=
1.2
self
.
hp
=
self
.
max_hp
def
cure
(
self
):
# 治疗
if
self
.
hp
+
60
>
self
.
max_hp
:
self
.
hp
=
self
.
max_hp
...
...
@@ -25,24 +19,13 @@ class Hero(object):
info1
=
self
.
name
+
"对"
+
enemy
.
name
+
"发起进攻,"
info2
=
"造成"
+
str
(
self
.
attack
)
+
"点伤害,"
enemy
.
hp
-=
self
.
attack
self
.
gp
+=
15
if
self
.
gp
>=
self
.
max_gp
:
self
.
upgrade
()
info5
=
self
.
name
+
'升级'
+
'
\n
'
+
'等级为'
+
self
.
level
+
'
\n
'
+
'血量为'
+
self
.
hp
+
'
\n
'
+
'攻击力为:'
+
self
.
attack
else
:
info5
=
''
if
enemy
.
hp
>
0
:
info3
=
enemy
.
name
+
"还剩下"
+
str
(
enemy
.
hp
)
+
"血量"
info4
=
'您的经验增加了'
+
'15'
info
=
info1
+
info2
+
info4
+
info5
info
=
info1
+
info2
+
info3
print
(
info
)
else
:
info3
=
enemy
.
name
+
"阵亡,游戏结束"
info4
=
'您的经验增加了'
+
'30'
info
=
info1
+
info2
+
info3
+
info4
+
info5
self
.
gp
+=
15
info
=
info1
+
info2
+
info3
print
(
info
)
exit
()
...
...
@@ -56,20 +39,30 @@ class Player(Hero):
print
(
"角色"
+
self
.
name
+
"创建成功,英雄类型为:"
,
self
.
hero_type
)
print
(
"当前等级、血量、攻击力分别为:"
,
self
.
level
,
self
.
hp
,
self
.
attack
)
def
cure
(
self
):
# 治疗
z
=
random
.
randint
(
35
,
60
)
if
self
.
hp
+
z
>
self
.
max_hp
:
self
.
hp
=
self
.
max_hp
else
:
self
.
hp
+=
z
print
(
self
.
name
+
"使用了治疗,血量增加:"
,
z
,
",目前的血量为:"
,
self
.
hp
)
houyi
=
Player
(
"射手"
,
"后羿"
)
yase
=
Hero
(
"垭瑟"
)
print
(
'-'
*
30
+
'
\n
游戏开始'
)
while
True
:
time
.
sleep
(
0.
5
)
time
.
sleep
(
0.
2
)
print
(
'-'
*
30
)
time
.
sleep
(
0.5
)
time
.
sleep
(
0.2
)
print
(
' --玩家回合--'
)
c
=
input
(
'请选择释放英雄技能(1攻击/2治疗):'
)
if
c
==
'1'
or
c
==
'攻击'
:
time
.
sleep
(
0.
5
)
time
.
sleep
(
0.
2
)
houyi
.
combat
(
yase
)
elif
c
==
'2'
or
c
==
'治疗'
:
time
.
sleep
(
0.
5
)
time
.
sleep
(
0.
2
)
houyi
.
cure
()
else
:
time
.
sleep
(
0.
5
)
time
.
sleep
(
0.
2
)
print
(
'输入错误!'
)
print
(
' --电脑回合--'
)
\ 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