Python練習(day7)

來源:互聯網
上載者:User

標籤:裝備   技能   log   練習   elf   ack   amp   互動   mon   

定義銳雯類:    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練習(day7)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.