send( self.connection, self.player.getNick(), self.server ) def receiveData( self ): while True: data_receive = receive( self.connection, self.packet_size ) print data_receive if __name__ == "__main__": screen_size = ( game_configuration['screenW'], game_configuration['screenH'] ) screen = pydisplay.set_mode( screen_size ) pydisplay.set_caption( "Laser-Snake: " + game_configuration['version'] ) pyevent.set_allowed( None ) pyevent.set_allowed( [QUIT, KEYDOWN] ) nick_keys, port_keys = range( K_LEFTPAREN, K_z + 1 ) + range( K_KP0, K_KP_PLUS + 1 ) + [ K_KP_EQUALS ], range( K_0, K_9 + 1 ) + range( K_KP0, K_KP9 + 1 ) ip_keys = port_keys + [ K_PERIOD, K_KP_PERIOD ] nick_box = Box( screen, "Enter your nickname: ", (150, 100), nick_keys ) ip_box = Box( screen, "Enter server IP: ", (150, 100), ip_keys ) port_box = Box( screen, "Enter server port: ", (150, 100), port_keys ) name = nick_box.run() ip = ip_box.run() port = port_box.run() if len( ip ) == 0 or len( port ) == 0: ip, port = ip or game_configuration['ip'], port or game_configuration['port'] client = Client( name, ip, int(port) ) client.sendJoinRequest() choice_box = Box( screen, "Are you ready? (yes/no) ", (150, 100), nick_keys ) choice = choice_box.run() if 'yes' in choice.lower(): client.sendReadyRequest() client.receiveCountDown()
print '{} comamnd received from {}'.format( request['cmd'], address[0]) self.handler[request['cmd']](self, request, address) else: print request['cmd'] except socket.error: pass if __name__ == '__main__': screen = pydisplay.set_mode((1024, 576)) pydisplay.set_caption("Laser-Snake server: " + server_configuration['version']) pyevent.set_allowed(None) pyevent.set_allowed([QUIT, KEYDOWN]) port_keys = range(K_0, K_9 + 1) + range(K_KP0, K_KP9 + 1) ip_keys = port_keys + [K_PERIOD, K_KP_PERIOD] ip_box = Box(screen, "Please enter the server IP address: ", (10, 100), ip_keys) port_box = Box( screen, "Please enter the port to start server (leave blank for default): ", (10, 100), port_keys) ip = ip_box.run() port = port_box.run() if len(ip) == 0 or len(port) == 0: ip, port = ip or server_configuration['ip'], int( port or server_configuration['port']) serve = Server(ip, int(port)) serve.receive()
data_receive = receive(self.connection, self.packet_size) print data_receive if __name__ == "__main__": screen_size = (game_configuration['screenW'], game_configuration['screenH']) screen = pydisplay.set_mode(screen_size) pydisplay.set_caption("Laser-Snake: " + game_configuration['version']) pyevent.set_allowed(None) pyevent.set_allowed([QUIT, KEYDOWN]) nick_keys, port_keys = range(K_LEFTPAREN, K_z + 1) + range( K_KP0, K_KP_PLUS + 1) + [K_KP_EQUALS], range(K_0, K_9 + 1) + range( K_KP0, K_KP9 + 1) ip_keys = port_keys + [K_PERIOD, K_KP_PERIOD] nick_box = Box(screen, "Enter your nickname: ", (150, 100), nick_keys) ip_box = Box(screen, "Enter server IP: ", (150, 100), ip_keys) port_box = Box(screen, "Enter server port: ", (150, 100), port_keys) name = nick_box.run() ip = ip_box.run() port = port_box.run() if len(ip) == 0 or len(port) == 0: ip, port = ip or game_configuration['ip'], port or game_configuration[ 'port'] client = Client(name, ip, int(port)) client.sendJoinRequest() choice_box = Box(screen, "Are you ready? (yes/no) ", (150, 100), nick_keys) choice = choice_box.run() if 'yes' in choice.lower(): client.sendReadyRequest() client.receiveCountDown()