Commit 638c1e93 by BellCodeEditor

auto save

parent 9a581ef4
Showing with 19 additions and 13 deletions
# 英雄角色类
class Hero(object):
class Hero:
def __init__(self, name):
self.level = 1
self.hp = 250
self.attack = 40
self.name = name
self.level = 1 # 等级
self.hp = 250 # 血量
self.attack = 40 # 攻击力
self.name = name # 名字
def combat(): # 攻击
???
yase = Hero("垭瑟")
houyi= Hero("后羿")
yase.combat(houyi)
\ No newline at end of file
def combat(self,enemy): # def定义战斗()里加上参数,形参1
enemy.hp -= self.attack # ∵受到的伤害=攻击者的攻击力∴受伤后的血量=初始血量-攻击力
info1 = self.name+"对"+enemy.name"发起攻击," # 攻击者"对"被攻击对象"发起攻击"
info2 = "造成"+str(self.attack)+"点伤害," # "造成"攻击者攻击力"点伤害"
if enemy.hp > 0: # if判断,如果被攻击对象血量>0
info3 = enemy.name+"还剩下"+str(enemy.hp)+"血量" # 被攻击对象"还剩下""血量"
info = info1+info2+info3 # 将3段信息连接
print(info) # 打印出3段信息info
else: # 否则
info3 = enemy.name+"阵亡,游戏结束" # 信息3=被攻击对象"阵亡,游戏结束"
info = info1+info2+info3 # 将3段信息连接
print(info) # 打印出3段信息
exit() # 程序停止
\ 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