protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { if (keyData == Keys.Down) { if (pi.MoverAbajo(tab)) { pi = new Pieza(NuevaPieza(), new Point(100, 0), /*NuevaOrientacion()*/ OrientacionPieza.Arriba); tab.VerificarLineas(); if (tab.Perder()) { MessageBox.Show("Haz Perdido!!\nPuntos: " + lbPuntos.Text); tab = new Tablero(); } lbPuntos.Text = tab.ObtenerPuntos().ToString(); } Refrescar(); } if (keyData == Keys.Right) { pi.MoverDerecha(tab); Refrescar(); } if (keyData == Keys.Left) { pi.MoverIzquierda(tab); Refrescar(); } if (keyData == Keys.Up) { pi.Rotar(tab); Refrescar(); } return(base.ProcessCmdKey(ref msg, keyData)); }
public void EnviarRecibir() { if (Servidor) { try { IPAddress ipAd = IPAddress.Any; TcpListener myList = new TcpListener(ipAd, 8001); myList.Start(); TcpClient client = myList.AcceptTcpClient(); NetworkStream strm = client.GetStream(); IFormatter formatter = new BinaryFormatter(); Pieza p = (Pieza)formatter.Deserialize(strm); Tablero t = (Tablero)formatter.Deserialize(strm); IFormatter formatter1 = new BinaryFormatter(); NetworkStream cosa = client.GetStream(); formatter.Serialize(cosa, pi); NetworkStream cosa1 = client.GetStream(); formatter.Serialize(cosa1, tab); foreach (Cuadro x in t.cuadritos) { x.Brocha = Brocha; x.Brocha1 = Brocha; x.Brocha2 = Brocha; x.Brocha3 = Brocha; x.Brocha4 = Brocha; x.Brocha5 = Brocha; x.Brocha6 = Brocha; } if (p.pieza.ToString() == "Cubo") { foreach (Cuadro c in p.PiezaO) { c.Brocha = Brocha; c.Brocha1 = Brocha; c.Brocha2 = Brocha; c.Brocha3 = Brocha; c.Brocha4 = Brocha; c.Brocha5 = Brocha; c.Brocha6 = Brocha; } } if (p.pieza.ToString() == "I") { foreach (Cuadro c in p.PiezaO) { c.Brocha = Brocha3; c.Brocha1 = Brocha3; c.Brocha2 = Brocha3; c.Brocha3 = Brocha3; c.Brocha4 = Brocha3; c.Brocha5 = Brocha3; c.Brocha6 = Brocha3; } } if (p.pieza.ToString() == "Jota") { foreach (Cuadro c in p.PiezaO) { c.Brocha = Brocha2; c.Brocha1 = Brocha2; c.Brocha2 = Brocha2; c.Brocha3 = Brocha2; c.Brocha4 = Brocha2; c.Brocha5 = Brocha2; c.Brocha6 = Brocha2; } } if (p.pieza.ToString() == "Te") { foreach (Cuadro c in p.PiezaO) { c.Brocha = Brocha6; c.Brocha1 = Brocha6; c.Brocha2 = Brocha6; c.Brocha3 = Brocha6; c.Brocha4 = Brocha6; c.Brocha5 = Brocha6; c.Brocha6 = Brocha6; } } if (p.pieza.ToString() == "ESE") { foreach (Cuadro c in p.PiezaO) { c.Brocha = Brocha4; c.Brocha1 = Brocha4; c.Brocha2 = Brocha4; c.Brocha3 = Brocha4; c.Brocha4 = Brocha4; c.Brocha5 = Brocha4; c.Brocha6 = Brocha4; } } if (p.pieza.ToString() == "ELE") { foreach (Cuadro c in p.PiezaO) { c.Brocha = Brocha1; c.Brocha1 = Brocha1; c.Brocha2 = Brocha1; c.Brocha3 = Brocha1; c.Brocha4 = Brocha1; c.Brocha5 = Brocha1; c.Brocha6 = Brocha1; } } if (p.pieza.ToString() == "Zeta") { foreach (Cuadro c in p.PiezaO) { c.Brocha = Brocha5; c.Brocha1 = Brocha5; c.Brocha2 = Brocha5; c.Brocha3 = Brocha5; c.Brocha4 = Brocha5; c.Brocha5 = Brocha5; c.Brocha6 = Brocha5; } } tab2 = t; label4.Text = tab2.ObtenerPuntos().ToString(); RefrescarS(p); if (tab2.Perder()) { MessageBox.Show("Has Ganado!!!\nPuntosJ1: " + tab.ObtenerPuntos() + "\nPuntosJ2: " + tab2.ObtenerPuntos()); Application.Exit(); } //cosa.Close(); //cosa1.Close(); myList.Stop(); } catch (Exception e) { MessageBox.Show(e.Message); } } else { try { TcpClient tcpclnt = new TcpClient(); tcpclnt.Connect(IP, 8001); IFormatter formatter = new BinaryFormatter(); NetworkStream cosa = tcpclnt.GetStream(); formatter.Serialize(cosa, pi); NetworkStream cosa1 = tcpclnt.GetStream(); formatter.Serialize(cosa1, tab); NetworkStream strm = tcpclnt.GetStream(); IFormatter formatter1 = new BinaryFormatter(); Pieza p = (Pieza)formatter1.Deserialize(strm); Tablero t = (Tablero)formatter1.Deserialize(strm); foreach (Cuadro x in t.cuadritos) { x.Brocha = Brocha; x.Brocha1 = Brocha; x.Brocha2 = Brocha; x.Brocha3 = Brocha; x.Brocha4 = Brocha; x.Brocha5 = Brocha; x.Brocha6 = Brocha; } if (p.pieza.ToString() == "Cubo") { foreach (Cuadro c in p.PiezaO) { c.Brocha = Brocha; c.Brocha1 = Brocha; c.Brocha2 = Brocha; c.Brocha3 = Brocha; c.Brocha4 = Brocha; c.Brocha5 = Brocha; c.Brocha6 = Brocha; } } if (p.pieza.ToString() == "I") { foreach (Cuadro c in p.PiezaO) { c.Brocha = Brocha3; c.Brocha1 = Brocha3; c.Brocha2 = Brocha3; c.Brocha3 = Brocha3; c.Brocha4 = Brocha3; c.Brocha5 = Brocha3; c.Brocha6 = Brocha3; } } if (p.pieza.ToString() == "Jota") { foreach (Cuadro c in p.PiezaO) { c.Brocha = Brocha2; c.Brocha1 = Brocha2; c.Brocha2 = Brocha2; c.Brocha3 = Brocha2; c.Brocha4 = Brocha2; c.Brocha5 = Brocha2; c.Brocha6 = Brocha2; } } if (p.pieza.ToString() == "Te") { foreach (Cuadro c in p.PiezaO) { c.Brocha = Brocha6; c.Brocha1 = Brocha6; c.Brocha2 = Brocha6; c.Brocha3 = Brocha6; c.Brocha4 = Brocha6; c.Brocha5 = Brocha6; c.Brocha6 = Brocha6; } } if (p.pieza.ToString() == "ESE") { foreach (Cuadro c in p.PiezaO) { c.Brocha = Brocha4; c.Brocha1 = Brocha4; c.Brocha2 = Brocha4; c.Brocha3 = Brocha4; c.Brocha4 = Brocha4; c.Brocha5 = Brocha4; c.Brocha6 = Brocha4; } } if (p.pieza.ToString() == "ELE") { foreach (Cuadro c in p.PiezaO) { c.Brocha = Brocha1; c.Brocha1 = Brocha1; c.Brocha2 = Brocha1; c.Brocha3 = Brocha1; c.Brocha4 = Brocha1; c.Brocha5 = Brocha1; c.Brocha6 = Brocha1; } } if (p.pieza.ToString() == "Zeta") { foreach (Cuadro c in p.PiezaO) { c.Brocha = Brocha5; c.Brocha1 = Brocha5; c.Brocha2 = Brocha5; c.Brocha3 = Brocha5; c.Brocha4 = Brocha5; c.Brocha5 = Brocha5; c.Brocha6 = Brocha5; } } tab2 = t; label4.Text = tab2.ObtenerPuntos().ToString(); RefrescarS(p); if (tab2.Perder()) { MessageBox.Show("Has Ganado!!!\nPuntosJ1: " + tab.ObtenerPuntos() + "\nPuntosJ2: " + tab2.ObtenerPuntos()); Application.Exit(); } //cosa.Close(); // cosa1.Close(); } catch (Exception e) { MessageBox.Show(e.Message); } } }