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
ff1d6fb9
authored
Jul 30, 2022
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
01577f95
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
10 deletions
diy1.py
diy1.py
View file @
ff1d6fb9
# 英雄角色类
import
random
# 英雄角色类
class
Hero
(
object
):
def
__init__
(
self
,
name
):
def
__init__
(
self
,
name
,
hp
,
att
):
self
.
level
=
1
self
.
hp
=
250
self
.
att
=
40
self
.
hp
=
hp
self
.
att
=
att
self
.
name
=
name
self
.
type
=
'pc'
def
combat
(
self
,
enemy
):
# 攻击
def
combat
(
self
,
enemy
):
m
=
True
if
self
.
type
==
'pc'
:
self
.
hp
>
60
else
:
m
=
input
(
f
'{self.name} 1=att 2=hp'
)
==
'1'
if
enemy
.
hp
>
0
:
if
m
:
if
random
.
randint
(
1
,
100
)
<=
50
:
enemy
.
hp
-=
self
.
att
*
2
print
(
f
'{self.name} high attack to {enemy.name},'
,
end
=
""
)
print
(
f
'it got {self.att*2} blode,'
,
end
=
""
)
else
:
# 攻击
enemy
.
hp
-=
self
.
att
print
(
f
'{self.name}attack to{enemy.name},'
,
end
=
""
)
print
(
f
'it got{self.att}blode,'
,
end
=
""
)
print
(
f
'{self.name} attack to {enemy.name},'
,
end
=
""
)
print
(
f
'it got {self.att} blode,'
,
end
=
""
)
else
:
self
.
hp
+=
20
print
(
f
'{self.name} heal 20 bolde'
)
if
enemy
.
hp
<=
0
:
print
(
f
'{enemy.name}dide,game over.'
)
print
(
f
'{enemy.name}
dide,game over.'
)
exit
()
else
:
print
(
f
'{enemy.name} surplus {enemy.hp} blode.'
)
yase
=
Hero
(
"垭瑟"
)
houyi
=
Hero
(
"后羿"
)
yase
=
Hero
(
"垭瑟"
,
300
,
25
)
houyi
=
Hero
(
"后羿"
,
260
,
30
)
ch
=
input
(
'1=yase 2=houyi 3=none'
)
if
ch
==
'1'
:
yase
.
type
=
'human'
elif
ch
==
'2'
:
houyi
.
type
=
'human'
while
True
:
yase
.
combat
(
houyi
)
houyi
.
combat
(
yase
)
\ 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