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
d9be9fce
authored
May 05, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
ee97dcbd
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
6 deletions
diy1.py
diy1.py
View file @
d9be9fce
...
...
@@ -3,12 +3,25 @@ class Hero(object):
def
__init__
(
self
,
name
):
self
.
level
=
1
self
.
hp
=
250
self
.
attack
=
4
0
self
.
attack
=
2
0
self
.
name
=
name
def
combat
():
# 攻击
???
def
combat
(
self
,
enemy
):
# 攻击
info1
=
self
.
name
+
'对'
+
enemy
.
name
+
'发起进攻'
+
'造成'
+
str
(
self
.
attack
)
+
'点伤害'
enemy
.
hp
-=
self
.
attack
if
enemy
.
hp
>
0
:
info2
=
enemy
.
name
+
'还剩下'
+
str
(
enemy
.
hp
)
+
'血量'
info
=
info1
+
info2
print
(
info
)
else
:
info2
=
enemy
.
name
+
'已阵亡,游戏结束'
info
=
info1
+
info2
print
(
info
)
exit
()
yase
=
Hero
(
"垭瑟"
)
houyi
=
Hero
(
"后羿"
)
yase
.
combat
(
houyi
)
\ No newline at end of file
yase
.
combat
(
houyi
)
houyi
.
combat
(
yase
)
#当调用combat()时,可以输出"xxxx对xxx发起进攻,造成xx点伤害,xxx还剩下x血量"
#发动攻击后,当被攻击者的血量大于0,则输出:xxx对xx发起进攻,造成x点伤害
#xx还剩下x血量当被攻击者的血量小于等于0,则输出:xx对xx发起进攻造成x点伤害,xx阵亡,游戏结束
\ 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