Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
lesson16_4
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
3ee11010
authored
Aug 15, 2023
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
f19096ae
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
132 additions
and
0 deletions
diy.py
diy2.py
diy.py
0 → 100644
View file @
3ee11010
class
Hero
(
object
):
def
__init__
(
self
,
name
):
self
.
level
=
1
self
.
hp
=
3500
self
.
attack
=
388
self
.
name
=
name
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
+
'阵亡'
else
:
info3
=
enemy
.
name
+
'还剩下'
+
str
(
enemy
.
hp
)
+
'点生命值'
print
(
info1
+
info2
+
info3
)
def
cure
(
self
):
self
.
hp
=
self
.
hp
+
500
if
self
.
hp
>
self
.
max_hp
:
self
.
hp
=
self
.
max_hp
print
(
self
.
name
+
"使用了治疗,血量为:"
,
self
.
hp
)
class
Player
(
Hero
):
def
__init__
(
self
,
name
,
hero_type
):
super
()
.
__init__
(
name
)
self
.
hp
=
3000
self
.
attack
=
450
self
.
hero_type
=
hero_type
self
.
max_hp
=
self
.
hp
print
(
'角色'
+
self
.
name
+
'创建成功,类型为:'
+
hero_type
)
print
(
'等级,血量,攻击力:'
,
self
.
level
,
self
.
hp
,
self
.
attack
)
def
cure
(
self
):
s
=
random
.
randint
(
30
,
60
)
self
.
hp
=
self
.
hp
+
s
if
self
.
hp
>
self
.
max_hp
:
self
.
hp
=
self
.
max_hp
print
(
self
.
name
+
"使用了治疗,血量为:"
,
self
.
hp
)
ailin
=
Player
(
'艾琳'
,
'射手'
)
houyi
=
Hero
(
"后羿"
)
print
(
'_'
*
30
)
print
(
' 战斗开始'
)
while
True
:
print
(
'_'
*
30
)
a
=
input
(
'请选择攻击1
\
治疗2:'
)
if
a
==
'q'
:
print
(
'游戏结束'
)
break
elif
a
==
"1"
:
ailin
.
combat
(
houyi
)
elif
a
==
"2"
:
ailin
.
cure
()
else
:
print
(
'请重新输入1
\2
:'
)
continue
import
random
zz
=
random
.
randint
(
1
,
3
)
if
zz
==
1
:
houyi
.
cure
()
else
:
houyi
.
combat
(
ailin
)
\ No newline at end of file
diy2.py
0 → 100644
View file @
3ee11010
import
random
class
Hero
(
object
):
def
__init__
(
self
,
name
):
self
.
level
=
1
self
.
hp
=
3500
self
.
attack
=
388
self
.
name
=
name
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
+
'阵亡'
else
:
info3
=
enemy
.
name
+
'还剩下'
+
str
(
enemy
.
hp
)
+
'点生命值'
print
(
info1
+
info2
+
info3
)
def
cure
(
self
):
self
.
hp
=
self
.
hp
+
500
if
self
.
hp
>
self
.
max_hp
:
self
.
hp
=
self
.
max_hp
print
(
self
.
name
+
"使用了治疗,血量为:"
,
self
.
hp
)
class
Player
(
Hero
):
def
__init__
(
self
,
name
,
hero_type
):
super
()
.
__init__
(
name
)
self
.
hp
=
3000
self
.
attack
=
450
self
.
hero_type
=
hero_type
self
.
max_hp
=
self
.
hp
print
(
'角色'
+
self
.
name
+
'创建成功,类型为:'
+
hero_type
)
print
(
'等级,血量,攻击力:'
,
self
.
level
,
self
.
hp
,
self
.
attack
)
def
cure
(
self
):
s
=
random
.
randint
(
300
,
600
)
self
.
hp
=
self
.
hp
+
s
if
self
.
hp
>
self
.
max_hp
:
self
.
hp
=
self
.
max_hp
w
=
str
(
self
.
name
)
+
"使用了治疗"
+
str
(
s
)
+
"血量为:"
+
str
(
self
.
hp
)
print
(
w
)
ailin
=
Player
(
'艾琳'
,
'射手'
)
houyi
=
Hero
(
"后羿"
)
print
(
'_'
*
30
)
print
(
' 战斗开始'
)
while
True
:
print
(
'_'
*
30
)
a
=
input
(
'请选择攻击1
\
治疗2:'
)
if
a
==
'q'
:
print
(
'游戏结束'
)
break
elif
a
==
"1"
:
ailin
.
combat
(
houyi
)
elif
a
==
"2"
:
ailin
.
cure
()
else
:
print
(
'请重新输入1
\2
:'
)
continue
import
random
zz
=
random
.
randint
(
1
,
3
)
if
zz
==
1
:
houyi
.
cure
()
else
:
houyi
.
combat
(
ailin
)
\ 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