士兵突擊

#-*-coding:utf-8-*-
#新建士兵
class Soldier(object):
    #屬性
    def __init__(self):
        self.name="姓名"
        self.gun="槍"
 
    #定義開火
    def fire(self):
        print("士兵可以開火")
    #定義許三多
    def xu_san(self):
        self.name="許三多"
        print(self.name)
#定義槍
class Gun(Soldier):
    def __init__(self):
        self.bullet_quantity=int(0)  #當前子彈數量
        self.big_bullet=int(30)       #最大數量
    def AK_47(self):
        gun.fire_bullet()
    #定義發射子彈
    def fire_bullet(self):
        while self.bullet_quantity<=int(30) and self.bullet_quantity>=int(0):
            #self.big_bullet
            self.bullet_quantity-=self.bullet_quantity
            #for i in self.bullet_quantity :
            #    print (i)
            print("沒子彈了")
            if self.bullet_quantity==int(0):
                Gun.shot_bullet(self)
                print("正在發射子彈,子彈打完了裝彈!")
                break
    #定義裝填子彈
    def  shot_bullet(self):
        while self.bullet_quantity==int(0) and self.bullet_quantity>=int(30):
            self.bullet_quantity+=self.bullet_quantity
            print("正在裝彈")
            if self.bullet_quantity==int(30):
                print("子彈裝點完畢")
                break
    #士兵突擊
class Soldier_assault(object):
    def xu(self):
        #士兵許三多有一把AK47
        soldier.xu_san()
        #士兵可以開火
        soldier.fire()
        #槍能夠發射子彈
        gun.AK_47()
        #槍裝填子彈,增加子彈數量
soldier=Soldier()  #實例化士兵
#soldier.fire()
#soldier.xu_san()
gun=Gun()
#gun.AK_47()
         #實例化槍
soldier_assault=Soldier_assault() #士兵突擊!
soldier_assault.xu()
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章