• LOL游戏基本代码


    class Hero:
    def __init__(self, new_nickname,
    new_aggressivity,
    new_life_value,
    new_money,
    new_armor # 护甲值为:12
    ):
    self.nickname = new_nickname
    self.aggressivity = new_aggressivity
    self.life = new_life_value
    self.money = new_money
    self.armor = new_armor
    self.equip_list = []
    self.count = 0

    def __str__(self):
    if self.count == 1:return '请不要鞭尸!谢谢合作'
    if self.life == 0:
    self.count += 1
    return '这傻叉已经被你活活打死了哦!'
    else:
    msg = "(英雄)%s的攻击力为:%d,生命值为:%d,你有:%d金币,护甲值:%d"
    % (self.nickname, self.aggressivity, self.life, self.money, self.armor)
    msg += " 身上的装备有%s" % (str(self.equip_list))
    return msg

    def add_equip(self, equip):
    self.money -= equip.get_price() # 装备的价钱!用自己的钱购买装备后的余额
    self.aggressivity += equip.aggrev
    self.equip_list.append(equip.get_name())

    def attack(self, enemy):
    damage_value = self.aggressivity - enemy.armor # 再减护甲值相当于掉血量damage_value
    enemy.life -= damage_value
    if enemy.life < 0:
    enemy.life = 0 # 如果血量是负数说明已经死了!写血量为0即可
    print('%s向%s发起了一次攻击' % (self.nickname, enemy.nickname))
    print('%s的生命值减少了%s,剩余生命值为%s' % (enemy.nickname, damage_value, enemy.life))


    class Equip:
    def __init__(self, new_name, new_price, life_value, new_aggrev):
    self.name = new_name
    self.price = new_price # BlackCleaver
    self.lif_value = life_value
    self.aggrev = new_aggrev

    def __str__(self):
    return "装备(%s)的价钱为:%d" % (self.name, self.price)

    def get_price(self):
    return self.price

    def get_name(self):
    return self.name


    Ruiwen = Hero('锐雯', 54, 414, 9999, 12)
    print(Ruiwen)
    shop_duolanjian = Equip('多兰之刃', 475, 100, 9)
    print(shop_duolanjian)
    shop_wujin = Equip('无尽之刃', 3600, 0, 80)
    print(shop_wujin)

    Ruiwen.add_equip(shop_duolanjian)
    print(Ruiwen)
    Ruiwen.add_equip(shop_wujin)
    print(Ruiwen)
    Ruiwen.add_equip(shop_wujin)
    print(Ruiwen)
    Gailun = Hero('盖伦', 54, 455, 9999, 19)
    print(Gailun)
    Gailun.attack(Ruiwen)

    print(Ruiwen) # 查看锐雯是不是被攻击并血量值减少了
    Ruiwen.attack(Gailun)
    print()
    print(Gailun)
    Ruiwen.attack(Gailun)
    print()
    print(Gailun)
    Ruiwen.attack(Gailun)
    print()
    # Ruiwen.attack(Gailun)#好像已经死了,不存在鞭尸的哦!- -
    print(Gailun)
    print('-'*50)
    Ruiwen.attack(Gailun)
    print()
    print(Gailun)
  • 相关阅读:
    firefox上网问题解决
    ubuntu内核的编译安装
    ubuntu常用命令
    source insight 添加文件类型
    ubuntu版本查看命令
    百年孤独与拉丁美洲历史--转载
    Guess Number Higher or Lower II--困惑
    Symmetric Tree
    一棵开花的树
    yii2 mysql数据库读写分离配置
  • 原文地址:https://www.cnblogs.com/wangcheng9418/p/9230088.html
Copyright © 2020-2023  润新知