Exemple #1
0
        private void PedirNombre()
        {
            FormNuevoRecord formNuevoRecord = new FormNuevoRecord();

            if (formNuevoRecord.ShowDialog() == DialogResult.OK)
            {
                if (formNuevoRecord.textBox1.Text.Trim() != "")
                {
                    if (iniciarConexion())
                    {
                        IPHostEntry host    = Dns.GetHostEntry(Dns.GetHostName());
                        string      ipLocal = null;
                        foreach (var ip in host.AddressList)
                        {
                            if (ip.AddressFamily == AddressFamily.InterNetwork)
                            {
                                ipLocal = ip.ToString();
                                break;
                            }
                        }
                        MemoryStream memoryStream = new MemoryStream();
                        formatter.Serialize(memoryStream, new Record(formNuevoRecord.textBox1.Text, segundos, ipLocal));
                        peticionYcierre($"sendrecord {Transformaciones.ByteArrayToString(memoryStream.ToArray())}");
                    }
                    else
                    {
                        MessageBox.Show("Has cancelado el envio del record", "Record cancelado", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else
                {
                    MessageBox.Show("No puedes enviar un nombre en blanco", "Record cancelado", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Exemple #2
0
 private void Getrecords_Click(object sender, EventArgs e)
 {
     if (iniciarConexion())
     {
         String       recordhex    = peticionYcierre("getrecords");
         MemoryStream memoryStream = new MemoryStream(Transformaciones.StringToByteArray(recordhex));
         Record []    records      = (Record[])formatter.Deserialize(memoryStream);
         memoryStream.Close();
         new FormRecords(records).ShowDialog();
     }
 }
Exemple #3
0
        private void ComprobarLetra(object sender, EventArgs e)
        {
            bool acerto = false;

            if (textLetra.Text != "")
            {
                if (!comprobadas.Contains(textLetra.Text.ToLower()))
                {
                    comprobadas       = comprobadas + textLetra.Text.ToLower();
                    lcomprobados.Text = "";
                    foreach (Char letra in comprobadas)
                    {
                        lcomprobados.Text = lcomprobados.Text + letra + " ";
                    }
                }
                for (int i = 0; i < labels.Count; i++)
                {
                    if (textLetra.Text.ToLower() == (String)labels[i].Tag)
                    {
                        labels[i].Text = (String)labels[i].Tag;
                        acerto         = true;
                    }
                }
                if (!acerto)
                {
                    dibujoAhorcado1.Errores++;
                }
                else
                {
                    bool fin = true;
                    foreach (Label label in labels)
                    {
                        if (label.Text != (String)label.Tag)
                        {
                            fin = false;
                        }
                    }
                    if (fin)
                    {
                        System.Diagnostics.Debug.WriteLine("Termino");
                        timer1.Stop();
                        if (iniciarConexion())
                        {
                            String       recordhex    = peticionYcierre("getrecords");
                            MemoryStream memoryStream = new MemoryStream(Transformaciones.StringToByteArray(recordhex));
                            Record[]     records      = (Record[])formatter.Deserialize(memoryStream);
                            memoryStream.Close();
                            bool mejor = false;
                            foreach (Record record in records)
                            {
                                if (record != null)
                                {
                                    if (record.tiempo > segundos)
                                    {
                                        mejor = true;
                                        break;
                                    }
                                }
                                else
                                {
                                    mejor = true;
                                }
                            }
                            if (mejor)
                            {
                                PedirNombre();
                            }
                        }
                        else
                        {
                            MessageBox.Show("No se ha podido conetar al servidor para comprobar los recods", "Problema con el servidor", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        tJugar.Enabled     = true;
                        Jugar.Enabled      = true;
                        mJugar.Enabled     = true;
                        labelLetra.Enabled = false;
                        sendword.Enabled   = false;
                        textLetra.Enabled  = false;
                    }
                }
                textLetra.Text = "";
            }
        }