Ejemplo n.º 1
0
    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");
        }
    }