-
Notifications
You must be signed in to change notification settings - Fork 0
/
inventory.py
53 lines (41 loc) · 1.02 KB
/
inventory.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
class Inventory:
items = []
maxSize = 20
# Insert an item at a specific index
def insertItem(self, index, item):
if len(self.items) >= self.maxSize:
return False
self.items.insert(index,item)
return True
# Insert an item at the end of the item list
def addItem(self, item):
if len(self.items) >= self.maxSize:
return False
self.items.append(item)
return True
def removeItem(self, item):
self.items.remove(item)
def popItem(self):
return self.items.pop()
def getItem(self, index):
try:
item = self.items[index]
except:
return False
return item
def hasItem(self, item):
return item in self.items
# Find and return the first occurence of an item in the list
def findItem(self, name):
for item in self.items:
if item.name == name:
return item
return False
def overcapacity(self):
return len(self.items) > self.maxSize
def setMaxSize(self, maxSize):
self.maxSize = maxSize
def getMaxSize(self):
return self.maxSize
def length(self):
return len(self.items)