qfxx第三週1作業

#!/usr/bin/python3
#-*- coding: utf-8 -*-
#-*- author:zhangjiao -*-

'''
1.同桌找了一個女朋友跟你炫耀
同桌類:
特徵:name,sex,age,女朋友
行爲:炫耀
女朋友類
特徵:name,sex,age,facevalue
行爲:做飯  賣萌  敲代碼
'''
class classMate():
    def __init__(self,name,sex,age,hobby):
        self.name=name
        self.sex=sex
        self.age=age
        self.hobby=hobby

    def haveGirlFriend(self):
        self.girlFriend=girlFriend("二丫","女",18,60,'做飯  賣萌  敲代碼')
        print("我有一個叫%s的女朋友,%d歲,顏值%d,喜歡%s"%(self.girlFriend.name,self.girlFriend.age,self.girlFriend.faceValue,self.girlFriend.hobby))

    def selfIntroduction(self):
        print("我是%s,%s歲,喜歡%s"%(self.name,self.age,self.hobby))

    def letGirlIntroduction(self):
        self.girlFriend.selfIntroduction()

class girlFriend():
    def __init__(self,name,sex,age,faceValue,hobby):
        self.name=name
        self.sex=sex
        self.age=age
        self.faceValue=faceValue
        self.hobby=hobby
    def selfIntroduction(self):
        print("我是%s,%s歲,喜歡%s"%(self.name,self.age,self.hobby))

classmate=classMate("二蛋",'男',20,"炫耀")
classmate.selfIntroduction()
classmate.haveGirlFriend()
classmate.letGirlIntroduction()

'''

2.人開槍射擊子彈
人:
特徵:name  槍
行爲:射擊  裝子彈
槍:
特徵:型號  射擊範圍  彈夾
行爲:砰 開槍  上膛

彈夾:
特徵:子彈個數
行爲: 加彈  減彈
'''
class man():
    def __init__(self,name):
        self.name=name
        self.guns=gun()

    def shoot(self):
        if self.guns.clips.nun>=0:
            self.guns.loaded()
            self.guns.shooting()
        else:
            print("需要裝子彈")
            self.loading()

    def loadingAll(self):
        print("正在換彈夾")
        self.guns.clips.__init__()

    def loadingOne(self):
        print("正在給彈夾上一顆子彈")
        self.guns.clips.addc()

class gun():
    def __init__(self):
        self.clips=clip()

    def  loaded(self):
        print("上膛中")
        print('預備')

    def shooting(self):
        print("砰")
        self.clips.reducec()


class clip():
    def __init__(self):
        self.nun=7

    def addc(self):
        if self.nun==7:
            print("彈夾已滿")
        else:
            self.nun+=1
            print("正在加彈")

    def reducec(self):
        if self.nun==0:
            print("彈夾已空")
        else:
            self.nun-=1
            print("正在減彈")



if __name__=="__main__":
    man1=man(input("我是:"))
    while 1:
        a=int(input("你手裏有一把槍,請選擇操作:\n"+
                "1:開槍   2:換彈夾  3:給彈夾上一顆子彈\n"+
                "4:退出射擊\n"))
        if a==1:
            man1.shoot()
        elif a==2:
            man1.loadingAll()
        elif a==3:
            man1.loadingOne()
        elif a==4:
            break
        print("你現在槍裏還有%d顆子彈"%man1.guns.clips.nun)
    print("歡迎再來")




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章