public void Ejecutar()
    {
        //PruebaPacMan pruebaPacMan = new PruebaPacMan();
        bool salir = false;
        //Nivel nivel = new Nivel();
        Pac p = new Pac(13, 10);

        nivel.Mostrar();
        p.Mostrar();
        p.Mover();

        do
        {
            p.Mostrar();
            nivel.MostrarPuntuacion();

            for (int i = 0; i < fantasmas.Length; i++)
            {
                fantasmas[i].Mostrar();
            }

            ConsoleKeyInfo tecla = Console.ReadKey();
            p.Borrar();

            switch (tecla.Key)
            {
            case ConsoleKey.Escape:
                salir = true;
                break;

            case ConsoleKey.LeftArrow:
                if (nivel.EsPosibleMover(p.X - 1, p.Y))
                {
                    p.X--;
                }
                break;

            case ConsoleKey.RightArrow:
                if (nivel.EsPosibleMover(p.X + 1, p.Y))
                {
                    p.X++;
                }
                break;

            case ConsoleKey.UpArrow:
                if (nivel.EsPosibleMover(p.X, p.Y - 1))
                {
                    p.Y--;
                }
                break;

            case ConsoleKey.DownArrow:
                if (nivel.EsPosibleMover(p.X, p.Y + 1))
                {
                    p.Y++;
                }
                break;

            default:
                break;
            }
            foreach (Fantasma f in fantasmas)
            {
                f.Mover();
            }

            foreach (Fantasma f in fantasmas)
            {
                f.Mostrar();
            }

            p.Mostrar();
            nivel.AumentarPuntuacion(nivel.ObtenerPuntosDe(p.X, p.Y));
        }while (!salir && !EsFinDePartida(fantasmas, p) && !nivel.FinPartida());
        Console.Clear();
        nivel.MostrarPuntuacion();
        if (nivel.FinPartida())
        {
            Console.WriteLine("Enhorabuena has ganado, los juglares cantaran tu gesta " +
                              "y Nacho te aprobará este curso");
        }
        if (EsFinDePartida(fantasmas, p))
        {
            Console.WriteLine("Te has morido");
        }
    }
Beispiel #2
0
    static void Main()
    {
        bool  salir = false;
        Nivel n     = new Nivel();

        n.CrearLaberinto();
        n.Mostrar();
        n.MostrarMarcador();

        Pac p = new Pac(7, 5);

        p.Mostrar();
        p.Mover();
        Fantasma[] fantasmas = new Fantasma[4];
        fantasmas[0] = new FantasmaRojo(2, 1);
        fantasmas[1] = new FantasmaNaranja(10, 8);
        fantasmas[2] = new FantasmaRosa(11, 1);
        fantasmas[3] = new FantasmaAzul(13, 7);
        do
        {
            n.Mostrar();
            n.MostrarMarcador();
            p.Mostrar();

            for (int i = 0; i < fantasmas.Length; i++)
            {
                fantasmas[i].Mostrar();
            }

            ConsoleKeyInfo tecla = Console.ReadKey();

            switch (tecla.Key)
            {
            case ConsoleKey.Escape:
                salir = true;
                break;

            case ConsoleKey.LeftArrow:
                if (n.EsPosibleMoverA(p.X - 1, p.Y))
                {
                    p.X--;
                }
                n.ObtenerPuntosDe(p.X, p.Y);
                break;

            case ConsoleKey.RightArrow:
                if (n.EsPosibleMoverA(p.X + 1, p.Y))
                {
                    p.X++;
                }
                n.ObtenerPuntosDe(p.X, p.Y);
                break;

            case ConsoleKey.UpArrow:
                if (n.EsPosibleMoverA(p.X, p.Y - 1))
                {
                    p.Y--;
                }
                n.ObtenerPuntosDe(p.X, p.Y);
                break;

            case ConsoleKey.DownArrow:
                if (n.EsPosibleMoverA(p.X, p.Y + 1))
                {
                    p.Y++;
                }
                n.ObtenerPuntosDe(p.X, p.Y);
                break;

            default:
                break;
            }

            for (int i = 0; i < fantasmas.Length; i++)
            {//Falta depurar movimiento de fantasmas
                if (n.EsPosibleMoverA(fantasmas[i].X, fantasmas[i].Y + 1))
                {
                    fantasmas[i].MoverAbajo();
                }
                else if (n.EsPosibleMoverA(fantasmas[i].X, fantasmas[i].Y - 1))
                {
                    fantasmas[i].MoverArriba();
                }
                else if (n.EsPosibleMoverA(fantasmas[i].X + 1, fantasmas[i].Y))
                {
                    fantasmas[i].MoverIzquierda();
                }
                else if (n.EsPosibleMoverA(fantasmas[i].X - 1, fantasmas[i].Y))
                {
                    fantasmas[i].MoverDerecha();
                }
            }
            Console.Clear();

            foreach (Fantasma f in fantasmas)
            {
                f.Mostrar();
            }

            n.Mostrar();
            p.Mostrar();

            for (int i = 0; i < fantasmas.Length; i++)
            {
                if (p.X == fantasmas[i].X && p.Y == fantasmas[i].Y)
                {
                    salir = true;
                }
            }

            if (salir)
            {
                Console.WriteLine("TE HA COMIDO EL FANTASMA!");
            }
        }while (!salir);
        Console.SetCursorPosition(5, 12);
        Console.WriteLine("FIN DE LA PARTIDA!");
    }