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
f6055992
authored
Oct 30, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
0f16447f
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
2 additions
and
45 deletions
diy1.py
diy1.py
View file @
f6055992
# 英雄角色类
class
Player
import
random
\ No newline at end of file
class
Hero
(
object
):
def
__init__
(
self
,
name
):
self
.
level
=
1
self
.
hp
=
250
self
.
attack
=
40
self
.
name
=
name
def
combat
(
self
,
enemy
):
# 攻击
enemy
.
hp
-=
self
.
attack
blon1
=
self
.
name
+
'对'
+
enemy
.
name
blon2
=
'造成了'
+
str
(
self
.
attack
)
+
'伤害'
if
enemy
.
hp
>
0
:
blon3
=
enemy
.
name
+
'还剩'
+
str
(
enemy
.
hp
)
blon
=
blon1
+
blon2
+
blon3
print
(
blon
)
else
:
print
(
enemy
.
name
+
'阵亡'
+
'游戏结束'
)
blon
=
blon1
+
blon2
+
blon3
print
(
blon
)
exit
()
def
cure
(
self
):
self
.
hp
=
self
.
hp
+
30
if
self
.
hp
>
self
.
max_hp
:
self
.
hp
=
self
.
max_hp
yase
=
Hero
(
"垭瑟"
)
houyi
=
Hero
(
"后羿"
)
yase
.
combat
(
houyi
)
print
(
"-"
*
30
)
print
(
" 战斗开始"
)
while
True
:
print
(
"-"
*
30
)
a
=
input
(
"1、攻击,2、治疗,q、游戏退出"
)
if
a
==
"q"
:
exit
()
if
a
==
"1"
:
houyi
.
combat
(
yase
)
if
a
==
"2"
:
houyi
.
cure
()
b
=
random
.
randint
(
1
,
3
)
if
b
==
1
:
yase
.
cure
()
elif
b
==
2
:
yase
.
combat
(
houyi
)
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