Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
lesson14_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
8cad87a0
authored
Jan 18, 2022
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
556629f5
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
8 deletions
diy.py
diy.py
View file @
8cad87a0
import
random
class
Hero
:
def
__init__
(
self
,
name
,
hp
,
Gj
):
def
__init__
(
self
,
name
,
hp
,
Gj
,
max_hp
):
self
.
hp
=
hp
self
.
Gj
=
Gj
self
.
dj
=
1
self
.
name
=
name
self
.
max_hp
=
self
.
hp
print
(
'角色'
+
self
.
name
+
'创建成功'
)
print
(
'等级:'
+
str
(
self
.
dj
)
+
'生命值:'
+
str
(
self
.
hp
)
+
'攻击力:'
+
str
(
self
.
Gj
))
def
shj
(
self
):
self
.
dj
=
self
.
dj
+
1
self
.
Gj
=
self
.
Gj
+
5
...
...
@@ -12,15 +16,41 @@ class Hero:
enemy
.
hp
=
enemy
.
hp
-
self
.
Gj
q1
=
self
.
name
+
'对'
+
enemy
.
name
+
'发起攻击'
q2
=
'造成了'
+
str
(
self
.
Gj
)
+
'伤害'
if
enemy
.
hp
>
0
:
q3
=
enemy
.
name
+
'还剩'
+
str
(
enemy
.
hp
)
q
=
q1
+
q2
+
q3
print
(
q
)
else
:
q3
=
enemy
.
name
+
'已阵亡,游戏结束'
q
=
q1
+
q2
+
q3
print
(
q
)
def
zhiliao
(
self
):
self
.
hp
+=
60
if
self
.
hp
>
self
.
max_hp
:
self
.
hp
=
self
.
max_hp
class
Player
(
Hero
):
pass
yase
=
Hero
(
'亚瑟'
,
100
,
20
)
yase
.
shj
()
houyi
=
Player
(
'后羿'
,
50
,
40
)
houyi
.
shj
()
print
(
yase
.
name
)
print
(
houyi
.
name
)
def
__init__
(
self
,
name
,
hp
,
Gj
,
max_hp
,
hero_type
):
super
()
.
__init__
(
name
,
hp
,
Gj
,
max_hp
)
self
.
hero_type
=
hero_type
yase
=
Hero
(
'亚瑟'
,
100
,
20
,
100
)
houyi
=
Player
(
'后羿'
,
50
,
40
,
50
,
'射手'
)
yase
.
j
(
houyi
)
print
(
'-'
*
30
)
print
(
' 战斗开始'
)
while
True
:
print
(
'-'
*
30
)
xuanze
=
input
(
'请选择攻击技能(1攻击/2治疗):'
)
if
xuanze
==
'1'
:
yase
.
j
(
houyi
)
elif
xuanze
==
'2'
:
yase
.
zhiliao
()
elif
xuanze
==
'q'
:
print
(
'已退出游戏'
)
else
:
print
(
'输入1或2'
)
continue
a
=
random
.
randint
(
1
,
3
)
if
a
==
1
:
houyi
.
j
(
yase
)
else
:
houyi
.
zhiliao
()
\ 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