Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
bellcode
/
lesson15_test2
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
7b4250fe
authored
Jun 18, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
1cf9f5c8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
1 deletions
12.py
diy2-test.py
12.py
0 → 100644
View file @
7b4250fe
#第一节
class
Hero
(
object
):
def
__init__
(
self
,
name
):
self
.
level
=
1
self
.
hp
=
250
self
.
attack
=
40
self
.
name
=
name
def
combat
(
self
,
gjdx
):
# 攻击
gjdx
.
hp
-=
self
.
attack
info1
=
self
.
name
+
'对'
+
gjdx
.
name
+
'发起攻击'
info2
=
gjdx
.
name
+
'血量减少'
+
str
(
self
.
attack
)
if
gjdx
.
hp
>
0
:
info3
=
gjdx
.
name
+
'的血量还剩'
+
str
(
gjdx
.
hp
)
info
=
info1
+
info2
+
info3
print
(
info
)
else
:
info3
=
gjdx
.
name
+
'血量不足,已阵亡,游戏结束'
info
=
info1
+
info2
+
info3
print
(
into
)
exit
()
#第二节
class
Player
(
Hero
):
def
__init__
(
self
,
name
,
leixing
):
super
(
Player
,
self
)
.
__init__
(
name
)
self
.
hp
=
200
self
.
attack
=
50
self
.
leixing
=
leixing
print
(
self
.
name
+
'已创建'
)
print
(
self
.
name
+
'是一名'
+
self
.
leixing
)
print
(
self
.
name
+
'的初始血量为:'
+
str
(
self
.
hp
),
';'
+
'初始攻击为:'
+
str
(
self
.
attack
))
yase
=
Hero
(
"垭瑟"
)
houyi
=
Player
(
"后羿"
,
'弓箭手'
)
yase
.
combat
(
houyi
)
diy2-test.py
View file @
7b4250fe
...
...
@@ -12,7 +12,8 @@ class Dog: # 狗类
class
Husky
(
Dog
):
# 哈士奇类
def
__init__
(
self
):
??
super
()
.
__init__
()
self
.
skin
=
'black'
coco
=
Husky
()
print
(
coco
.
skin
)
\ 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