面向对象初始应用和认知2
生活随笔
收集整理的這篇文章主要介紹了
面向对象初始应用和认知2
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
# class People:
# animal = '高級動物'
# soup = '有靈魂'
# language = '語言'
# def __init__(self,nation,name,sex,age,lenght):
# self.nation=nation
# self.name = name
# self.sex = sex
# self.age = age
# self.lenght = lenght
# def f1(self):
# print("%s在吃飯"%self.name)
# def f2(self):
# print("%s在睡覺"%self.name)
# def f3(self):
# print("%s在工作"%self.name)
# p1=People("中國","alex","未知",42,175)
# p2=People("韓國","金所炫","女",21,170)
class GameRole:gamename="lol"gamers="兩億"gamenature="端游對戰"count=0def __init__(self,name,ad,hp):GameRole.count=self.count+1#GameRole.count=GameRole.count+1self.name=nameself.ad=adself.hp=hpprint(GameRole.count)def attack(self,p):p.hp-=self.adprint("%s攻擊了%s,%s受到了%s傷害,還剩%s血量"%(self.name,p.name,p.name,self.ad,p.hp))def game_equipment(self,equipment):self.equipment=equipment
class Shop:def __init__(self,name,ad):self.name=nameself.ad=addef slaughter(self,p1,p2):p2.hp-=self.adprint("%s用%s攻擊了%s,%s收到了%s傷害,還剩%s點血量"%(p1.name,self.name,p2.name,p2.name,self.ad,p2.hp))
p1=GameRole("維恩",30,300)
p2=GameRole("納爾",20,400)
sword=Shop("寶劍",60)
# p1.attack(p2)
# sword.slaughter(p1,p2)
p1.game_equipment(sword)
p1.equipment.slaughter(p1,p2)
?
轉載于:https://www.cnblogs.com/zhangdaye/p/9362483.html
總結
以上是生活随笔為你收集整理的面向对象初始应用和认知2的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Educational Codeforc
- 下一篇: 【线段树 集合hash】bzoj437