comparison demos/rpg/scripts/gamecontroller.py @ 535:9fbe3dce925a

Added custom exceptions.
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Mon, 31 May 2010 18:44:48 +0000
parents 65a92a2449d5
children 1afe46247ab1
comparison
equal deleted inserted replaced
534:65a92a2449d5 535:9fbe3dce925a
33 33
34 from scripts.scene import Scene 34 from scripts.scene import Scene
35 from scripts.guicontroller import GUIController 35 from scripts.guicontroller import GUIController
36 from scripts.actors.baseactor import TalkAction, PickUpItemAction 36 from scripts.actors.baseactor import TalkAction, PickUpItemAction
37 from scripts.objects.baseobject import GameObjectTypes 37 from scripts.objects.baseobject import GameObjectTypes
38 from scripts.misc.exceptions import ObjectNotFoundError
38 39
39 40
40 class KeyState(object): 41 class KeyState(object):
41 def __init__(self): 42 def __init__(self):
42 self._keystate = { } 43 self._keystate = { }
208 cmd.append(arg) 209 cmd.append(arg)
209 210
210 if cmd[0] == "spawn": 211 if cmd[0] == "spawn":
211 result = "Usage: spawn [item|actor] [id] [posx] [posy]" 212 result = "Usage: spawn [item|actor] [id] [posx] [posy]"
212 if len(cmd) != 5: 213 if len(cmd) != 5:
213 print len(cmd)
214 return result 214 return result
215 else: 215 else:
216 if cmd[1] == "item": 216 try:
217 obj = self._scene.loadItem(cmd[2]) 217 if cmd[1] == "item":
218 elif cmd[1] == "actor": 218 obj = self._scene.loadItem(cmd[2])
219 obj = self._scene.loadActor(cmd[2]) 219 elif cmd[1] == "actor":
220 else: 220 obj = self._scene.loadActor(cmd[2])
221 return result 221 else:
222 return result
223 except ObjectNotFoundError, e:
224 result = "Error while loading object: " + cmd[2]
225 obj = None
226
222 if obj: 227 if obj:
223 self._scene.addObjectToScene(obj) 228 self._scene.addObjectToScene(obj)
224 result = "--OK--" 229 result = "--OK--"
225 else:
226 result = "Error: Not Found!"
227 230
228 return result 231 return result
229 232
230 def newGame(self): 233 def newGame(self):
231 self._guicontroller.hideMainMenu() 234 self._guicontroller.hideMainMenu()