Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
bellcode
/
lesson13-1
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
3e1b4f6d
authored
Jun 23, 2024
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
98db3cea
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
39 deletions
diy.py/diy.py
diy1.py
diy.py/diy.py
deleted
100644 → 0
View file @
98db3cea
# class hero:
# def __init__(self,name,hp,attack):
# self.level = 1
# self.name = name
# self.hp=hp
# self.attack=attack
# def shenji(self):
# self.hp=self.hp+50
# self.level=self.level+1
# self.attack=self.attack+4
# yase=hero("yase",300,200)
# yase.shenji()
# print(yase.hp)
# houyi = hero("后裔",200,400)
# houyi.shenji()
# print(houyi.hp)
# 创建一个cat类 每一只猫都有名字(name),年龄(age),性别(sex)
# 每一只猫都有吃东西的行为(print("猫在吃饭")).实例化出一只名字为aa,年龄为10,性别为男的猫 并在控制台打印猫在吃饭
class
cat
:
def
__init__
(
self
,
name
,
age
,
sex
,
hungry
):
self
.
name
=
name
self
.
age
=
age
self
.
sex
=
sex
self
.
hungry
=
hungry
def
eat
(
self
):
self
.
hungry
=
self
.
hungry
-
1
a
=
cat
(
"cat1"
,
11
,
"man"
,
5
)
b
=
cat
(
"cat2"
,
11
,
"man"
,
5
)
a
.
eat
()
a
.
name
=
"a猫"
print
(
a
.
name
)
print
(
b
.
hungry
)
diy1.py
0 → 100644
View file @
3e1b4f6d
class
Hero
(
object
):
def
__init__
(
self
,
name
):
self
.
level
=
1
self
.
hp
=
3500
self
.
name
=
name
self
.
attack
=
388
def
combat
(
self
,
enemy
):
enemy
.
hp
-=
self
.
attack
info1
=
self
.
name
+
'对'
+
enemy
.
name
+
"造成了伤害"
info2
=
'造成了'
+
str
(
self
.
attack
)
+
"真实伤害"
if
enemy
.
hp
<
0
:
info3
=
enemy
.
name
+
'阵亡'
else
:
info3
=
enemy
.
name
+
'剩下'
+
str
(
enemy
.
hp
)
+
"点生命值"
print
(
info1
+
"
\n
"
+
info2
+
"
\n
"
+
info3
)
yase
=
Hero
(
"亚瑟"
)
houyi
=
Hero
(
"后羿"
)
junming
=
Hero
(
"俊明"
)
yase
.
combat
(
houyi
)
\ 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