private void Conectar_Click(object sender, EventArgs e)
        {
            int idUsuario, idJugador;

            Servicios.Service1Client servicio = new Servicios.Service1Client();
            idUsuario = servicio.GetIdUsuario(TxtUsuario.Text);
            if (idUsuario == -1)
            {
                //personaje no existe
                MessageBox.Show("El usuario ingresado no existe, vuelva a intentarlo.", "Error de conexion", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                if (TxtContrasenia.Text.Equals(servicio.GetPassUsuarioId(idUsuario)))
                {
                    //contraseña correcta(Instanciar Jugador)
                    idJugador = servicio.GetIdJugadorId(idUsuario);
                    Controladores.ControladorMainProgram.controlador.instanciarJugador(idJugador, TxtUsuario.Text, servicio.GetNombreJugador(idJugador), servicio.GetVidaJugadorId(idJugador), servicio.GetPuntajeJugadorId(idJugador));

                    //========//
                    lblUsuarioEditar.Text      = Controladores.ControladorMainProgram.controlador.Jugador.NombreUsuario;
                    lblVidaEditar.Text         = Controladores.ControladorMainProgram.controlador.Jugador.Vida.ToString();
                    lblMejorPuntajeEditar.Text = Controladores.ControladorMainProgram.controlador.Jugador.Puntaje.ToString();

                    pnlConectado.BringToFront();

                    MessageBox.Show("Bienvenido " + TxtUsuario.Text + ", se ha logrado conectar a su cuenta, ¡ahora podra guardar sus logros y trofeos!.", "Conexion Exitosa!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    //Contraseñas incorrectas
                    MessageBox.Show("Contraseña no coincide con el usuario ingresado, vuelva a intentarlo.", "Error de conexion", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Exemplo n.º 2
0
 public void crearUsuario(String nombreUsuario, String contrasenia, String nombreJugador)
 {
     Servicios.Service1Client servicio = new Servicios.Service1Client();
     if (servicio.AddJugador(nombreJugador))
     {
         if (servicio.AddUsuario(servicio.GetIdJugadorNombre(nombreJugador), nombreUsuario, contrasenia))
         {
             controlador.Vista.CreacionJugadorMensaje(true);
         }
         else
         {
             servicio.EliminarJugadorNombre(nombreJugador);
             controlador.Vista.CreacionJugadorMensaje(false);
         }
     }
     else
     {
         controlador.Vista.CreacionJugadorMensaje(false);
     }
 }
        private void LaberintoVista_KeyDown(object sender, KeyEventArgs e)
        {
            if (!firstMove)
            {
                //si se ha comenzado a mover comienza el descuento de puntaje
                Thread thread = new Thread(restarPuntaje);
                thread.Name = "restarPuntajeThread";
                thread.Start();
                firstMove = true;
            }
            //actualizacion del puntaje
            actualizarPuntaje();
            Point punto;
            int   posXMatriz, posYMatriz;

            //posiciones anteriores del jugador
            posXMatriz = (Controladores.ControladorLaberinto.controlador.Jugador.Representacion.Location.X / Controladores.ControladorLaberinto.controlador.LargoCamino) - 3 / 8;
            posYMatriz = (Controladores.ControladorLaberinto.controlador.Jugador.Representacion.Location.Y / Controladores.ControladorLaberinto.controlador.AnchoCamino) - 3 / 8;
            //sender utiliza Para los movimientos
            //al llamar recursivamente se iran agregando infinitamente.
            if (!repitiendoMovimientos)
            {
                Controladores.ControladorLaberinto.controlador.Jugador.MovimientosEvents.Add(e);
            }
            if (e.KeyCode == Controladores.ControladorConfiguraciones.controlador.KeyArribaDef)
            {
                if (posYMatriz - 1 >= 0 && Controladores.ControladorLaberinto.controlador.MatrizPaneles.ElementAt(posYMatriz - 1).ElementAt(posXMatriz).BackColor != Color.Gray)
                {
                    punto = new Point(Controladores.ControladorLaberinto.controlador.Jugador.Representacion.Location.X,
                                      Controladores.ControladorLaberinto.controlador.Jugador.Representacion.Location.Y - (Controladores.ControladorLaberinto.controlador.ConstVel * Controladores.ControladorLaberinto.controlador.AnchoCamino));
                    Controladores.ControladorLaberinto.controlador.Jugador.Representacion.Location = punto;
                    if (!repitiendoMovimientos)
                    {
                        Controladores.ControladorLaberinto.controlador.Jugador.Movimientos.Add(punto);
                    }
                }
            }
            else if (e.KeyCode == Controladores.ControladorConfiguraciones.controlador.KeyAbajoDef)
            {
                if (posYMatriz + 1 < Controladores.ControladorLaberinto.controlador.DimY * 2 + 1 &&
                    Controladores.ControladorLaberinto.controlador.MatrizPaneles.ElementAt(posYMatriz + 1).ElementAt(posXMatriz).BackColor != Color.Gray)
                {
                    punto = new Point(Controladores.ControladorLaberinto.controlador.Jugador.Representacion.Location.X,
                                      Controladores.ControladorLaberinto.controlador.Jugador.Representacion.Location.Y + (Controladores.ControladorLaberinto.controlador.ConstVel *
                                                                                                                          Controladores.ControladorLaberinto.controlador.AnchoCamino));
                    Controladores.ControladorLaberinto.controlador.Jugador.Representacion.Location = punto;
                    if (!repitiendoMovimientos)
                    {
                        Controladores.ControladorLaberinto.controlador.Jugador.Movimientos.Add(punto);
                    }
                }
            }
            else if (e.KeyCode == Controladores.ControladorConfiguraciones.controlador.KeyDerDef)
            {
                if (posXMatriz + 1 < Controladores.ControladorLaberinto.controlador.DimX * 2 + 1 &&
                    Controladores.ControladorLaberinto.controlador.MatrizPaneles.ElementAt(posYMatriz).ElementAt(posXMatriz + 1).BackColor != Color.Gray)
                {
                    punto = new Point(Controladores.ControladorLaberinto.controlador.Jugador.Representacion.Location.X +
                                      (Controladores.ControladorLaberinto.controlador.ConstVel * Controladores.ControladorLaberinto.controlador.LargoCamino),
                                      Controladores.ControladorLaberinto.controlador.Jugador.Representacion.Location.Y);
                    Controladores.ControladorLaberinto.controlador.Jugador.Representacion.Location = punto;
                    if (!repitiendoMovimientos)
                    {
                        Controladores.ControladorLaberinto.controlador.Jugador.Movimientos.Add(punto);
                    }
                }
                else if (posYMatriz + 2 < Controladores.ControladorLaberinto.controlador.DimY * 2 + 1 &&
                         Controladores.ControladorLaberinto.controlador.MatrizPaneles.ElementAt(posYMatriz + 2).ElementAt(0).BackColor != Color.Gray)
                {
                    punto = new Point(3 * Controladores.ControladorLaberinto.controlador.LargoCamino / 8,
                                      Controladores.ControladorLaberinto.controlador.Jugador.Representacion.Location.Y +
                                      (Controladores.ControladorLaberinto.controlador.ConstVel * Controladores.ControladorLaberinto.controlador.AnchoCamino) * 2);
                    Controladores.ControladorLaberinto.controlador.Jugador.Representacion.Location = punto;
                    if (!repitiendoMovimientos)
                    {
                        Controladores.ControladorLaberinto.controlador.Jugador.Movimientos.Add(punto);
                    }
                }
            }
            else if (e.KeyCode == Controladores.ControladorConfiguraciones.controlador.KeyIzqDef)
            {
                if (posXMatriz - 1 >= 0 && Controladores.ControladorLaberinto.controlador.MatrizPaneles.ElementAt(posYMatriz).ElementAt(posXMatriz - 1).BackColor != Color.Gray)
                {
                    punto = new Point(Controladores.ControladorLaberinto.controlador.Jugador.Representacion.Location.X - (Controladores.ControladorLaberinto.controlador.ConstVel * Controladores.ControladorLaberinto.controlador.LargoCamino), Controladores.ControladorLaberinto.controlador.Jugador.Representacion.Location.Y);
                    Controladores.ControladorLaberinto.controlador.Jugador.Representacion.Location = punto;
                    if (!repitiendoMovimientos)
                    {
                        Controladores.ControladorLaberinto.controlador.Jugador.Movimientos.Add(punto);
                    }
                }
                else if (posYMatriz - 2 >= 0 &&
                         Controladores.ControladorLaberinto.controlador.MatrizPaneles.ElementAt(posYMatriz - 2).ElementAt(Controladores.ControladorNuevoJuego.controlador.DimX * 2).BackColor != Color.Gray)
                {
                    punto = new Point(Controladores.ControladorLaberinto.controlador.ConstVel * Controladores.ControladorLaberinto.controlador.LargoCamino *
                                      (Controladores.ControladorNuevoJuego.controlador.DimX * 2) + (3 * Controladores.ControladorLaberinto.controlador.LargoCamino / 8),
                                      Controladores.ControladorLaberinto.controlador.Jugador.Representacion.Location.Y - (Controladores.ControladorLaberinto.controlador.ConstVel *
                                                                                                                          Controladores.ControladorLaberinto.controlador.AnchoCamino) * 2);
                    Controladores.ControladorLaberinto.controlador.Jugador.Representacion.Location = punto;
                    if (!repitiendoMovimientos)
                    {
                        Controladores.ControladorLaberinto.controlador.Jugador.Movimientos.Add(punto);
                    }
                }
            }
            //posicion actual del jugador
            posXMatriz = (Controladores.ControladorLaberinto.controlador.Jugador.Representacion.Location.X / Controladores.ControladorLaberinto.controlador.LargoCamino) - 3 / 8;
            posYMatriz = (Controladores.ControladorLaberinto.controlador.Jugador.Representacion.Location.Y / Controladores.ControladorLaberinto.controlador.AnchoCamino) - 3 / 8;

            if (Controladores.ControladorLaberinto.controlador.MatrizPaneles.ElementAt(posYMatriz).ElementAt(posXMatriz).BackColor == Color.Orange &&
                Controladores.ControladorLaberinto.controlador.TrofeosRestantes == 0)
            {
                System.Windows.Forms.DialogResult resultado;
                //Has Ganado!!

                resultado = System.Windows.Forms.MessageBox.Show("Has ganado!\n¿Deseas ver la repeticion?", " ", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                if (!repitiendoMovimientos)
                {
                    if (Controladores.ControladorMainProgram.controlador.Jugador != null)
                    {
                        Servicios.Service1Client servicio = new Servicios.Service1Client();
                        Thread guardarPuntaje             = new Thread(() => servicio.UpdatePuntaje(Controladores.ControladorMainProgram.controlador.Jugador.Id,
                                                                                                    Controladores.ControladorLaberinto.controlador.Puntaje));
                        guardarPuntaje.Start();
                    }
                }

                if (resultado == DialogResult.Yes)
                {
                    hacerVisibleTrofeos(Controladores.ControladorNuevoJuego.controlador.RepresentacionLaberinto);
                    repetirMovimientos(Controladores.ControladorLaberinto.controlador.Jugador);
                }
                else if (resultado == DialogResult.No)
                {
                    this.btnRendirse_Click(null, null);
                }
            }
            else if (Controladores.ControladorLaberinto.controlador.MatrizPaneles.ElementAt(posYMatriz).ElementAt(posXMatriz).BackColor == Control.DefaultBackColor)
            {
                // verificacion si salió del laberinto, por el color, es decir si el color es control pierde
                System.Windows.Forms.MessageBox.Show("Has perdido!", " ", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.btnRendirse_Click(null, null);
            }
            if (Controladores.ControladorLaberinto.controlador.MatrizPaneles.ElementAt(posYMatriz).ElementAt(posXMatriz).BackColor == Color.Red)
            {
                //es trofeo y acabo de pasar por él
                Controladores.ControladorLaberinto.controlador.MatrizPaneles.ElementAt(posYMatriz).ElementAt(posXMatriz).BackColor = Color.Brown;
                Controladores.ControladorLaberinto.controlador.TrofeosRestantes--;
            }
        }