Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
lesson16_2
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
73cd0100
authored
Dec 20, 2020
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
80d792b3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
12 deletions
diy1.py
diy1.py
View file @
73cd0100
import
random
import
random
class
Monster
():
class
Monster
():
def
__init__
(
self
,
name
,
hp
,
attack
,
attack_info
,
treatment
):
def
__init__
(
self
,
name
,
hp
,
attack
,
attack_info
):
self
.
level
=
1
self
.
level
=
1
self
.
name
=
name
self
.
name
=
name
self
.
hp
=
hp
self
.
hp
=
hp
self
.
max_hp
=
self
.
hp
self
.
max_hp
=
self
.
hp
self
.
attack
=
attack
self
.
attack
=
attack
self
.
attack_info
=
attack_info
self
.
attack_info
=
attack_info
self
.
treatment
=
treatment
def
combat
(
self
,
enemy
):
# 攻击
def
combat
(
self
,
enemy
):
# 攻击
enemy
.
hp
-=
self
.
attack
enemy
.
hp
-=
self
.
attack
...
@@ -27,28 +26,31 @@ class Monster():
...
@@ -27,28 +26,31 @@ class Monster():
exit
()
exit
()
def
cure
(
self
):
# 治疗
def
cure
(
self
):
# 治疗
self
.
hp
=
self
.
hp
+
self
.
treatment
blood
=
random
.
randint
(
2
,
4
)
self
.
hp
=
self
.
hp
+
blood
if
self
.
hp
>
self
.
max_hp
:
if
self
.
hp
>
self
.
max_hp
:
self
.
hp
=
self
.
max_hp
self
.
hp
=
self
.
max_hp
print
(
self
.
name
+
"饮用露珠,血量增加:"
,
self
.
treatment
,
",目前的血量为:"
,
self
.
hp
,
"
\n
"
,
"-"
*
30
)
print
(
self
.
name
,
"磕了口药,血量增加"
,
blood
,
","
,
self
.
name
,
"目前的血量为"
,
self
.
hp
)
def
meet
(
self
,
enemy
):
def
meet
(
self
,
enemy
):
pass
pass
name
=
input
(
"取个响亮的名字吧_"
)
name
=
input
(
"取个响亮的名字吧_"
)
print
(
"你是_"
+
name
+
"
\n
"
+
"-"
*
30
)
print
(
"你是_"
+
name
+
"
\n
"
+
"-"
*
30
)
player
=
Monster
(
name
,
20
,
3
,
"挥动拳头"
,
4
)
player
=
Monster
(
name
,
20
,
4
,
"挥动拳头"
)
flowey
=
Monster
(
"flowey"
,
10
,
2
,
"射出'友谊颗粒'"
,
2
)
flowey
=
Monster
(
"flowey"
,
30
,
4
,
"射出'友谊颗粒'"
)
frog
ey
=
Monster
(
"frogey"
,
8
,
3
,
"用舌头弹了一下"
,
3
)
frog
y
=
Monster
(
"frogy"
,
25
,
3
,
"用舌头弹了一下"
)
print
(
"角色创建成功-"
+
player
.
name
)
print
(
"角色创建成功-"
+
player
.
name
)
print
(
"角色属性:"
+
str
(
player
.
hp
)
+
" "
+
str
(
player
.
attack
)
+
"
"
+
str
(
player
.
treatment
)
+
"
(血量 攻击力 治疗值)"
)
print
(
"角色属性:"
+
str
(
player
.
hp
)
+
" "
+
str
(
player
.
attack
)
+
"
随机2-4
(血量 攻击力 治疗值)"
)
print
(
"输入'exit'来结束游戏"
+
"
\n
"
+
"-"
*
30
)
print
(
"输入'exit'来结束游戏"
+
"
\n
"
+
"-"
*
30
)
def
battle
(
enemy
):
def
battle
(
enemy
):
print
(
"你遇到了"
+
enemy
.
name
)
print
(
"你遇到了"
+
enemy
.
name
)
print
(
" 战斗开始"
)
print
(
"-"
*
30
)
print
(
"-"
*
30
)
print
(
" 战斗开始"
)
while
True
:
while
True
:
print
(
"-"
*
30
)
choice
=
input
(
"请选择行动方式(1_攻击 /2_治疗)_"
)
choice
=
input
(
"请选择行动方式(1_攻击 /2_治疗)_"
)
if
choice
==
"exit"
:
if
choice
==
"exit"
:
print
(
"游戏结束"
)
print
(
"游戏结束"
)
...
@@ -58,7 +60,7 @@ def battle(enemy):
...
@@ -58,7 +60,7 @@ def battle(enemy):
elif
choice
==
"2"
:
elif
choice
==
"2"
:
player
.
cure
()
player
.
cure
()
else
:
else
:
print
(
"输入无效!"
+
"
\n
"
+
"-"
*
30
)
print
(
"输入无效!"
)
continue
continue
a_choice
=
random
.
randint
(
1
,
2
)
a_choice
=
random
.
randint
(
1
,
2
)
if
a_choice
==
1
:
if
a_choice
==
1
:
...
@@ -66,4 +68,4 @@ def battle(enemy):
...
@@ -66,4 +68,4 @@ def battle(enemy):
elif
a_choice
==
2
:
elif
a_choice
==
2
:
enemy
.
cure
()
enemy
.
cure
()
battle
(
flowey
)
battle
(
frogy
)
\ No newline at end of file
\ 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