Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
bellcode
/
lesson15_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
005262d8
authored
Aug 18, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
b70de0c0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
13 deletions
diy1.py
diy1.py
View file @
005262d8
# 英雄角色类
# 英雄角色类
class
Hero
(
object
):
class
Hero
(
object
):
def
__init__
(
self
,
name
):
def
__init__
(
self
,
name
):
self
.
level
=
1
self
.
level
=
1
self
.
hp
=
250
self
.
hp
=
250
self
.
attack
=
40
self
.
attack
=
40
self
.
name
=
name
self
.
name
=
name
def
combat
(
self
,
hero_
):
# 攻击
def
combat
(
self
,
hero_
):
hero_
.
hp
-=
hero_
.
attack
print
(
'-'
*
50
)
hero_
.
hp
-=
self
.
attack
s1
=
self
.
name
+
'对'
+
hero_
.
name
+
'发起了攻击,'
s1
=
self
.
name
+
'对'
+
hero_
.
name
+
'发起了攻击,'
s2
=
hero_
.
name
+
'血量-'
+
str
(
self
.
attack
)
+
','
s2
=
hero_
.
name
+
'hp-'
+
str
(
self
.
attack
)
+
','
s3
=
hero_
.
name
+
'血量:'
+
str
(
hero_
.
hp
)
+
'。'
if
hero_
.
hp
>
0
:
s
=
s1
+
s2
+
s3
s3
=
hero_
.
name
+
'hp:'
+
str
(
hero_
.
hp
)
+
'。'
print
(
s
)
s
=
s1
+
s2
+
s3
print
(
s
)
else
:
s3
=
hero_
.
name
+
'阵亡,游戏结束!'
s
=
s1
+
s2
+
s3
print
(
s
)
exit
()
print
(
'-'
*
50
)
class
Player
:
def
__init__
(
self
,
name
):
super
()
__init__
(
level
,
name
)
self
.
hp
=
200
self
.
attack
=
50
yase
=
Hero
(
"垭瑟"
)
yase
=
Hero
(
"垭瑟"
)
houyi
=
Hero
(
"后羿"
)
houyi
=
Hero
(
"后羿"
)
yase
.
combat
(
houyi
)
player
=
Player
(
'后羿'
)
\ No newline at end of file
yase
.
combat
(
houyi
)
print
(
player
.
hp
)
\ 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