Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
lesson16_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
6e0e8330
authored
Apr 18, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
e47cb26d
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
78 additions
and
0 deletions
diy1.py
diy1.py
0 → 100644
View file @
6e0e8330
class
Hero
:
def
__init__
(
self
,
hp
,
attack
,
name
,
howCure
):
self
.
HP
=
hp
self
.
Attack
=
attack
self
.
level
=
1
self
.
Name
=
name
self
.
howCure
=
howCure
self
.
MaxHP
=
hp
def
UpGrade
(
SB
):
SB
.
level
+=
1
SB
.
HP
+=
300
SB
.
Attack
+=
30
def
ComBot
(
A
,
B
):
B
.
HP
-=
A
.
Attack
info1
=
A
.
Name
+
"对"
+
B
.
Name
+
"发起进攻"
info2
=
",共造成"
+
str
(
A
.
Attack
)
+
"点伤害"
if
B
.
HP
>
0
:
info3
=
B
.
Name
+
"还剩下"
+
str
(
B
.
HP
)
+
"点生命"
else
:
info3
=
B
.
Name
+
"死亡,游戏结束,"
+
A
.
Name
+
"胜利"
print
(
info1
+
info2
+
info3
)
exit
()
print
(
info1
+
info2
+
info3
)
def
cure
(
self
):
self
.
HP
+=
self
.
howCure
if
self
.
HP
>
self
.
MaxHP
:
self
.
HP
=
self
.
MaxHP
print
(
self
.
Name
,
"使用了治疗术,当前血量"
,
self
.
HP
)
class
Player
(
Hero
):
def
__init__
(
self
,
hp
,
attack
,
name
,
type
,
howCure
):
super
()
.
__init__
(
hp
,
attack
,
name
,
howCure
)
self
.
type
=
type
print
(
"玩家创建成功 姓名:"
,
self
.
Name
)
print
(
"玩家创建成功 血量:"
,
self
.
HP
)
print
(
"玩家创建成功 攻击力:"
,
self
.
Attack
)
print
(
"玩家创建成功 职业:"
,
self
.
type
)
print
(
"玩家创建成功 治疗量:"
,
self
.
howCure
)
print
(
"游戏开始"
)
print
(
"--------------------------------"
)
print
(
"欢迎来到王者荣耀"
)
print
(
"我是裁判:机器人"
)
print
(
"废话不多说,开始游戏!"
)
print
(
" "
)
a
=
input
(
"输入任意键开始游戏"
)
print
(
"--------------------------------"
)
player
=
Player
(
5000
,
250
,
"亚瑟"
,
"战士"
,
300
)
computer
=
Hero
(
3000
,
400
,
"后羿"
,
200
)
print
(
"--------------------------------"
)
while
True
:
print
(
"机器人:轮到您的回合"
)
print
(
"--------------------------------"
)
b
=
0
;
while
True
:
b
=
input
(
"请输入(1:治疗术,2:普通攻击)"
)
if
b
==
"1"
:
print
(
"机器人:您使用了治疗术"
)
player
.
cure
()
print
(
"--------------------------------"
)
break
elif
b
==
"2"
:
print
(
"机器人:您使用了普通攻击"
)
player
.
ComBot
(
computer
)
print
(
"--------------------------------"
)
break
else
:
print
(
"机器人:输入错误,请重新输入!"
)
print
(
"--------------------------------"
)
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