Beispiel #1
0
        private void Window_KeyDown(object sender, KeyEventArgs e)
        {
            if (!termino)
            {
                //Identificar que boton se dio click para decidir que hacer
                //Hacer un movimiento hacia abajo.
                if (e.Key == Key.Down)
                {
                    turno++;

                    if (esteMero != null)
                    {
                        //Hacer un casting a la pieza origen para hacer el
                        //correcto metodo moverAbajo()
                        if (esteMero.GetType() == typeof(FichaLinea))
                        {
                            FichaLinea casting = (FichaLinea)esteMero;
                            casting.moverAbajo();
                        }
                        else if (esteMero.GetType() == typeof(FichaTanque))
                        {
                            FichaTanque casting = (FichaTanque)esteMero;
                            casting.moverAbajo();
                        }
                        else if (esteMero.GetType() == typeof(FichaLetraL))
                        {
                            FichaLetraL casting = (FichaLetraL)esteMero;
                            casting.moverAbajo();
                        }
                        else if (esteMero.GetType() == typeof(FichaSerpiente))
                        {
                            FichaSerpiente casting = (FichaSerpiente)esteMero;
                            casting.moverAbajo();
                        }
                        else if (esteMero.GetType() == typeof(FichaSerpienteInvertida))
                        {
                            FichaSerpienteInvertida casting = (FichaSerpienteInvertida)esteMero;
                            casting.moverAbajo();
                        }
                        else if (esteMero.GetType() == typeof(FichaCuadrado))
                        {
                            FichaCuadrado casting = (FichaCuadrado)esteMero;
                            casting.moverAbajo();
                        }


                        if (!esteMero.moverse)
                        {
                            verificarLineas();


                            ///////

                            bool finish = false;

                            for (int j = 0; j < 10; j++)
                            {
                                if (conteo[0, j] == 1)
                                {
                                    finish = true;
                                }
                            }

                            if (finish)
                            {
                                terminarPartida();
                            }
                            else
                            {
                                crearFicha2();
                            }
                        }

                        contador = 0;
                        seMovio  = true;
                    }
                }
                else if (e.Key == Key.Right)
                {
                    if (esteMero != null)
                    {
                        if (esteMero.GetType() == typeof(FichaLinea))
                        {
                            FichaLinea casting = (FichaLinea)esteMero;
                            casting.moverDerecha();
                        }
                        else if (esteMero.GetType() == typeof(FichaTanque))
                        {
                            FichaTanque casting = (FichaTanque)esteMero;
                            casting.moverDerecha();
                        }
                        else if (esteMero.GetType() == typeof(FichaLetraL))
                        {
                            FichaLetraL casting = (FichaLetraL)esteMero;
                            casting.moverDerecha();
                        }
                        else if (esteMero.GetType() == typeof(FichaSerpiente))
                        {
                            FichaSerpiente casting = (FichaSerpiente)esteMero;
                            casting.moverDerecha();
                        }
                        else if (esteMero.GetType() == typeof(FichaSerpienteInvertida))
                        {
                            FichaSerpienteInvertida casting = (FichaSerpienteInvertida)esteMero;
                            casting.moverDerecha();
                        }
                        else if (esteMero.GetType() == typeof(FichaCuadrado))
                        {
                            FichaCuadrado casting = (FichaCuadrado)esteMero;
                            casting.moverDerecha();
                        }
                    }
                }
                else if (e.Key == Key.Left)
                {
                    if (esteMero != null)
                    {
                        //esteMero.moverIzquierda();

                        if (esteMero.GetType() == typeof(FichaLinea))
                        {
                            FichaLinea casting = (FichaLinea)esteMero;
                            casting.moverIzquierda();
                        }
                        else if (esteMero.GetType() == typeof(FichaTanque))
                        {
                            FichaTanque casting = (FichaTanque)esteMero;
                            casting.moverIzquierda();
                        }
                        else if (esteMero.GetType() == typeof(FichaLetraL))
                        {
                            FichaLetraL casting = (FichaLetraL)esteMero;
                            casting.moverIzquierda();
                        }
                        else if (esteMero.GetType() == typeof(FichaSerpiente))
                        {
                            FichaSerpiente casting = (FichaSerpiente)esteMero;
                            casting.moverIzquierda();
                        }
                        else if (esteMero.GetType() == typeof(FichaSerpienteInvertida))
                        {
                            FichaSerpienteInvertida casting = (FichaSerpienteInvertida)esteMero;
                            casting.moverIzquierda();
                        }
                        else if (esteMero.GetType() == typeof(FichaCuadrado))
                        {
                            FichaCuadrado casting = (FichaCuadrado)esteMero;
                            casting.moverIzquierda();
                        }
                    }
                }
                else if (e.Key == Key.Up)
                {
                    if (esteMero != null)
                    {
                        if (esteMero.GetType() == typeof(FichaLinea))
                        {
                            FichaLinea casting = (FichaLinea)esteMero;
                            casting.girar();
                        }
                        else if (esteMero.GetType() == typeof(FichaTanque))
                        {
                            FichaTanque casting = (FichaTanque)esteMero;
                            casting.girar();
                        }
                        else if (esteMero.GetType() == typeof(FichaLetraL))
                        {
                            FichaLetraL casting = (FichaLetraL)esteMero;
                            casting.girar();
                        }
                        else if (esteMero.GetType() == typeof(FichaSerpiente))
                        {
                            FichaSerpiente casting = (FichaSerpiente)esteMero;
                            casting.girar();
                        }
                        else if (esteMero.GetType() == typeof(FichaSerpienteInvertida))
                        {
                            FichaSerpienteInvertida casting = (FichaSerpienteInvertida)esteMero;
                            casting.girar();
                        }
                    }
                }
                else if (e.Key == Key.Space)
                {
                    if (esteMero != null)
                    {
                        while (esteMero.moverse)
                        {
                            if (esteMero.GetType() == typeof(FichaLinea))
                            {
                                FichaLinea casting = (FichaLinea)esteMero;
                                casting.moverAbajo();
                            }
                            else if (esteMero.GetType() == typeof(FichaTanque))
                            {
                                FichaTanque casting = (FichaTanque)esteMero;
                                casting.moverAbajo();
                            }
                            else if (esteMero.GetType() == typeof(FichaLetraL))
                            {
                                FichaLetraL casting = (FichaLetraL)esteMero;
                                casting.moverAbajo();
                            }
                            else if (esteMero.GetType() == typeof(FichaSerpiente))
                            {
                                FichaSerpiente casting = (FichaSerpiente)esteMero;
                                casting.moverAbajo();
                            }
                            else if (esteMero.GetType() == typeof(FichaSerpienteInvertida))
                            {
                                FichaSerpienteInvertida casting = (FichaSerpienteInvertida)esteMero;
                                casting.moverAbajo();
                            }
                            else if (esteMero.GetType() == typeof(FichaCuadrado))
                            {
                                FichaCuadrado casting = (FichaCuadrado)esteMero;
                                casting.moverAbajo();
                            }
                        }



                        verificarLineas();
                        /////

                        //crearFicha();
                        bool finish = false;

                        for (int j = 0; j < 10; j++)
                        {
                            if (conteo[0, j] == 1)
                            {
                                finish = true;
                            }
                        }

                        if (finish)
                        {
                            terminarPartida();
                        }
                        else
                        {
                            //crearFicha();
                            crearFicha2();
                        }
                    }
                }
                else if (e.Key == Key.C)
                {
                    //Verificar cuales casillas estan reconocidas como ocupadas
                    // Y cuales no -- "Testeto"
                    string array = "";
                    for (int i = 0; i < 20; i++)
                    {
                        for (int j = 0; j < 10; j++)
                        {
                            array += conteo[i, j] + " ";
                        }
                        array += "\n";
                    }
                    MessageBox.Show(array);

                    ////
                }
            }
        }