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
Commit
b39a8d79
authored
Sep 08, 2022
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
9a8f86cd
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
10 deletions
diy2.py
diy3.py
diy2.py
View file @
b39a8d79
...
@@ -9,7 +9,6 @@ class Hero: # 英雄类
...
@@ -9,7 +9,6 @@ class Hero: # 英雄类
self
.
attack
=
'出错了!"attack"未设置'
self
.
attack
=
'出错了!"attack"未设置'
self
.
max_hp
=
self
.
hp
self
.
max_hp
=
self
.
hp
def
combat
(
self
,
enemy
):
# 攻击功能
def
combat
(
self
,
enemy
):
# 攻击功能
info1
=
self
.
name
+
"对"
+
enemy
.
name
+
"发起进攻,"
info1
=
self
.
name
+
"对"
+
enemy
.
name
+
"发起进攻,"
info2
=
"造成"
+
str
(
self
.
attack
)
+
"点伤害,"
info2
=
"造成"
+
str
(
self
.
attack
)
+
"点伤害,"
...
@@ -25,12 +24,33 @@ class Hero: # 英雄类
...
@@ -25,12 +24,33 @@ class Hero: # 英雄类
exit
()
exit
()
def
cure
(
self
):
def
cure
(
self
):
self
.
hp
=
self
.
hp
+
10
curehp
=
random
.
randint
(
5
,
30
)
self
.
hp
=
self
.
hp
+
curehp
if
self
.
hp
>
self
.
hp_max
:
if
self
.
hp
>
self
.
hp_max
:
self
.
hp
=
250
self
.
hp
=
250
print
(
str
(
self
.
name
),
'血量已达到最大限制!'
)
else
:
else
:
print
(
str
(
self
.
name
),
'回血成功!血量加10点,目前血量:'
,
str
(
self
.
hp
))
pass
print
(
str
(
self
.
name
),
'回血成功!目前血量:'
,
str
(
self
.
hp
))
# print('log:',curehp)
def
wk
(
self
):
wkmax
=
random
.
randint
(
0
,
20
)
# print('log:',wkmax)
if
wkmax
>
9
:
print
(
self
.
name
,
'没有挖到任何东西'
)
else
:
wkmax2
=
int
(
random
.
randint
(
1
,
3
))
self
.
level
=
self
.
level
+
wkmax2
print
(
self
.
name
,
'挖到了'
,
wkmax2
,
'经验,目前经验:'
,
self
.
level
)
def
sj
(
self
):
if
self
.
level
>=
5
:
self
.
hp
=
self
.
hp
+
30
self
.
attack
=
self
.
attack
+
5
self
.
level
=
self
.
level
-
5
print
(
str
(
self
.
name
),
'升级成功!血量加30,攻击力加5,扣除经验5'
)
else
:
print
(
str
(
self
.
name
),
'经验不足,无法升级'
)
class
Player
(
Hero
):
# 玩家英雄
class
Player
(
Hero
):
# 玩家英雄
def
__init__
(
self
,
name
,
hp
,
attack
):
def
__init__
(
self
,
name
,
hp
,
attack
):
...
@@ -41,17 +61,42 @@ class Player(Hero): # 玩家英雄
...
@@ -41,17 +61,42 @@ class Player(Hero): # 玩家英雄
print
(
str
(
self
.
name
)
+
'创建成功!血量:'
,
str
(
self
.
hp
),
',攻击力:'
,
str
(
self
.
attack
))
print
(
str
(
self
.
name
)
+
'创建成功!血量:'
,
str
(
self
.
hp
),
',攻击力:'
,
str
(
self
.
attack
))
player1
=
Player
(
"后羿"
,
2
20
,
1
5
)
player1
=
Player
(
"后羿"
,
2
00
,
5
)
player2
=
Player
(
"亚瑟"
,
2
50
,
10
)
player2
=
Player
(
"亚瑟"
,
2
00
,
5
)
while
True
:
while
True
:
print
(
'
--------------------------------'
)
print
(
'
='
*
35
)
user_input
=
str
(
input
(
'请选择英雄技能(1:攻击,2:回血
)
'
))
user_input
=
str
(
input
(
'请选择英雄技能(1:攻击,2:回血
,3:挖矿):
'
))
if
user_input
==
"1"
:
if
user_input
==
"1"
:
player1
.
combat
(
player2
)
player1
.
combat
(
player2
)
if
player2
.
hp
>
50
:
if
player2
.
hp
>
50
:
player2
.
combat
(
player1
)
player2
.
combat
(
player1
)
else
:
else
:
player2
.
cure
()
player2
.
cure
()
if
user_input
==
"2"
:
elif
user_input
==
"2"
:
player2
.
cure
()
player1
.
cure
()
player1
.
cure
()
if
random
.
randint
(
0
,
1
)
==
0
:
if
player2
.
level
>=
5
:
player2
.
wk
()
else
:
player2
.
cure
()
elif
user_input
==
"3"
:
player1
.
wk
()
if
random
.
randint
(
0
,
1
)
==
0
:
if
player2
.
level
>=
5
:
player2
.
wk
()
else
:
player2
.
cure
()
else
:
player2
.
combat
(
player1
)
elif
user_input
==
"4"
:
player1
.
sj
()
if
random
.
randint
(
0
,
1
)
==
0
:
if
player2
.
level
>=
5
:
player2
.
wk
()
else
:
player2
.
cure
()
else
:
player2
.
combat
(
player1
)
else
:
print
(
'无效字符,请重新输入'
)
\ No newline at end of file
diy3.py
0 → 100644
View file @
b39a8d79
a
=
[
1
,
2
,
3
,
4
,
5
]
print
(
a
)
a
.
append
(
12
)
print
(
a
)
\ 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