# 類
class student:
Class = "G20大資料1班" #類屬性(大家都有,且一樣)
def __init__(self,name,number): #實體屬性(大家都有,但是不一樣)
self.name = name
self.no = number
student1 = student("張三","20200001") #實體化物件
# 反恐精英\
# 人
class Person:
def __init__(self,name):
self.name = name
self.blood = 100
def install_bull(self,clip,bullet): # 裝子彈方法
clip.save_bullets(bullet) # 呼叫彈夾安裝子彈方法來實作
def install_clip(self, clip, Gun):
Gun.install_clip(clip)
class Clip:
def __init__(self,capacity):
self.capacity = capacity
self.current_list = []
def save_bullets(self,bullet):#安裝子彈
if len(self.current_list)<self.capacity:
self.current_list.append(bullet)
print("安裝子彈成功")
print("當前子彈數目{}/{}".format(len(self.current_list),self.capacity))
class bullet:
pass
class gun:
def __init__(self):
self.clip = None
def install_clip(self,clip):
if not self.clip:
self.clip = clip
print("槍已經裝上彈夾,目前彈夾容量{}/{}".format(len(clip.current_list),clip.capacity))
Solider1 = Person("牛戰士")
clip = Clip(30)
i = 0
while True:
bullet1 = bullet()
Solider1.install_bull(clip,bullet1)
if i < 5:
i = i+1
else:
break
Gun = gun() # 生成一把槍
#print(clip.current_list )
Solider1.install_clip(clip,Gun)
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/231584.html
標籤:python
上一篇:openCV學習筆記2—繪圖函式(畫線,矩形,圓形,橢圓,多邊形,在圖片上添加文字)
下一篇:Django框架學習1
