def new_event(self, event): if self.__estado in self.__estados_activos: if event.type == olpcgames.CONNECT: self.__tube_id = event.id self.__audio.play_voice_sound("club", "conexion exitosa") log.debug("Participantes: " + str(mesh.get_participants())) self.__set_up() elif event.type == olpcgames.PARTICIPANT_ADD: # create a new participant display value... current = self._buddies.get(event.handle) if not current: if current is False: self.remove_buddy(current) else: def on_buddy(buddy, event=event): """Process update from the network telling us about a buddy Note: this function runs in the wrapper's thread, *not* the Pygame thread!""" log.info('''Newly joined buddy: %s (%s)''', buddy.props.nick, event.handle) self.add_buddy(event.handle, buddy) mesh.lookup_buddy(event.handle, on_buddy) elif event.type == olpcgames.PARTICIPANT_REMOVE: if not self.remove_buddy(event.handle): # race condition, need to block new/upcoming elements... self._buddies[event.handle] = False elif event.type == olpcgames.MESSAGE_UNI: self.__handle_message(event.handle, event.content) return False else: if event.type == olpcgames.MESSAGE_UNI and event.content == "HAY_ALGUIEN?": mesh.send_to(event.handle, "HAY_ALGUIEN?NO_ESTOY") return False
def new_event(self, event): if self.__estado in self.__estados_activos: if event.type == olpcgames.CONNECT: self.__tube_id = event.id self.__audio.play_voice_sound("club","conexion exitosa") log.debug("Participantes: " + str(mesh.get_participants())) self.__set_up() elif event.type == olpcgames.PARTICIPANT_ADD: # create a new participant display value... current = self._buddies.get( event.handle ) if not current: if current is False: self.remove_buddy( current ) else: def on_buddy( buddy, event=event ): """Process update from the network telling us about a buddy Note: this function runs in the wrapper's thread, *not* the Pygame thread!""" log.info( '''Newly joined buddy: %s (%s)''', buddy.props.nick, event.handle ) self.add_buddy( event.handle, buddy ) mesh.lookup_buddy( event.handle, on_buddy ) elif event.type == olpcgames.PARTICIPANT_REMOVE: if not self.remove_buddy( event.handle ): # race condition, need to block new/upcoming elements... self._buddies[ event.handle ] = False elif event.type == olpcgames.MESSAGE_UNI: self.__handle_message(event.handle, event.content) return False else: if event.type == olpcgames.MESSAGE_UNI and event.content == "HAY_ALGUIEN?": mesh.send_to(event.handle,"HAY_ALGUIEN?NO_ESTOY") return False
def send_game_message(self): self.__can_contrarios = 0 self.__contrarios = [] for participante in mesh.get_participants(): if mesh.my_handle() != participante: self.__contrarios.append(participante) mesh.send_to(participante, "JUEGO?") self.__can_contrarios = len(self.__contrarios) self.__conf_men_juego = 0
def __set_up(self): envio_mensaje = False self.__can_contrarios = 0 self.__conf_men_juego = 0 for participante in mesh.get_participants(): if mesh.my_handle() != participante: envio_mensaje = True mesh.send_to(participante, "HAY_ALGUIEN?") self.__can_contrarios += 1 if not envio_mensaje: self.__audio.play_voice_sound("club", "esperando oponente") self.__estado = ESPERANDO_OPONENTE
def __set_up(self): envio_mensaje = False self.__can_contrarios = 0 self.__conf_men_juego = 0 for participante in mesh.get_participants(): if mesh.my_handle() != participante: envio_mensaje = True mesh.send_to(participante, "HAY_ALGUIEN?") self.__can_contrarios += 1 if not envio_mensaje: self.__audio.play_voice_sound("club","esperando oponente") self.__estado = ESPERANDO_OPONENTE
def __send_waiting_message(self): for participante in mesh.get_participants(): if mesh.my_handle() != participante: mesh.send_to(participante, "ESPERANDO_JUEGO_NUEVO")