Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
lesson14_2
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
7af263a8
authored
Mar 18, 2023
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
70850cf8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
86 additions
and
0 deletions
diy2.py
diy3.py
diy2.py
View file @
7af263a8
class
Hero
:
def
__init__
(
self
,
name
,
hp
,
level
,
attack
):
self
.
name
=
name
self
.
hp
=
hp
self
.
level
=
level
self
.
attack
=
attack
def
upgrade
(
self
):
self
.
level
+=
1
self
.
hp
+=
50
self
.
attack
+=
4
yase
=
Hero
(
"亚瑟"
,
200
,
1
,
30
)
houyi
=
Hero
(
"后裔"
,
250
,
1
,
27
)
houyi
.
upgrade
()
yase
.
upgrade
()
#yase.hp=350
print
(
"亚瑟的血量:"
,
yase
.
hp
)
print
(
"后羿的血量:"
,
houyi
.
hp
)
diy3.py
0 → 100644
View file @
7af263a8
import
random
class
Hero
:
def
__init__
(
self
,
name
):
self
.
name
=
name
self
.
hp
=
250
self
.
level
=
1
self
.
attack
=
40
self
.
max_hp
=
self
.
hp
def
combat
(
self
,
enemy
):
#普通攻击
enemy
.
hp
-=
self
.
attack
info1
=
self
.
name
+
"对"
+
enemy
.
name
+
"发起了攻击,"
info2
=
"造成了"
+
str
(
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
+=
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
,
type
):
super
()
.
__init__
(
name
)
self
.
hp
=
200
self
.
attack
=
50
self
.
herotype
=
type
self
.
max_hp
=
self
.
hp
print
(
"英雄角色"
+
self
.
name
+
"创建成功,类型是:"
+
self
.
herotype
)
print
(
"当前角色的等级、血量、攻击力分别是:
%
d、
%
d、
%
d"
%
(
self
.
level
,
self
.
hp
,
self
.
attack
))
def
cure
(
self
):
#普通治疗
blood
=
random
.
randint
(
30
,
50
)
self
.
hp
+=
blood
if
self
.
hp
>
self
.
max_hp
:
self
.
hp
=
self
.
max_hp
print
(
self
.
name
,
"启动治疗术,血量增加了"
,
blood
,
",目前血量是:"
,
self
.
hp
)
yase
=
Hero
(
"亚瑟"
)
houyi
=
Player
(
"后羿"
,
'射手'
)
print
(
"-"
*
50
)
print
(
" 战斗开始"
)
while
True
:
choice
=
input
(
"请选择释放英雄技能(1治疗/2攻击):"
)
if
choice
==
"1"
:
houyi
.
cure
()
elif
choice
==
"2"
:
houyi
.
combat
(
yase
)
elif
choice
==
"q"
:
print
(
"游戏结束!"
)
break
else
:
print
(
"请输入1或2"
)
continue
num
=
random
.
randint
(
1
,
3
)
if
num
==
1
:
yase
.
cure
()
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