public void EscribirenListaPartidas(string mensajerecibido)
        {
            ListaPartidas.Rows.Clear();
            ListaPartidas.ColumnCount                                   = 1;
            ListaPartidas.ColumnHeadersVisible                          = true;
            ListaPartidas.DefaultCellStyle.BackColor                    = Color.FromArgb(0, 50, 137);
            ListaPartidas.DefaultCellStyle.SelectionBackColor           = Color.FromArgb(0, 50, 137);
            ListaPartidas.RowHeadersDefaultCellStyle.SelectionBackColor = Color.Olive;
            ListaPartidas.EnableHeadersVisualStyles                     = false;
            ListaPartidas.RowHeadersDefaultCellStyle.BackColor          = Color.FromArgb(0, 50, 137);
            ListaPartidas.ColumnHeadersDefaultCellStyle.BackColor       = Color.FromArgb(0, 50, 137);

            string[] trozos  = mensajerecibido.Split('/');
            string   mensaje = trozos[1].Split('\0')[0];
            string   mensaje2;
            int      nm = Convert.ToInt32(mensaje);

            if (nm != 0)
            {
                ListaPartidas.Rows.Clear();
                partidasBox.Text = mensaje;
                int i;
                for (i = 2; i < nm + 2; i++)
                {
                    mensaje2 = trozos[i].Split('\0')[0];
                    ListaPartidas.Rows.Add(mensaje2);
                    ListaPartidas.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
                }
                ListaPartidas.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
            }
            else
            {
                partidasBox.Text = "0";
            }
        }
        /// <summary>
        /// Selecciona las 5 (como máximo) partidas victoriosas con la menor duracion.
        /// </summary>
        /// <returns>Devuelve una List<> de Partidas.</returns>
        public static List <Partida> filtrarParaElTop5()
        {
            List <Partida> ret  = new List <Partida>();
            int            cont = 5;
            int            i    = 0;

            while ((cont != 0) && (i < ListaPartidas.Count()))
            {
                if (ListaPartidas[i].resultado == true)
                {
                    ret.Add(ListaPartidas[i]);
                    cont--;
                }
                i++;
            }
            return(ret);
        }
示例#3
0
 public void PonTabla2(string id)
 {
     ListaPartidas.Rows.Add(id);
     ListaPartidas.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
 }
示例#4
0
        private void AtenderServidor()
        {
            while (true)
            {
                //Recibimos la respuesta del servidor
                byte[] msg2 = new byte[80];
                server.Receive(msg2);
                string       mensajerecibido = Encoding.ASCII.GetString(msg2);
                string[]     trozos          = Encoding.ASCII.GetString(msg2).Split('/');
                int          codigo          = Convert.ToInt32(trozos[0]);
                string       mensaje         = trozos[1].Split('\0')[0];
                string       mensaje2;
                DialogResult result;
                switch (codigo)

                {
                case 1:
                    if (mensaje == "SI")
                    {
                        MessageBox.Show("El usuario: " + Username.Text + ", se ha registrado correctamente.");
                    }
                    else
                    {
                        MessageBox.Show("El usuario: " + Username.Text + ", ya está cogido.");
                    }
                    break;


                case 2:
                    mensaje2 = trozos[2].Split('\0')[0];

                    if (mensaje == "SI")
                    {
                        if (mensaje2 == "El usuario: " + Username.Text + ", se ha anadido correctamente a la lista")
                        {
                            MessageBox.Show(mensaje2);
                            registered = true;
                            //DelegadoParaAbrirMain delegado1 = new DelegadoParaAbrirMain (AbrirMain);
                            //this.invoke(delegado1, new object [] {Username.Text});
                        }
                        else
                        {
                            MessageBox.Show(mensaje2);
                            registered = false;
                        }
                    }
                    else
                    {
                        MessageBox.Show(mensaje2);
                    }
                    break;

                case 3:
                    MessageBox.Show(mensaje);
                    break;

                case 4:
                    MessageBox.Show(mensaje);
                    break;

                case 5:
                    MessageBox.Show(mensaje);
                    break;

                case 6:
                    //Recibimos notificación
                    int nm = Convert.ToInt32(mensaje);
                    if (nm != 0)
                    {
                        ListaConectados.Rows.Clear();
                        NumConn.Text = mensaje;
                        int i;
                        for (i = 2; i < nm + 2; i++)
                        {
                            mensaje2 = trozos[i].Split('\0')[0];
                            DelegadoParaEscribir delegado = new DelegadoParaEscribir(PonTabla);
                            ListaConectados.Invoke(delegado, new object [] { mensaje2 });
                        }
                        ListaConectados.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
                    }
                    else
                    {
                        NumConn.Text = "0";
                    }
                    break;

                case 7:
                    int id = Convert.ToInt32(mensaje);
                    mensaje2 = trozos[2].Split('\0')[0];
                    if (id != -1)
                    {
                        result = (MessageBox.Show("Hola, " + Username.Text + ": " + mensaje2 + " te ha invitado a jugar a la partida " + id + ", ¿aceptas?", "aceptar", MessageBoxButtons.YesNo));
                        switch (result)
                        {
                        case DialogResult.Yes:
                            string envio = "8/" + mensaje + "/SI";
                            // Enviamos al servidor el username y password tecleadas.
                            byte[] msg = System.Text.Encoding.ASCII.GetBytes(envio);
                            server.Send(msg);
                            break;

                        case DialogResult.No:
                            envio = "8/" + mensaje + "/NO";
                            // Enviamos al servidor el username y password tecleadas.
                            msg = System.Text.Encoding.ASCII.GetBytes(envio);
                            server.Send(msg);
                            break;
                        }
                    }
                    else
                    {
                        MessageBox.Show(mensaje2);
                    }
                    break;

                case 8:
                    id       = Convert.ToInt32(mensaje);
                    ID       = id;
                    mensaje2 = trozos[2].Split('\0')[0];
                    string mensaje3 = trozos[3].Split('\0')[0];
                    if (mensaje3 == "SI")
                    {
                        MessageBox.Show(mensaje2 + " ha aceptado a jugar la partida " + id);
                        cont   = cont + 1;
                        juegan = juegan + 1;
                    }
                    else
                    {
                        MessageBox.Show(mensaje3);
                        cont = cont + 1;
                    }



                    if (cont == contador)
                    {
                        invited  = true;
                        contador = 0;
                        cont     = 0;
                    }
                    break;

                case 9:
                    autor    = mensaje;
                    mensaje2 = trozos[2].Split('\0')[0];
                    RecibirChat(autor, mensaje2);
                    break;

                case 10:
                    //Recibimos notificación
                    int n = Convert.ToInt32(mensaje);      //recibimos el numero de partidas disponibles

                    if (n != 0)
                    {
                        ListaPartidas.Rows.Clear();
                        partidasBox.Text = mensaje;
                        int i;
                        for (i = 2; i < n + 2; i++)
                        {
                            mensaje2 = trozos[i].Split('\0')[0];
                            DelegadoParaEscribir delegado = new DelegadoParaEscribir(PonTabla2);
                            ListaPartidas.Invoke(delegado, new object[] { mensaje2 });
                        }
                        ListaPartidas.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
                    }
                    else
                    {
                        partidasBox.Text = "0";
                    }
                    break;
                }
            }
        }