-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBag.py
106 lines (99 loc) · 3.23 KB
/
Bag.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# -*- coding: utf-8 -*-
"""
Created on Fri Aug 3 07:44:14 2018
@author: X
"""
class Bag(object):
def __init__(self):
self.bagCapacity = 5
self.bag_ = []
self.bagName = 'bag'
pass
def addItem(self,item_):
if len(self.bag_)<self.bagCapacity:
self.bag_.append(item_)
return False
else:
return True
pass
def popItem(self,itemName_):
itemTemp = None
for i in self.bag_:
if (i.Name == itemName_)or(i.shortName == itemName_):
itemTemp = i
#assiIndex = self.bag_.index(itemTemp)
break
if itemTemp is not None:
self.bag_.remove(itemTemp)
return itemTemp
else:
#print('No such thing in your bag.')
return None
pass
def info(self):
if len(self.bag_)>0:
for i in self.bag_:
print('{num}\{itemname}({shortname})'.format(num=self.bag_.index(i)+1,itemname=i.Name,shortname=i.shortName))
#print(self.bag_.index(i)+1,'\\',i.Name)
else:
print('Empty')
#print(self.bag_)
#print(len(self.bag_))
pass
# def discard(self,itemName_):
# _=popItem(itemName_)
# pass
class weaponSlot(Bag):
def __init__(self):
self.bagCapacity = 3
self.bag_ = []
self.bagName = 'weapon slot'
def multiWeaponCheck(self,weapon_):
weaponCount = 1
for i in self.bag_:
if weapon_.Name == i.Name:
weaponCount+=1
weapon_.shortName=weapon_.shortName+str(weaponCount)
return weapon_
def info(self):
if len(self.bag_)>0:
for i in self.bag_:
print('{num}|{itemname}({shortname})|{gunInfo}'.format(num=self.bag_.index(i)+1,\
itemname=i.Name,shortname=i.shortName,gunInfo = i.type.gunInfo()))
else:
print('Empty')
pass
class bulletBag(object):
def __init__(self):
self.bulletPackCapacity = 80
self.bagCapacity = 3
self.bag_=[]
self.bagName = 'bullet bag'
self.bulletNumDict = {}
def addItem(self,bP):
if len(self.bag_)<self.bagCapacity:
if bP.Name in self.bulletNumDict.keys():
self.bulletNumDict[bP.Name]+=bP.numOfBullets
else:
self.bulletNumDict[bP.Name]=bP.numOfBullets
#self.bag_.append(item_)
return False
else:
return True
def popBullet(self,bullteName,requiredBulletNum):
if bullteName in self.bulletNumDict.keys():
bulletNum = self.bulletNumDict[bullteName]
if bulletNum>0 and bulletNum>=requiredBulletNum:
self.bulletNumDict[bullteName] -= requiredBulletNum
return requiredBulletNum
else:
self.bulletNumDict[bullteName] = 0
return bulletNum
else:
print("This type of bullet doesn't existed. ")
return 0
pass
def info(self):
for key,value in self.bulletNumDict.items():
print('{name}:{num}'.format(name=key,num=value))
pass