1 from random import randint
2 from MyConfigConnector import MY_SingleConfigConnector
3
5 """
6 singleton class to hold unique ids for game objects
7
8 @ivar idList: the list of the used id's in the game
9 @type idList: List of Integer
10 """
11
12 __instance = None
13
22
25
27 """
28 gets a free id for any game object
29
30 @rtype: Integer
31 @return: returns a free id that can be used for a unique game element
32 """
33
34 free_id = 0
35 free = False
36 liste = self.idList
37 while not free:
38 old_id = free_id
39 for i in liste:
40 if free_id == i:
41 free_id += 1
42 break
43 if free_id == old_id:
44 free = True
45 break
46
47
48 if len(liste) > 0:
49 for i in range(len(liste)):
50 if free_id > liste[len(liste)-1]:
51 liste.append(free_id)
52 break
53
54 if free_id < liste[i]:
55 n = i
56 old_i = liste[n]
57 while n != len(liste)-1:
58 temp = liste[n+1]
59 liste[n+1] = old_i
60 old_i = temp
61 n += 1
62 liste.append(old_i)
63 liste[i] = free_id
64 break
65 else:
66 liste.append(free_id)
67
68 return free_id
69
71 """
72 sets an id free for further use
73
74 @type free_id: Integer
75 @param free_id: the id that can be freed out of the idList
76 """
77
78 self.idList.remove(free_id)
79
81 """
82 singleton class which holds lists for all ingame stairs, items, hurdles and bullets
83
84 @ivar stairList: the list that conatins all stairs and patforms that exists for the game (NOT in the game)
85 @type stairList: List of Blender scene indices
86 @ivar itemList: the list that conatins all items that exists for the game (NOT in the game)
87 @type itemList: List [Blender scene indices, KX_GameObject]
88 @ivar merchList: the list that conatins all merch items that exists for the game (NOT in the game, so there is a static length per game of this list )
89 @type merchList: List of KX_GameObject
90 @ivar merchObjectList: the list that conatins all merch objects that are used in the game (because linked objects appear twice, so this was a simple workaround to get a faultless game, sorry)
91 @type merchObjectList: List of KX_GameObject
92 """
93
94 __instance = None
95
97 if self.__instance is None:
98 self.__instance = object.__new__(self, *args, **kargs)
99
100
101 self.stairList = []
102 self.itemList = []
103 self.merchList = []
104 self.merchObjectList = []
105 self.collectionList = {}
106 self.littleInfoTextList = []
107 self.bigInfoTextList = []
108
109 return self.__instance
110
113
115 """
116 sets the stair list filled with their indices, to get a random/specific stair later
117
118 @type scene: KX_Scene
119 @param scene: the blender scene object which holds all objects
120 """
121
122 for i, obj in enumerate(scene.objectsInactive):
123 if obj.name[2:7] == "stair":
124 self.stairList.append(i)
125
127 """
128 sets the item list, filled with their indices, to get a random/specific item later
129
130 @type scene: KX_Scene
131 @param scene: the blender scene object which holds all objects
132 """
133
134 for i, obj in enumerate(scene.objectsInactive):
135 name = "OB" + obj.name[7:]
136 if obj.name[2:6] == "item":
137 self.itemList.append([i, obj])
138
140 """
141 creates a list of all merchandise items
142
143 @type scene: KX_Scene
144 @param scene: the blender scene object which holds all objects
145 """
146
147 for obj in scene.objectsInactive:
148 if obj.name[2:7] == "xItem":
149 self.merchList.append(obj)
150
151
153 """
154 class for the player's inventory with all needed methods
155
156 @ivar inventoryList: the list that contains the players skill levels (health etc.). one skill => [number of dose, item name, lifetime]
157 @type inventoryList: List of List [[Integer, String, Integer], ...]
158 """
159
161 self.inventoryList = []
162
164 for i in self.inventoryList:
165 if i[1] == name:
166 return i
167 return "none"
168
170 """
171 sets the inventory with values from the config parser
172 """
173
174 self.inventoryList = []
175 myElementList = MY_SingleElementList().itemList
176
177 for i in range(len(myElementList)):
178 item = myElementList[i][1]
179 self.inventoryList.append([MY_SingleConfigConnector().getPowerUpValue(item.name[7:]), item.name[7:], item["life_time"], item["life_time"]])
180
181 - def useItem(self, item_name, add):
182 """
183 adds or remove an item from its list and the config parser
184
185 @type item_name: String
186 @param item_name: the nameof the item that shall be used
187 @type add: Boolean
188 @param add: True if an item was collected, False if item was used
189
190 @rtype: Boolean
191 @return: 'True' if the item exists, else 'False'
192 """
193
194 item = self[item_name]
195 exist = False
196 if not add:
197 if item[0] >= 1:
198 if item[3] != 0:
199 item[2] -= 1
200 item[0] -= 1
201 exist = True
202 if item_name == "health" and item[0] == 0:
203 exist = False
204 elif add:
205 if item_name == "sniper":
206 item[0] += item[3]
207 else:
208 item[0] += 1
209 exist = True
210
211 MY_SingleConfigConnector().setPowerUps(item[1], item[0])
212
213 return exist
214
216 """
217 adds a merchandise item to the config parser
218
219 @type merch_name: String
220 @param merch_name: the name of the merhcandise item that was collected
221 """
222
223 MY_SingleConfigConnector().setMerch(merch_name)
224