예제 #1
0
        /// <summary>
        /// Game Loop Class
        /// </summary>
        public void Loop()
        {
            // Intantiate a new ship
            ship = new Ship(level);

            // Add a ship to the objects collection
            objectsCollection.Add(ship);

            // Add the enemies to the objects collection
            objectsCollection.Add(enemies);

            // Add the barriers to the objects collection
            objectsCollection.Add(barriers);

            // Add the ovni to the objects collection
            objectsCollection.Add(ovni);

            // Add the explosions to the objects collection
            objectsCollection.Add(explosions);

            // Clear the buffer from the menu render
            BufferEditor.ClearBuffer();

            /// Call a global Start method ///
            for (int i = 0; i < objectsCollection.Count; i++)
            {
                objectsCollection[i].Start();
            }

            // Create a new long start
            long start;

            // Create a new long timeToWait
            int timeToWait;

            // Calls the get ready animation before the game starts
            GetReady();

            // Loops...
            do
            {
                // The time in ticks at the start of the frame
                start = DateTime.Now.Ticks / 10000;

                /// Call a global update method ///
                for (int i = 0; i < objectsCollection.Count; i++)
                {
                    objectsCollection[i].Update();
                }

                // Displays the header
                DisplayHeader();

                // Check for hits
                EnemyDestroyedCheck();
                OvniDestroyedCheck();
                BarrierHitCheck();

                // If there's no enemies left
                if (enemies.EnemyList.Count == 0)
                {
                    // Call the level completed method
                    LevelCompleted();
                }

                // Check if the ship was hit
                if (ShipDestroyedCheck())
                {
                    // Call the life lost method
                    LifeLost();

                    gameOver = lifes == 0;
                }

                /// Render the frame ///
                BufferEditor.DisplayRender();

                // Get the delay needed
                timeToWait = (int)(start + FAME_TIME - DateTime.Now.Ticks / 10000);

                // Delay the thread by a certain ammout of time so the game can be precieved
                Thread.Sleep(timeToWait < 0 ? 0 : timeToWait);

                // While the game is not over
            } while (!gameOver);

            // Clears the buffer
            BufferEditor.ClearBuffer();
        }
예제 #2
0
        /// <summary>
        /// Is called when the level is completed to play animations and initialise the next level
        /// </summary>
        private void LevelCompleted()
        {
            // Create a new timer to be a counter for the animations duration
            Timer counter = new Timer(201);

            // Create a new timer for the blinking animation
            Timer blinker = new Timer(9);

            // Create a new bool
            bool displayScore = false;

            // Clears the buffer
            BufferEditor.ClearBuffer();

            // Loops while the counter is counting
            while (counter.IsCounting())
            {
                // Sets the display score to true or false depending on the counter
                displayScore = !blinker.IsCounting() ? !displayScore : displayScore;

                // If displayScore is true
                if (displayScore)
                {
                    // Write an informational text saying that the level was completed
                    BufferEditor.WriteWithColor(0, 22, " ", ConsoleColor.Yellow);
                    BufferEditor.WriteWithColor(0, 24, " ", ConsoleColor.Yellow);
                    BufferEditor.Delete(36, 22, "L E V E L  C O M P L E T E D!");
                    BufferEditor.Delete(38, 24, "Level bonus 1000 points!");
                    NumberManager.WriteLevel(level);
                }
                else
                {
                    // Delete the previously written text
                    BufferEditor.Write(36, 22, "                             ");
                    BufferEditor.Write(38, 24, "                        ");
                    NumberManager.DeleteLevel();
                }

                // Updates the score
                score += 5;
                NumberManager.WriteScore(score);

                // Updates the header
                DisplayHeader();

                // Display the frame
                BufferEditor.DisplayRender();

                // Wait for 20 miliseconds
                Thread.Sleep(20);
            }

            // Removes the text in the middle of the screen
            BufferEditor.Write(36, 22, "                             ");
            BufferEditor.Write(38, 24, "                        ");

            // Increases the level
            level++;

            // Updates the level number
            NumberManager.WriteLevel(level);

            // Delays for 800 miliseconds
            Thread.Sleep(800);

            // Initializes the next level
            InitNextLevel();
        }