コード例 #1
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!");
    }