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
5477adb8
authored
Feb 12, 2022
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
9a581ef4
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
4 deletions
diy1.py
diy1.py
View file @
5477adb8
...
...
@@ -6,9 +6,43 @@ class Hero(object):
self
.
attack
=
40
self
.
name
=
name
def
combat
():
# 攻击
???
yase
=
Hero
(
"垭瑟"
)
def
combat
(
self
,
dr
):
# 攻击
'''
我方英雄对敌方英雄进行攻击,
1.敌方英雄hp(???)减少 减少的是我方英雄攻击力(???)的点数
2.输出提示信息
2.1我方英雄(???) 对 敌方英雄(???) 进行了攻击,
2.2造成了 我方英雄攻击力(???) 点伤害,
3.判断 敌方英雄hp(???) 小于等于 0
3.1判断成立,代表敌方英雄阵亡, 敌方英雄(???) 已阵亡
3.2判断不成立, 游戏继续 敌方英雄(???)还剩 多少(???)点血量
'''
dr
.
hp
-=
self
.
attack
#dr.hp = dr.hp - self.attack
i1
=
self
.
name
+
"对"
+
dr
.
name
+
"进行了攻击,"
i2
=
"造成了"
+
str
(
self
.
attack
)
+
"点伤害,"
if
dr
.
hp
<=
0
:
i3
=
dr
.
name
+
"已阵亡,游戏结束"
print
(
i1
+
i2
+
i3
)
exit
()
else
:
i3
=
dr
.
name
+
"还剩"
+
str
(
dr
.
hp
)
+
"点血量"
print
(
i1
+
i2
+
i3
)
class
player
(
Hero
):
def
__init__
(
self
,
name
,
herotype
):
super
()
.
__init__
(
name
)
self
.
hp
=
600
self
.
attack
=
70
self
.
herotype
=
herotype
s1
=
"玩家英雄:"
+
self
.
name
+
",创建完成,祝您游戏愉快!"
s2
=
"英雄定位:"
+
self
.
herotype
+
"hp,attack分别为:"
+
str
(
self
.
hp
)
+
","
+
str
(
self
.
attack
)
print
(
s1
)
print
(
s2
)
yase
=
player
(
"垭瑟"
,
"战士"
)
houyi
=
Hero
(
"后羿"
)
yase
.
combat
(
houyi
)
'''
子类会继承父类的所有方法和属性
可以修改里边的属性和方法
为了避免重复继承导致的问题,需要使用super函数
'''
\ 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