Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
bellcode
/
lesson15_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
7545591c
authored
Nov 03, 2020
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
b4a6964f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
67 additions
and
7 deletions
diy1.py
diy1.py
View file @
7545591c
import
random
# 英雄角色类
# 英雄角色类
class
Hero
(
object
)
:
class
Hero
:
def
__init__
(
self
,
name
):
def
__init__
(
self
,
name
):
self
.
level
=
1
self
.
level
=
1
self
.
hp
=
250
self
.
hp
=
250
self
.
attack
=
40
self
.
attack
=
40
self
.
name
=
name
self
.
name
=
name
self
.
max_hp
=
self
.
hp
def
combat
():
# 攻击
def
combat
(
self
,
enemy
):
# 攻击
info2
=
"造成"
+
str
(
self
.
attack
)
+
"点伤害,"
info1
=
self
.
name
+
enemy
.
name
+
"发起进攻,"
enemy
.
hp
=
enemy
.
hp
-
self
.
attack
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
()
def
cure
(
self
):
self
.
hp
=
self
.
hp
+
60
if
self
.
hp
>
self
.
max_hp
:
self
.
hp
=
self
.
max_hp
print
(
self
.
name
+
"已增加"
,
60
,
"点血量,"
+
"目前血量为:"
,
self
.
hp
)
class
Player
(
Hero
):
def
__init__
(
self
,
name
,
hero_type
):
super
()
.
__init__
(
name
)
self
.
level
=
1
self
.
hp
=
210
self
.
attack
=
55
self
.
max_hp
=
self
.
hp
self
.
name
=
name
self
.
hero_type
=
hero_type
print
(
"角色"
+
self
.
name
+
"已生成,英雄类型为:"
,
self
.
hero_type
)
print
(
self
.
name
,
"的血量、等级、攻击力为:"
,
self
.
hp
,
self
.
level
,
self
.
attack
)
def
cure
(
self
):
blood
=
random
.
randint
(
30
,
50
)
self
.
hp
=
self
.
hp
+
blood
if
self
.
hp
>
self
.
max_hp
:
self
.
hp
=
self
.
max_hp
print
(
self
.
name
+
"已增加"
,
blood
,
"点血量,"
+
"目前血量为:"
,
self
.
hp
)
yase
=
Hero
(
"垭瑟"
)
houyi
=
Hero
(
"后羿"
)
houyi
=
Player
(
"后羿"
,
"射手"
)
yase
.
combat
(
houyi
)
yase
=
Hero
(
"亚瑟"
)
\ No newline at end of file
print
(
"-"
*
30
)
print
(
" 战斗开始"
)
while
True
:
print
(
"-"
*
30
)
choice
=
input
(
"请选择技能(1攻击/2治疗)"
)
if
choice
==
"1"
:
houyi
.
combat
(
yase
)
elif
choice
==
"2"
:
houyi
.
cure
()
elif
choice
==
"q"
:
print
(
"已退出游戏"
)
break
else
:
print
(
"请输入1或2"
)
continue
status
=
random
.
randint
(
1
,
3
)
if
status
==
1
:
yase
.
cure
()
else
:
yase
.
combat
(
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