Python Practice (Day7)

Source: Internet
Author: User

定义锐雯类:    class Riven:            camp=‘Noxus‘            def __init__(self,nickname,                                     aggressivity=54,                                     life_value=414,                                     money=1001,                                     armor=3):                    self.nickname=nickname                    self.aggressivity=aggressivity                    self.life_value=life_value                    self.money=money                    self.armor=armor            def attack(self,enemy):                    damage_value=self.aggressivity-enemy.armor                    enemy.life_value-=damage_value

定义盖文类:class Garen:        camp=‘Demacia‘        def __init__(self,nickname,                                 aggressivity=58,                                 life_value=455,                                 money=100,                                 armor=10):                self.nickname=nickname                self.aggressivity=aggressivity                self.life_value=life_value                self.money=money                self.armor=armor        def attack(self,enemy):                damage_value=self.aggressivity-enemy.armor                enemy.life_value-=damage_value

定义装备:    class BlackCleaver:            def __init__(self,price=475,aggrev=9,life_value=100):                    self.price=price                    self.aggrev=aggrev                    self.life_value=life_value            def update(self,obj):                    obj.money-=self.price #减钱                    obj.aggressivity+=self.aggrev #加攻击                    obj.life_value+=self.life_value #加生命值            def fire(self,obj): #这是该装备的主动技能,喷火,烧死对方                    obj.life_value-=1000 #假设火烧的攻击力是1000测试交互:r1=Riven(‘草丛伦‘)g1=Garen(‘盖文‘)b1=BlackCleaver()print(r1.aggressivity,r1.life_value,r1.money) #r1的攻击力,生命值,护甲if r1.money > b1.price:        r1.b1=b1        b1.update(r1)print(r1.aggressivity,r1.life_value,r1.money) #r1的攻击力,生命值,护甲print(g1.life_value)r1.attack(g1) #普通攻击print(g1.life_value)r1.b1.fire(g1) #用装备攻击print(g1.life_value) #g1的生命值小于0就死了

Python Practice (Day7)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.