Ejemplo n.º 1
0
    static void Main(string[] args)
    {
        startMenu();
        Console.BufferWidth   = Console.WindowWidth = consoleWidth;
        Console.BufferHeight  = Console.WindowHeight = consoleHeight;
        Console.CursorVisible = false;
        Dwarf       Toshko    = new Dwarf();
        Rocket      littleBoy = new Rocket();
        List <Rock> rocks     = new List <Rock>();

        int level = 1;
        int score = 0;
        int speed = startSpeed;

        while (Toshko.Lives > 0)
        {
            displayMenuAndFrame(Toshko.Lives, speed, level, score < playGroundHeight ? 0 : score - 40);
            printObject(Toshko);
            if (littleBoy.IsFired == true)
            {
                printObject(littleBoy);
            }

            while (Console.KeyAvailable)
            {
                ConsoleKeyInfo pressedKey = Console.ReadKey();
                if (pressedKey.Key == ConsoleKey.RightArrow)
                {
                    Toshko.MoveRight();
                }
                else if (pressedKey.Key == ConsoleKey.LeftArrow)
                {
                    Toshko.MoveLeft();
                }
                else if (pressedKey.Key == ConsoleKey.UpArrow)
                {
                    if (littleBoy.IsFired == false)
                    {
                        littleBoy.IsFired = true;
                        littleBoy.X       = Toshko.X + 1;
                        littleBoy.Y       = Toshko.Y - 1;
                        printObject(littleBoy);
                    }
                }
            }

            Random rand        = new Random();
            int    rocksPerRow = rand.Next(1, 5 + level);

            for (int i = 0; i < rocksPerRow; i++)
            {
                Rock rock = new Rock();
                rocks.Add(rock);
            }

            bool collision = false;
            Rock hitedRock = new Rock(0, 0, "*", ConsoleColor.Red);
            for (int i = 0; i < rocks.Count; i++)
            {
                if (rocks[i].Y <= playGroundHeight)
                {
                    printObject(rocks[i]);
                }
                else
                {
                    rocks[i].destroy();
                }
                if ((rocks[i].Y == Toshko.Y) && (rocks[i].X >= Toshko.X && rocks[i].X <= Toshko.X + 2))
                {
                    collision = true;
                }
                if (littleBoy.IsFired == true && littleBoy.X == rocks[i].X &&
                    (littleBoy.Y == rocks[i].Y || littleBoy.Y == rocks[i].Y + 1))
                {
                    littleBoy.IsFired = false;
                    hitedRock.X       = rocks[i].X;
                    hitedRock.Y       = rocks[i].Y;
                    printObject(hitedRock);
                }

                if (rocks[i].Destroyed == true || (rocks[i].X == hitedRock.X && rocks[i].Y == hitedRock.Y))
                {
                    rocks.RemoveAt(i--);
                }
                else
                {
                    rocks[i].Fall();
                }
            }

            if (collision)
            {
                clearPlayGround(2);
                printObject(new Object(Toshko.X, Toshko.Y, "XXX", ConsoleColor.Red));
                Toshko.Lives--;
                Console.Beep();
            }

            if (littleBoy.IsFired)
            {
                littleBoy.moveUp();
            }

            if (((score - playGroundHeight) % 50 == 0) && (score > playGroundHeight) && (speed > 30))
            {
                speed -= 5;
            }
            if ((score - playGroundHeight) == Math.Pow(2, level) * 30)
            {
                level++;
            }

            score++;
            Thread.Sleep(speed);
            clearPlayGround(1);
        }
    }