Commit c8d23e97 by BellCodeEditor

save project

parent 7ad6e31b
Showing with 24 additions and 7 deletions
# 英雄角色类 class Hero:
class Hero(object):
def __init__(self, name): def __init__(self, name):
self.level = 1 self.level = 1
self.hp = 250 self.hp = 200
self.attack = 40 self.attack = 40
self.name = name self.name = name
def combat(self, enemy): # 攻击 def combat(self, enemy):
enemy.hp -= self.attack enemy.hp -= self.attack
info_1 = self.name + '对' + enemy.name+'发起进攻!' info_1 = self.name + '对' + enemy.name+'发起进攻!'
info_2 = '造成了' + str(self.attack)+ '点伤害' info_2 = '造成了' + str(self.attack)+ '点伤害'
...@@ -15,10 +14,10 @@ class Hero(object): ...@@ -15,10 +14,10 @@ class Hero(object):
info = info_1 + info_2 + info_3 info = info_1 + info_2 + info_3
print(info) print(info)
else: else:
info_3 = enemy.name + '已阵亡!' info_3 = enemy.name + '已阵亡!'
info = info_1 + info_2 + info_3 info = info_1 + info_2 + info_3
print(info) print(info)
yase = Hero("垭瑟") yase = Hero('亚瑟')
houyi= Hero("后羿") houyi = Hero('后羿')
yase.combat(houyi) yase.combat(houyi)
\ No newline at end of file
class Cat:
def __init__(self):
self.footNum = 4 # 腿
self.eyeNum = 2 # 眼睛
self.head = 1 # 头
self.earsNum = 2 # 耳朵
self.skin = "black"
def run(self):
print("小猫飞快的跑起来")
def skill(self, prey):
print('小猫抓住了'+ prey)
tom = Cat()
tom.skill("老鼠")
\ No newline at end of file
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