Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
lesson16_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
f22996bc
authored
Feb 26, 2022
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
9a145c31
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
63 additions
and
3 deletions
diy1.py
diy1.py
View file @
f22996bc
...
...
@@ -26,6 +26,25 @@ class Hero(object):
info
=
info1
+
info2
+
info3
print
(
info
)
exit
()
def
hui
(
self
):
self
.
hp
+=
self
.
max_hp
*
0.5
if
self
.
hp
>
self
.
max_hp
:
self
.
hp
=
self
.
max_hp
print
(
self
.
name
+
"使用了大治疗,血量增加:"
,
str
(
self
.
max_hp
*
0.5
),
",目前的血量为:"
,
self
.
hp
)
def
cai
(
self
,
enemy
):
info1
=
self
.
name
+
"对"
+
enemy
.
name
+
"发起进攻,"
self
.
gong
=
enemy
.
max_hp
*
0.5
info2
=
"造成"
+
str
(
self
.
gong
)
+
"点伤害,"
enemy
.
hp
-=
self
.
gong
if
enemy
.
hp
>
0
:
info3
=
enemy
.
name
+
"还剩下"
+
str
(
enemy
.
hp
)
+
"血量"
info
=
info1
+
info2
+
info3
print
(
info
)
else
:
info3
=
enemy
.
name
+
"阵亡,游戏结束"
info
=
info1
+
info2
+
info3
print
(
info
)
exit
()
class
Player
(
Hero
):
def
__init__
(
self
,
hero_type
,
name
):
...
...
@@ -34,24 +53,64 @@ class Player(Hero):
self
.
attack
=
50
self
.
max_hp
=
self
.
hp
self
.
hero_type
=
hero_type
self
.
gong
=
self
.
attack
print
(
"角色"
+
self
.
name
+
"创建成功,英雄类型为:"
,
self
.
hero_type
)
print
(
"当前等级、血量、攻击力分别为:"
,
self
.
level
,
self
.
hp
,
self
.
attack
)
def
xi
(
self
,
enemy
):
info1
=
self
.
name
+
"对"
+
enemy
.
name
+
"发起进攻,"
self
.
gong
=
self
.
attack
*
0.8
info2
=
"造成"
+
str
(
self
.
gong
)
+
"点伤害,"
enemy
.
hp
-=
self
.
gong
self
.
hp
+=
self
.
gong
if
self
.
hp
>
self
.
max_hp
:
self
.
hp
=
self
.
max_hp
if
enemy
.
hp
>
0
:
info3
=
enemy
.
name
+
"还剩下"
+
str
(
enemy
.
hp
)
+
"血量"
info
=
info1
+
info2
+
info3
print
(
info
)
print
(
self
.
name
+
"还剩下"
+
str
(
self
.
hp
)
+
"血量"
)
else
:
info3
=
enemy
.
name
+
"阵亡,游戏结束"
info
=
info1
+
info2
+
info3
print
(
info
)
exit
()
def
san
(
self
,
enemy
):
info1
=
self
.
name
+
"对"
+
enemy
.
name
+
"发起进攻,"
self
.
gong
=
self
.
attack
*
2.5
info2
=
"造成"
+
str
(
self
.
gong
)
+
"点伤害,"
enemy
.
hp
-=
self
.
gong
if
enemy
.
hp
>
0
:
info3
=
enemy
.
name
+
"还剩下"
+
str
(
enemy
.
hp
)
+
"血量"
info
=
info1
+
info2
+
info3
print
(
info
)
else
:
info3
=
enemy
.
name
+
"阵亡,游戏结束"
info
=
info1
+
info2
+
info3
print
(
info
)
exit
()
houyi
=
Player
(
"射手"
,
"后羿"
)
yase
=
Hero
(
"垭瑟"
)
print
(
"-"
*
100
)
print
(
" 战斗开始"
)
while
True
:
print
(
"-"
*
100
)
choise
=
input
(
"1?2"
)
choise
=
input
(
"1?2
?3?4
"
)
if
int
(
choise
)
==
1
:
houyi
.
combat
(
yase
)
elif
int
(
choise
)
==
2
:
houyi
.
cure
()
elif
int
(
choise
)
==
3
:
houyi
.
xi
(
yase
)
elif
int
(
choise
)
==
4
:
houyi
.
san
(
yase
)
else
:
print
(
"…………………………………………………………………………………………………………"
)
num
=
random
.
randint
(
1
,
2
)
num
=
random
.
randint
(
1
,
4
)
if
num
==
1
:
yase
.
combat
(
houyi
)
elif
num
==
2
:
yase
.
cure
()
elif
num
==
3
:
yase
.
hui
()
elif
num
==
4
:
yase
.
cai
(
houyi
)
\ 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