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
0c4f2fed
authored
Dec 20, 2020
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
4ae2f0d0
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
9 deletions
diy1.py
diy1.py
View file @
0c4f2fed
import
random
class
Monster
():
def
__init__
(
self
,
name
,
hp
,
attack
,
attack_info
,
treatment
):
self
.
level
=
1
self
.
name
=
name
self
.
hp
=
hp
self
.
max_hp
=
self
.
hp
self
.
attack
=
attack
self
.
attack_info
=
attack_info
self
.
treatment
=
treatment
...
...
@@ -26,10 +27,10 @@ class Monster():
exit
()
def
cure
(
self
):
# 治疗
self
.
hp
=
self
.
hp
+
60
self
.
hp
=
self
.
hp
+
self
.
treatment
if
self
.
hp
>
self
.
max_hp
:
self
.
hp
=
self
.
max_hp
print
(
self
.
name
+
"
使用了治疗
,血量增加:"
,
60
,
",目前的血量为:"
,
self
.
hp
)
print
(
self
.
name
+
"
饮用露珠
,血量增加:"
,
60
,
",目前的血量为:"
,
self
.
hp
)
def
meet
(
self
,
enemy
):
pass
...
...
@@ -41,9 +42,28 @@ flowey = Monster("flowey",10,2,"射出'友谊颗粒'",2)
frogey
=
Monster
(
"frogey"
,
8
,
3
,
"用舌头弹了一下"
,
3
)
print
(
"角色创建成功-"
+
player
.
name
)
print
(
"角色属性:"
+
str
(
player
.
hp
)
+
" "
+
str
(
player
.
attack
)
+
" "
+
str
(
player
.
treatment
)
+
"(血量 攻击力 治疗值)"
+
"
\n
"
+
"-"
*
30
)
print
(
"输入'exit'来结束游戏"
)
def
battle
(
enemy
):
print
(
"你遇到了"
+
enemy
.
name
)
print
(
" 战斗开始"
)
print
(
"-"
*
30
)
while
True
:
choice
=
input
(
"请选择行动方式(1_攻击 /2_治疗)_"
)
if
chocie
==
"exit"
:
print
(
"游戏结束"
)
exit
()
elif
choice
==
"1"
:
player
.
combat
(
enemy
)
elif
choice
==
"2"
:
player
.
cure
()
else
:
print
(
"输入无效!"
)
continue
enemy_choice
=
random
.
randint
(
1
,
2
)
if
enemy_choice
==
"1"
:
enemy
.
combat
(
player
)
elif
enemy_choice
==
"2"
:
enemy
.
cure
()
def
battle
()
print
(
"你遇到了frogy"
)
print
(
" 战斗开始"
)
print
(
"-"
*
30
)
choice
=
input
(
"请选择行动方式(A_攻击 /B_治疗)_"
)
\ No newline at end of file
battle
(
flowey
)
\ 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