コード例 #1
0
    static void Main()
    {
        Ground ground = new Ground();

        BlueFish   bluefish   = new BlueFish(35, 20);
        RedFish    redfish    = new RedFish(45, 38);
        YellowFish yellowfish = new YellowFish(30, 22);

        while (true)
        {
            bluefish.DrawFish();
            redfish.DrawFish();
            yellowfish.DrawFish();
            bluefish.MoveFish();
            redfish.MoveFish();
            yellowfish.MoveFish();
            Thread.Sleep(40);
        }

        while (true)
        {
            Console.Clear();

            Ceiling ceiling = new Ceiling();
            ceiling.Draw();

            Rock rock = new Rock();
            rock.Draw(50, 22);

            PauseTillNextFrame(1000);
        }
    }
コード例 #2
0
    public void Run()
    {
        bool           finished = false;
        ConsoleKeyInfo key;

        while (!finished)
        {
            // Draw elements
            Console.Clear();
            myRock.Draw();
            for (int i = 0; i < amountOfFishes; i++)
            {
                fishes[i].Draw();
            }
            myBubble.Draw();

            // Move elements for next frame
            for (int i = 0; i < amountOfFishes; i++)
            {
                fishes[i].Move();
            }
            myBubble.Move();

            // And wait for the next frame
            Thread.Sleep(100);

            // Also, we can let the user exit the program, pressing ESC
            if (Console.KeyAvailable)
            {
                key = Console.ReadKey();
                if (key.Key == ConsoleKey.Escape)
                {
                    finished = true;
                }
            }
        }

        Console.Clear();
        Console.SetCursorPosition(35, 12);
        Console.ForegroundColor = ConsoleColor.White;
        Console.WriteLine("Bye Bye!");
        Console.ReadKey();
    }
コード例 #3
0
    public static void PlayApacheCombat()
    {
        Console.Clear();

        string[,] rockElements = new string[, ] {
            { " ", "P", " " }, { "P", " ", "P" }
        };

        Helicopter helicopter = new Helicopter();

        Helicopter.SetPosition(helicopter);
        Rock rock = new Rock(rockElements, consoleWindowWidth - 3, 13);

        while (true)
        {
            if (Console.KeyAvailable)
            {
                ConsoleKeyInfo keyInfo = Console.ReadKey();
                if (keyInfo.Key == ConsoleKey.UpArrow)
                {
                    Helicopter.MoveUp(helicopter);
                }
                if (keyInfo.Key == ConsoleKey.DownArrow)
                {
                    Helicopter.MoveDown(helicopter);
                }
            }

            HandleCollision(rock, helicopter, out collisionExists);

            if (collisionExists == true)
            {
                break;
            }
            Helicopter.Draw(helicopter);
            Rock.Draw(rock);
            Rock.MoveLeft(rock);
            Thread.Sleep(100);
            Console.Clear();
        }
    }
コード例 #4
0
    static void Main()
    {
        int frame = 1;
        while (true)
        {
            frame = -frame;

            Ceiling ceiling = new Ceiling();
            ceiling.SetWidth(80);
            if (frame == 1)
                ceiling.Draw('_');
            else
                ceiling.Draw('-');

            Rock rock = new Rock();
            rock.Draw();

            PauseTillNextFrame(300);
            Console.Clear();
        }
    }