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
6111a813
authored
Mar 25, 2023
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
9a581ef4
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
5 deletions
diy1.py
diy1.py
View file @
6111a813
...
...
@@ -6,9 +6,25 @@ class Hero(object):
self
.
attack
=
40
self
.
name
=
name
def
combat
():
# 攻击
???
def
combat
(
self
,
enemy
):
# 攻击
m1
=
print
(
self
.
name
+
"对"
+
enemy
.
name
+
"发起攻击"
)
m2
=
print
(
"并造成"
+
str
(
self
.
attack
)
+
"单位伤害"
)
enemy
.
hp
-=
self
.
attack
if
enemy
.
hp
>
0
:
m3
=
print
(
enemy
.
name
+
"血量剩余"
+
str
(
enemy
.
hp
))
print
(
m1
+
m2
+
m3
)
else
:
m3
=
enemy
.
name
+
"已死亡"
print
(
m1
+
m2
+
m3
)
yase
=
Hero
(
"垭瑟"
)
houyi
=
Hero
(
"后羿"
)
yase
.
combat
(
houyi
)
\ No newline at end of file
class
Player
(
Hero
):
def
__init__
(
self
,
name
):
super
()
.
__init__
(
name
)
self
.
hp
=
200
self
.
attack
=
50
player
=
Player
(
"后羿"
)
print
(
"玩家血量值:"
,
player
.
hp
)
print
(
"玩家血量值:"
,
player
.
attack
)
\ 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