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
e1a9060e
authored
Jul 09, 2022
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
1908b6f2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
10 deletions
diy1.py
diy1.py
View file @
e1a9060e
import
random
class
Hero
(
object
):
class
Hero
(
object
):
def
__init__
(
self
,
name
):
def
__init__
(
self
,
name
):
self
.
name
=
name
self
.
name
=
name
...
@@ -5,24 +6,34 @@ class Hero(object):
...
@@ -5,24 +6,34 @@ class Hero(object):
self
.
hp
=
250
self
.
hp
=
250
self
.
attack
=
40
self
.
attack
=
40
self
.
max_hp
=
self
.
hp
self
.
max_hp
=
self
.
hp
self
.
shield
=
0
def
cure
(
self
):
# 治疗
def
cure
(
self
):
# 治疗
???
self
.
hp
=
self
.
hp
+
30
print
(
self
.
name
+
"使用了治疗,血量增加:"
,
60
,
",目前的血量为:"
,
self
.
hp
)
if
self
.
hp
>
self
.
max_hp
:
self
.
hp
=
self
.
max_hp
print
(
self
.
name
+
"使用了治疗,血量增加:"
,
30
,
",目前的血量为:"
,
self
.
hp
)
def
combat
(
self
,
enemy
):
# 普通攻击
def
combat
(
self
,
enemy
):
# 普通攻击
info1
=
self
.
name
+
"对"
+
enemy
.
name
+
"发起进攻,"
info1
=
self
.
name
+
"对"
+
enemy
.
name
+
"发起进攻,"
info2
=
"造成"
+
str
(
self
.
attack
)
+
"点伤害,"
info2
=
"造成"
+
str
(
self
.
attack
)
+
"点伤害,"
enemy
.
hp
-=
self
.
attack
if
enemy
.
shield
>
self
.
attack
:
if
enemy
.
hp
>
0
:
enemy
.
shield
-=
self
.
attack
info3
=
enemy
.
name
+
"还剩下"
+
str
(
enemy
.
shield
)
+
"护盾"
else
:
enemy
.
hp
=
enemy
.
hp
-
(
self
.
attack
-
enemy
.
shield
)
info3
=
enemy
.
name
+
"还剩下"
+
str
(
enemy
.
hp
)
+
"血量"
info3
=
enemy
.
name
+
"还剩下"
+
str
(
enemy
.
hp
)
+
"血量"
if
enemy
.
hp
>
0
:
info
=
info1
+
info2
+
info3
info
=
info1
+
info2
+
info3
print
(
info
)
print
(
info
)
else
:
else
:
info3
=
enemy
.
name
+
"阵亡,游戏结束"
info3
=
enemy
.
name
+
"阵亡,游戏结束"
info
=
info1
+
info2
+
info3
info
=
info1
+
info2
+
info3
print
(
info
)
print
(
info
)
exit
()
exit
()
def
beshield
(
self
):
#护盾
self
.
shield
=
self
.
shield
+
50
print
(
self
.
name
+
"使用了护盾发生器,增加了"
+
str
(
50
)
+
"护盾"
)
class
Player
(
Hero
):
class
Player
(
Hero
):
def
__init__
(
self
,
hero_type
,
name
):
def
__init__
(
self
,
hero_type
,
name
):
...
@@ -36,7 +47,30 @@ class Player(Hero):
...
@@ -36,7 +47,30 @@ class Player(Hero):
houyi
=
Player
(
"射手"
,
"后羿"
)
houyi
=
Player
(
"射手"
,
"后羿"
)
yase
=
Hero
(
"垭瑟"
)
yase
=
Hero
(
"垭瑟"
)
houyi
.
combat
(
yase
)
print
(
'-'
*
30
)
yase
.
combat
(
houyi
)
print
(
' 游戏开始'
)
houyi
.
cure
()
print
(
'-'
*
30
)
yase
.
cure
()
while
True
:
\ No newline at end of file
choice
=
input
(
"请选择释放英雄技能(1攻击/2治疗/3护盾)"
)
if
choice
==
"q"
:
print
(
"游戏结束"
)
break
elif
choice
==
"1"
:
houyi
.
combat
(
yase
)
elif
choice
==
"2"
:
houyi
.
cure
()
elif
choice
==
"3"
:
houyi
.
beshield
()
else
:
print
(
"请重新输入1或2"
)
continue
choice
=
random
.
randint
(
1
,
3
)
if
choice
==
1
:
yase
.
combat
(
houyi
)
elif
choice
==
2
:
yase
.
cure
()
else
:
yase
.
beshield
()
print
(
'-'
*
30
)
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