def executeaction(self,id): if not self._objects.has_key(id): err('bad key') return False x=self._objects[id].getCmd() if not x: return False if x[0]=='MOVE': self.moveobject(id,x[1],x[2]) try: self._objects[id].angle=x[3] except: self._objects[id].angle=0 return True if x[0]=='PLANTBOMB': return True if x[0]=='FIRE': return True if x[0]=='IDLE': return True msg("executeaction do not know how to handle:\n"+self._objects[id].action) return False
def handle_worldinfo(self,worldinfo): # msg("Client.worldinfo: "+String(worldinfo)) world=String(worldinfo).splitlines() if not world[0]=='CONTINUE': self.allsprites.empty() # self._hero.add(self.allsprites) player=Player() stone=Stone() bomb=Bomb() # err(str(world)) for i in world: if i=='CONTINUE': continue if player.isPlayer(i): player.fromString(i) obj=DD(player.x,player.y) elif stone.isStone(i): stone.fromString(i) if stone.x>200 or stone.y>200: err("BAD stone: "+stone.toString()) obj=Block(stone.x,stone.y,stone.imageId) elif bomb.isBomb(i): bomb.fromString(i) #Change this obj! obj=DD(bomb.x,bomb.y) else: msg("handle_worldinfo got some crap:\n"+i) continue obj.add(self.allsprites)
def fromString(self,string): s=string.split(' ') if not s[0] == self.type: msg("bomb.fromString got something that was not a bomb:\n"+string) self.id = int(s[1]) self.x = int(s[2]) self.y = int(s[3]) self.timeleft = int(s[4]) self.imageId = int(s[5])
def fromString(self, string): s = string.split(" ") if not s[0] == self.type: msg("stone.fromString got something that was not a stone:\n" + string) self.id = int(s[1]) self.x = int(s[2]) self.y = int(s[3]) self.health = int(s[4]) self.imageId = int(s[5])
def fromString(self,string): if not self.isBomb(string): msg("bomb.fromString got something that was not a bomb:\n"+string) s=string.split(' ') self.type='BOMB' self.id = int(s[1]) self.x = int(s[2]) self.y = int(s[3]) self.timeleft = int(s[4]) self.image = int(s[5])
def fromString(self,string): try: if not self.isPlayer(string): return False d=string.split(' ') self.type=d[0] self.id =int(d[1]) self.x =int(d[2]) self.y =int(d[3]) self.angle=int(d[4]) self.health =int(d[5]) self.imageId =int(d[6]) self.height =20 self.width = 20 except: msg("player:fromString got bad values: \n-|"+string+'|-')
def handle_worldinfo(self,worldinfo): # msg("Client.worldinfo: "+String(worldinfo)) world=String(worldinfo).splitlines() player=Player() stone=Stone() bomb=Bomb() err("Number of rows received: "+str(len(world))) for i in world: if i=='CONTINUE': continue if str(i.split(' ')[0])=='MVWORLD': s=i.split(' ') dx=int(s[1]) dy=int(s[2]) for i in self._objects.keys(): self._objects[i].x+=dx self._objects[i].y+=dy if not (0 < self._objects[i].x <400 or 0 < self._objects[i].y <400): self._objects.pop(i) elif player.isPlayer(i): p=Player() p.fromString(i) self._objects[p.id]=p elif stone.isStone(i): s=Stone() s.fromString(i) # err("got stone: "+stone.toString()) # err("from : "+ str(i)) self._objects[s.id]=s elif bomb.isBomb(i): b=Bomb() b.fromString(i) self._objects[b.id]=b else: msg("handle_worldinfo got some crap:\n"+i+str(i.split(' '))) continue self.pyprint()