Commit 6cf927ee by BellCodeEditor

save project

parent 4e4e29b0
Showing with 28 additions and 10 deletions
class Hero: # 定义Cat类
def __init__(self, name): class Cat
self.level = 1 # 创建__init__()函数方法并放入参数self
self.hp = 250 def _init_(self)
self.attack = 40 # 设置变量footNum小猫腿数量为4
self.name = nameclass Hero: self.footNum=4
def cpmbat(self,enemy): # 设置变量eyeNum小猫眼睛数量为2
ingfol = self.name + "对" + enemy.name + "发起攻击" self.eyeNum=2
info2 = "造成" + str(self.attack) + enemy.name + "发起进攻" # 设置变量head小猫头数量为1
enemy.hp -= self. self.head=1
# 设置变量earsNum小猫耳朵数量为2
self.earsNum=2
# 设置变量skin小猫颜色为black
self.skin="black"
# 创建奔跑run函数方法
def run(self)
# 打印"小猫飞快的跑起来"
print("小猫飞快的跑起来")
# 创建捕猎skill函数方法
def skill(self,prey)
# 打印"小猫抓住了"+prey
print("小猫抓住了"+prey)
# 创建猫对象
cat=cat()
# 调用捕猎方法抓老鼠
cat.skill("老鼠")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment