理解面向对象编写的极致简单的小代码

# cheer_xiong
# (`・ω・´) python

# 对战类游戏
import random
import time



class ShadowDominates:  # 影流之主
    camp = 'Shadow_Isles'  # 暗影岛

    def __init__(self, name, ad=40, hp=450):
        self.name = name  # 名字
        self.ad = ad  # 攻击力
        self.hp = hp  # 血量

    def Q(self, Hero):  # Q技能 影奥义!诸刃
        hit_rate = random.randint(0, 100)
        if hit_rate >= 0 and hit_rate <= 80:
            Hero.hp -= self.ad
            print(f"{self.name}使用劫Q中了对面的{Hero.name}使用的亚索!")
        else:
            print(f'{Hero.name}的亚索通过走位躲开了Q技能')

    def W(self):  # W技能 影奥义!分身
        print("劫使用w往后撤退了,这无疑是给亚索机会呀")

    def E(self, Hero):  # E技能 影奥义!鬼斩
        Hero.hp -= self.ad
        print(f"{self.name}使用劫E中了对面的{Hero.name}使用的亚索!")

    def R(self, Hero):  # R技能 禁奥义!瞬狱影杀阵
        Hero.hp -= self.ad * 2
        print(f"{self.name}使用劫的最终奥义-瞬狱影杀阵-。效果十分显著!")


class HurricaneSwordsman:  # 疾风剑豪
    camp = 'Lone_Ranger'  # 独行侠

    def __init__(self, name, ad=22, hp=500):
        self.name = name  # 名字
        self.ad = ad  # 攻击力
        self.hp = hp  # 血量

    def Q(self, Hero):  # Q技能 斩钢闪
        hit_rate = random.randint(0, 100)
        if hit_rate >= 0 and hit_rate <= 80:
            Hero.hp -= self.ad
            print(f"{self.name}使用亚索Q中了对面的{Hero.name}使用的劫!")
        else:
            print(f'{Hero.name}的劫通过走位躲开了Q技能')

    def W(self):  # W技能 风墙
        print("亚索使用了风墙,太强了!")

    def E(self, Hero):  # E技能 踏浪斩
        Hero.hp -= self.ad
        print(f"{self.name}使用亚索踩在了对面的{Hero.name}使用的劫的脸上!")

    def R(self, Hero):  # R技能 狂风绝息斩
        Hero.hp -= self.ad * 2
        print(f"{self.name}瞬间击飞劫,接上-狂风绝息斩-!")


class Equipment:
    def BF_sword(self, hero):  # 暴风大剑
        hero.ad += 30


player1 = ShadowDominates('Faker')
player2 = HurricaneSwordsman('xiong_chao')
ZB = Equipment()
ZB.BF_sword(player2)  #疾风剑豪装备了bf大剑
print(f"疾风剑豪装备了bf大剑,攻击力为:{player2.ad}")

while True:
    if player2.hp < 0:
        print(f"{player2.name}的血量{player2.hp}")
        print(f"{player1.name}的劫击败了{player2.name}")
        break
    if player1.hp < 0:
        print(f"{player1.name}的血量{player1.hp}")
        print(f"{player2.name}的亚索击败了{player1.name}")

        break
    choose_who = random.randint(0, 7)
    time.sleep(0.5)
    if choose_who == 0:
        player1.Q(player2)
        print(f"{player2.name}的血量{player2.hp}")
    if choose_who == 1:
        player1.W()
        print(f"{player2.name}的血量{player2.hp}")
    if choose_who == 2:
        player1.E(player2)
        print(f"{player2.name}的血量{player2.hp}")
    if choose_who == 3:
        player1.R(player2)
        print(f"{player2.name}的血量{player2.hp}")
    if choose_who == 4:
        player2.Q(player1)
        print(f"{player1.name}的血量{player1.hp}")
    if choose_who == 5:
        player2.W()
        print(f"{player1.name}的血量{player1.hp}")
    if choose_who == 6:
        player2.E(player1)
        print(f"{player1.name}的血量{player1.hp}")
    if choose_who == 7:
        player2.R(player1)
        print(f"{player1.name}的血量{player1.hp}")

posted @ 2019-08-26 16:49  cheerxiong  阅读(269)  评论(0编辑  收藏  举报