Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
bellcode
/
lesson15_test2
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
759784f8
authored
Apr 18, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
930c7a23
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
20 deletions
diy2-test.py
game.py
diy2-test.py
View file @
759784f8
class
Dog
:
# 狗类
import
random
def
__init__
(
self
):
for
i
in
range
(
5
):
self
.
footNum
=
4
# 腿
a
=
random
.
randint
(
1
,
2
)
self
.
eyeNum
=
2
# 眼睛
print
(
a
)
self
.
head
=
1
# 头
\ No newline at end of file
self
.
earsNum
=
2
# 耳朵
self
.
skin
=
"white"
def
run
(
self
):
print
(
"狗狗飞快的跑起来"
)
class
Husky
(
Dog
):
# 哈士奇类
def
__init__
(
self
):
super
()
.
__init__
()
self
.
skin
=
"black"
coco
=
Husky
()
print
(
coco
.
skin
)
\ No newline at end of file
game.py
0 → 100644
View file @
759784f8
import
random
class
sheshou
:
def
__init__
(
self
,
name
):
self
.
hp
=
400
self
.
attack
=
80
self
.
name
=
name
def
combit
(
self
,
enemy
):
isbaoji
=
random
.
randint
(
1
,
2
)
if
isbaoji
==
1
:
enemy
.
hp
-=
self
.
attack
if
enemy
.
hp
>
0
:
print
(
f
"{self.name}对{enemy.name}发起了攻击,造成了{self.attack}点伤害,{enemy.name}还剩下{enemy.hp}点血量"
)
else
:
print
(
f
"{self.name}对{enemy.name}发起了攻击,暴击造成了{self.attack}点伤害,{enemy.name}阵亡,游戏结束"
)
exit
()
else
:
enemy
.
hp
-=
self
.
attack
*
2
if
enemy
.
hp
>
0
:
print
(
f
"{self.name}对{enemy.name}发起了攻击,暴击造成了{self.attack*2}点伤害,{enemy.name}还剩下{enemy.hp}点血量"
)
else
:
print
(
f
"{self.name}对{enemy.name}发起了攻击,造成了{self.attack*2}点伤害,{enemy.name}阵亡,游戏结束"
)
exit
()
class
tanke
(
sheshou
):
def
__init__
(
self
,
name
):
super
()
.
__init__
(
name
)
self
.
hp
=
500
self
.
attack
=
70
#创建实例化对象
houyi
=
sheshou
(
name
=
"houyi"
)
yase
=
tanke
(
name
=
"yase"
)
houyi
.
combit
(
enemy
=
yase
)
yase
.
combit
(
enemy
=
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