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
69d866ce
authored
Jul 23, 2022
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
63f5acad
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
69 additions
and
9 deletions
diy.py
sd.py
diy.py
View file @
69d866ce
class
Hero
:
def
__init__
(
self
,
name
,
hp
,
attack
):
def
__init__
(
self
,
name
):
self
.
level
=
1
self
.
name
=
name
self
.
hp
=
hp
self
.
attack
=
attack
self
.
name
=
name
self
.
hp
=
2500
self
.
attack
=
50
#def upgrade():
# yase.level = yase.level+1
# yase.hp = yase.hp+50
# yase.attack = yase.attack+4
#upgrade()
#print(yase.hp)
def
combat
(
self
,
enemy
):
enemy
.
hp
-=
self
.
attack
info1
=
self
.
name
+
"对"
+
enemy
.
name
+
"发起攻击,"
info2
=
"造成"
+
str
(
self
.
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
)
exit
()
class
Plarer
(
Hero
):
def
__init__
(
self
,
name
,
hero_type
):
super
()
.
__init__
(
name
)
self
.
hp
=
200
self
.
attack
=
50
self
.
hero_type
=
hero_type
print
(
"角色"
+
houyi
.
name
+
"创建成功,英雄类型为:"
,
houyi
.
hero_type
)
print
(
"当前等级,血量,攻击力分别为:"
,
houyi
.
level
,
houyi
.
hp
,
houyi
.
attack
)
houyi
=
Plarer
(
"后羿"
,
"射手"
)
yase
=
Hero
(
"亚瑟"
)
yase
=
Hero
(
"海绵宝宝"
,
250
,
99
)
houyi
=
Hero
(
"杰哥"
,
1
,
300
)
print
(
"海绵宝宝滴血量为:"
,
yase
.
hp
)
print
(
"杰哥滴血量为:"
,
houyi
.
hp
)
\ No newline at end of file
sd.py
0 → 100644
View file @
69d866ce
class
Hero
:
def
__init__
(
self
,
name
):
self
.
level
=
1
self
.
name
=
name
self
.
hp
=
2500
self
.
attack
=
50
#def upgrade():
# yase.level = yase.level+1
# yase.hp = yase.hp+50
# yase.attack = yase.attack+4
#upgrade()
#print(yase.hp)
def
combat
(
self
,
enemy
):
enemy
.
hp
-=
self
.
attack
info1
=
self
.
name
+
"对"
+
enemy
.
name
+
"发起攻击,"
info2
=
"造成"
+
str
(
self
.
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
)
exit
()
class
Plarer
(
Hero
):
def
__init__
(
self
,
name
,
hero_type
):
super
()
.
__init__
(
name
)
self
.
hp
=
200
self
.
attack
=
50
self
.
hero_type
=
hero_type
print
(
"角色"
+
houyi
.
name
+
"创建成功,英雄类型为:"
,
houyi
.
hero_type
)
print
(
"当前等级,血量,攻击力分别为:"
,
houyi
.
level
,
houyi
.
hp
,
houyi
.
attack
)
houyi
=
Plarer
(
"后羿"
,
"射手"
)
yase
=
Hero
(
"亚瑟"
)
\ 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