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
65af4d89
authored
Mar 29, 2022
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
e35ede85
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
4 deletions
diy1.py
diy1.py
View file @
65af4d89
...
@@ -3,7 +3,7 @@ class Hero(object):
...
@@ -3,7 +3,7 @@ class Hero(object):
def
__init__
(
self
,
name
):
def
__init__
(
self
,
name
):
self
.
name
=
name
self
.
name
=
name
self
.
level
=
1
self
.
level
=
1
self
.
hp
=
25
0
self
.
hp
=
30
0
self
.
attack
=
40
self
.
attack
=
40
self
.
max_hp
=
self
.
hp
self
.
max_hp
=
self
.
hp
...
@@ -30,27 +30,42 @@ class Hero(object):
...
@@ -30,27 +30,42 @@ class Hero(object):
class
Player
(
Hero
):
class
Player
(
Hero
):
def
__init__
(
self
,
hero_type
,
name
):
def
__init__
(
self
,
hero_type
,
name
):
super
()
.
__init__
(
name
)
super
()
.
__init__
(
name
)
self
.
hp
=
2
00
self
.
hp
=
100000000000000
00
self
.
attack
=
50
self
.
attack
=
50
self
.
max_hp
=
self
.
hp
self
.
max_hp
=
self
.
hp
self
.
hero_type
=
hero_type
self
.
hero_type
=
hero_type
print
(
"角色"
+
self
.
name
+
"创建成功,英雄类型为:"
,
self
.
hero_type
)
print
(
"角色"
+
self
.
name
+
"创建成功,英雄类型为:"
,
self
.
hero_type
)
print
(
"当前等级、血量、攻击力分别为:"
,
self
.
level
,
self
.
hp
,
self
.
attack
)
print
(
"当前等级、血量、攻击力分别为:"
,
self
.
level
,
self
.
hp
,
self
.
attack
)
def
cure
(
self
):
# 治疗
blood
=
random
.
randint
(
30
,
51
)
self
.
hp
=
self
.
hp
+
blood
if
self
.
hp
>
self
.
max_hp
:
self
.
hp
=
self
.
max_hp
print
(
self
.
name
+
"使用了治疗,血量增加:"
,
+
blood
,
",目前的血量为:"
,
self
.
hp
)
houyi
=
Player
(
"射手"
,
"后羿"
)
houyi
=
Player
(
"射手"
,
"后羿"
)
yase
=
Hero
(
"垭瑟"
)
yase
=
Hero
(
"垭瑟"
)
print
(
'-'
*
30
)
print
(
'-'
*
30
)
print
(
' 战斗开始!'
)
print
(
' 战斗开始!'
)
print
(
" 按b键放彩蛋"
)
print
(
" 按q键放必杀"
)
while
True
:
while
True
:
print
(
'-'
*
30
)
print
(
'-'
*
30
)
choice
=
input
(
"请选择战斗方式:(1攻击
)/(2治疗
)"
)
choice
=
input
(
"请选择战斗方式:(1攻击
/2治疗/w退出
)"
)
if
choice
==
"1"
:
if
choice
==
"1"
:
houyi
.
combat
(
yase
)
houyi
.
combat
(
yase
)
elif
choice
==
"2"
:
elif
choice
==
"2"
:
houyi
.
cure
()
houyi
.
cure
()
elif
choice
==
"
q
"
:
elif
choice
==
"
w
"
:
print
(
"游戏结束"
)
print
(
"游戏结束"
)
break
break
elif
choice
==
"q"
:
print
(
"游戏结束,后羿胜利"
)
break
elif
choice
==
"b"
:
print
(
"游戏结束,后羿挑衅亚瑟,亚瑟放必杀,后羿卒!"
)
break
else
:
else
:
print
(
"请重新输入1/2"
)
print
(
"请重新输入1/2"
)
continue
continue
...
...
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