Esempio n. 1
0
        private void Empezar()
        {
            partidosJugados = UnJuegoMas();
            juego = new Juego();
            juego.GenerarNumeroAAdivinar();
            var ing = new IngresarNumero();
            //TODO!
            ing.ShowDialog();

            juego.NumeroAAdivinarPorLaCompu = ing.NumeroIngresado;
            MA.LimpiarTextBoxs(txtHistoriaCompu, txtHistoriaJugador);
            ProximoTurno();
            lblNumeroAAdivinarXLaCompu.Text = juego.NumeroAAdivinarPorLaCompu.ToString();
        }
Esempio n. 2
0
        // p pausa el juego y n crea una nueva partida, los movimientos se generan con las teclas de direccion
        private void Form1_Key(object sender, KeyEventArgs e)
        {
            if (e.KeyData == Keys.Up)
            {
                _direccion = 3;
            }

            if (e.KeyData == Keys.Right)
            {
                _direccion = 0;
            }

            if (e.KeyData == Keys.Down)
            {
                _direccion = 1;
            }


            if (e.KeyData == Keys.Left)
            {
                _direccion = 2;
            }

            if (e.KeyData == Keys.P)
            {
                if (timer1.Enabled == true)
                {
                    timer1.Enabled = false;
                }
                else
                {
                    timer1.Enabled = true;
                }
            }
            if (e.KeyData == Keys.N)
            {
                timer1.Stop();
                partida         = new Juego();
                timer1.Interval = partida.Velocidad;
                timer1.Start();
            }
        }
Esempio n. 3
0
        private void AtenderServidor()
        {//bucle de atencion a las peticiones del servidor
            while (true)
            {
                byte[] msg2 = new byte[200];
                server.Receive(msg2);
                string   mensaje = Encoding.ASCII.GetString(msg2).Split('\0')[0];
                string[] trozos  = mensaje.Split('/');
                int      codigo  = Convert.ToInt32(trozos[0]);



                switch (codigo)
                {
                case 1:    //log in
                    MessageBox.Show(trozos[1]);
                    string mensajerecivido = trozos[1];
                    string logincorrecto   = "Sesion iniciada correctamente";
                    if (string.Equals(mensajerecivido, logincorrecto))
                    {
                        DelegadoMostrarVentanas ventanas = new DelegadoMostrarVentanas(MostrarVentanas);
                        groupBox2.Invoke(ventanas, new object[] { });
                        Juego.Invoke(ventanas, new object[] { });
                        groupBox1.Invoke(ventanas, new object[] { });
                        Registro.Invoke(ventanas, new object[] { });
                    }
                    break;

                case 2:    //registro
                    MessageBox.Show(trozos[1]);
                    break;

                case 4:    //consulta
                    MessageBox.Show(trozos[1]);
                    break;

                case 5:    //consulta
                    MessageBox.Show(trozos[1]);
                    break;

                case 7:    //peticion para los invitados
                    string anfitrion = trozos[2];
                    partida = Convert.ToInt32(trozos[1]);
                    string       MessageBoxTitle   = "Invitación de chat";
                    string       MessageBoxContent = anfitrion + " te ha invitado a un chat cond id " + partida + "\n Deseas aceptarlo?";
                    string       respuesta_invitation;
                    DialogResult result = MessageBox.Show(MessageBoxContent, MessageBoxTitle, MessageBoxButtons.YesNo);
                    switch (result)
                    {
                    case DialogResult.Yes:

                        respuesta_invitation = "8/" + anfitrion + "/" + partida + "/" + usuario.Text + "/" + Convert.ToString(result) + "/1";
                        byte[] accept = System.Text.Encoding.ASCII.GetBytes(respuesta_invitation);
                        server.Send(accept);
                        ServicioChats(usuario_pc, partida);
                        break;

                    case DialogResult.No:
                        respuesta_invitation = "8/" + anfitrion + "/" + partida + "/" + usuario.Text + "/" + Convert.ToString(result) + "/0";
                        byte[] decline = System.Text.Encoding.ASCII.GetBytes(respuesta_invitation);
                        server.Send(decline);
                        break;
                    }

                    break;

                case 8:    //respuesta del anfitrion sobre las invitaciones
                    partida = Convert.ToInt32(trozos[1]);
                    string invitado      = trozos[2];
                    string respuesta_inv = trozos[3];
                    MessageBox.Show("Respuesta del invitado " + invitado + " al chat de id " + partida + " es " + respuesta_inv);
                    if (respuesta_inv == "Yes")
                    {
                        ServicioChats(usuario_pc, partida);
                    }
                    break;

                case 9:    //recebir mensaje del chat
                    int partida9 = Convert.ToInt32(trozos[1]);
                    autor        = trozos[2];
                    mensaje_chat = trozos[3];
                    EnviarChatForm(partida9, autor, mensaje_chat);
                    //DelegadoParaEnviarChatMain delegado9 = new DelegadoParaEnviarChatMain(EnviarChatForm);
                    //this.Invoke(delegado9, new object[] { partida9, autor, mensaje_chat });
                    break;

                case 999:    //notificaciones de conexion

                    int numcon999 = Convert.ToInt32(trozos[1]);
                    DelegadoListaConectados delegado999 = new DelegadoListaConectados(PonerEnGrid);
                    dataGridView1.Invoke(delegado999, new object[] { numcon999, trozos });
                    break;
                }
            }
        }