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 handle(self,port,message): #msg(str(message)) if Atom(message[0]) == "init": self._outPort = port elif Atom(message[0]) =="connect": self.connect(message[1]) elif Atom(message[0])=="data": #msg(str(message)) #err('handle: '+str(message[2])+'\n'+str(message[1])+'\n'+str(message[0])+'\n'+str(message)) self.setaction(int(message[1]),message[2]) else: err("Server:handle() got something it did not understand: "+str(message))
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()
def send(self,id,info): if self._outPort: x=info.splitlines() if(len(x)>7): part="" for i in xrange(0,7): part+=x[i]+'\n' err(str(part)) self._outPort.write([id,part]) part="CONTINUE\n" for i in xrange(7,len(x)): part+=x[+i]+'\n' time.sleep(0.025) self.send(id,part) return True # err('Send id: '+str(id)) # err('Message Length: '+str(len(str(info)))) # if(len(str(info)) >255): # err("to much data "+str(len(str(info)))) # return False self._outPort.write([id,info]) return True
def setaction(self,id,action): err("Setting new action: "+str(id)+' '+str(action)) if not self._objects.has_key(id): return False self._objects[id].setCmd(action)
background.fill((255, 255, 255)) screen.blit(background, (0, 0)) pygame.display.flip() proto.init(1000,1000) if(proto.showView): proto.updateSprites() proto.startListener() x=0 #msg("starting loop") clock = pygame.time.Clock() while(proto.running == True): clock.tick(15) t=time.time() t+=0.02-time.time() if x>5: proto.tic(True) if(proto.showView): proto.updateSprites() proto.draw() #msg("draw success") x=0 else: proto.tic(False) x+=1 if t>0: time.sleep(t) else: pass err('Server overload, add more servers!')