Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
bellcode
/
lesson15_3
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
You need to sign in or sign up before continuing.
Commit
dd1b0974
authored
Oct 04, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
c7e94689
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
35 deletions
diy2.py
diy2.py
View file @
dd1b0974
class
Hero
:
# 英雄类
import
turtle
def
__init__
(
self
,
name
):
# 实例属性
len
=
20
self
.
name
=
name
screen
=
turtle
.
Screen
()
self
.
level
=
1
screen
.
bgcolor
(
"light green"
)
self
.
hp
=
250
pen
=
turtle
.
Pen
()
self
.
attack
=
40
pen
.
penup
()
self
.
max_hp
=
self
.
hp
pen
.
goto
(
100
,
-
100
)
pen
.
write
(
"傻逼,
\n
大傻逼"
,
font
=
(
"time"
,
20
,
"normal"
))
pen
.
hideturtle
()
def
combat
(
self
,
enemy
):
# 攻击功能
pen1
=
turtle
.
Pen
()
info1
=
self
.
name
+
"对"
+
enemy
.
name
+
"发起进攻,"
pen1
.
pensize
(
5
)
info2
=
"造成"
+
str
(
self
.
attack
)
+
"点伤害,"
pen1
.
pencolor
(
"green"
)
enemy
.
hp
-=
self
.
attack
pen1
.
left
(
45
)
if
enemy
.
hp
>
0
:
pen1
.
forward
(
2
*
len
)
info3
=
enemy
.
name
+
"还剩下"
+
str
(
enemy
.
hp
)
+
"血量"
pen1
.
circle
(
len
,
180
)
info
=
info1
+
info2
+
info3
pen1
.
right
(
90
)
print
(
info
)
pen1
.
circle
(
len
,
180
)
else
:
pen1
.
forward
(
2
*
len
)
info3
=
enemy
.
name
+
"阵亡,游戏结束"
pen1
.
hideturtle
()
info
=
info1
+
info2
+
info3
turtle
.
done
()
print
(
info
)
\ No newline at end of file
exit
()
class
Player
(
Hero
):
# 玩家英雄
def
__init__
(
self
,
name
,
Hero_type
):
super
()
.
__init__
(
name
)
self
.
hp
=
200
self
.
attack
=
50
self
.
Hero_type
=
Hero_type
print
(
"角色"
+
str
(
self
.
name
)
+
"创建成功,"
+
"英雄类型为"
+
str
(
Hero_type
))
print
(
"当前等级,血量,攻击力分别为:"
+
str
(
self
.
level
)
+
str
(
self
.
hp
)
+
str
(
self
.
attack
))
a
=
Player
()
print
(
a
)
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