private void LoSocket_msgReceived(object sender, EventArgs e) { try { //Obtenems la pelota del vecino ClSockets temp = (ClSockets)sender; datosPelota = temp.data; Ball pelota = JsonConvert.DeserializeObject <Ball>(datosPelota); BeginInvoke((Action) delegate { pelota.positionX = ConvertRange(0, pelota.resolutionX, 0, Screen.PrimaryScreen.Bounds.Width, pelota.positionX); pelota.positionY = ConvertRange(0, pelota.resolutionY, 0, Screen.PrimaryScreen.Bounds.Height, pelota.positionY); pelota.movementX = -pelota.movementX; if (pelota.movementX < 0) { pelota.positionX = pelota.positionX - pelota.diameter; } pelota.diameter = ConvertRange(0, pelota.resolutionX, 0, Screen.PrimaryScreen.Bounds.Width, pelota.diameter); ClBall pelotaui = new ClBall(Color.FromArgb(pelota.color), pelota.creator, pelota.movementX, pelota.movementY, pelota.diameter, this, 30, loPaddle, pelota.positionX, pelota.positionY, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, pelota.life); pelotaui.wallhit += LoBall_wallhit; }); } catch { } }
private void FrmMain_Load(object sender, EventArgs e) { Cursor.Hide(); loPaddle = new ClPaddle(this, Color.DarkBlue, 100, 15); ipLocal = GetLocalIPAddress().ToString(); /////////////////////////////////////////// ////Abrir clSocket y conectar listener loSocket = new ClSockets(ipLocal); //Conectamos con los clientes loSocket.connectSocketLeft(ipLeft); loSocket.connectSocketRight(ipRight); //Configuramos las funciones que escucharan los listeners loSocket.msgReceived += LoSocket_msgReceived; /////////////////////////////////////////// }