Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
bellcode
/
lesson2-2_DIY1
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
d0b08a20
authored
Apr 21, 2026
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
25abb509
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
3 deletions
2.py
3.py
diy1.py
2.py
0 → 100644
View file @
d0b08a20
class
Hero
:
def
__init__
(
self
,
name
):
self
.
name
=
name
self
.
hp
=
250
self
.
level
=
1
self
.
attack
=
20
def
combat
(
self
,
enemy
):
enemy
.
hp
=
enemy
.
hp
-
self
.
attack
info1
=
self
.
name
+
"对"
+
enemy
.
name
+
"发起了攻击!"
info2
=
enemy
.
name
+
"受到了"
+
str
(
enemy
.
attack
)
+
"点伤害,"
if
(
enemy
.
hp
>
0
):
info3
=
enemy
.
name
+
"还剩"
+
str
(
enemy
.
hp
)
+
"点血量!"
info
=
info1
+
info2
+
info3
print
(
info
)
else
:
info3
=
enemy
.
name
+
"已经死亡!"
info
=
info1
+
info2
+
info3
print
(
info
)
class
Player
(
Hero
):
def
__init__
(
self
,
name
):
self
.
name
=
name
self
.
hp
=
500
self
.
level
=
1
self
.
attack
=
15
yase
=
Hero
(
"亚瑟"
)
houyi
=
Player
(
"后羿"
)
print
(
houyi
.
hp
)
\ No newline at end of file
3.py
0 → 100644
View file @
d0b08a20
class
Hero
():
def
__init__
(
self
,
name
):
self
.
level
=
1
self
.
hp
=
300
self
.
attack
=
50
self
.
name
=
name
def
combat
(
self
,
enemy
):
enemy
.
hp
=
enemy
.
hp
-
self
.
attack
info1
=
self
.
name
+
"对"
+
enemy
.
name
+
"造成了"
+
str
(
self
.
attack
)
+
"点伤害!"
if
(
enemy
.
hp
>
0
):
info2
=
enemy
.
name
+
"还剩"
+
str
(
enemy
.
hp
)
+
"点血量"
else
:
info2
=
enemy
.
name
+
"已阵亡"
info
=
info1
+
info2
print
(
info
)
yase
=
Hero
(
"亚瑟王"
)
houyi
=
Hero
(
"后羿"
)
yase
.
combat
(
houyi
)
\ No newline at end of file
diy1.py
View file @
d0b08a20
player
=
input
(
"请出拳:石头/剪刀/布"
)
# 玩家出拳
print
(
"玩家出拳:"
+
player
)
\ 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