Exemplo n.º 1
0
        /// <summary>
        /// Get Ready method to animate the begining of the game or level
        /// </summary>
        private void GetReady()
        {
            // Create a new timer counter
            Timer counter = new Timer(160);

            // Create a new timer to blink the text
            Timer blinker = new Timer(9);

            // Create a new bool to display the text
            bool displayText = true;

            // While the counter is counting
            while (counter.IsCounting())
            {
                // Updates the header
                DisplayHeader();

                // Sets the `displayText` to true or false
                displayText = !blinker.IsCounting() ? !displayText : displayText;

                // If the displayText is true
                if (displayText)
                {
                    // Set a color and write to the buffer
                    BufferEditor.WriteWithColor(0, 50, " ", ConsoleColor.Yellow);
                    BufferEditor.Write(45, 50, "Get Ready!");
                }
                // Else...
                else
                {
                    // Delete from the buffer
                    BufferEditor.Delete(45, 50, "          ");
                }

                // Move the enemies down
                enemies.MoveDown();

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

                // Delay the loop
                Thread.Sleep(BASE_DELAY);
            }

            // Delete the text again
            BufferEditor.Write(45, 50, "          ");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Renders all the sprites in the menu
        /// </summary>
        public void RenderMenu()
        {
            // Display the enemies in the menu
            // Enemy 1
            for (int i = 0; i < Sprites.enemy1String.Length; i++)
            {
                BufferEditor.WriteWithColor(0, 10 + i, " ", ConsoleColor.Green);
                BufferEditor.Write(6, 10 + i, Sprites.enemy1String[i]);
                BufferEditor.Write(85, 10 + i, Sprites.enemy1String[i]);
            }
            // Enemy 2
            for (int i = 0; i < Sprites.enemy2String.Length; i++)
            {
                BufferEditor.WriteWithColor(0, 17 + i, " ", ConsoleColor.Cyan);
                BufferEditor.Write(6, 17 + i, Sprites.enemy2String[i]);
                BufferEditor.Write(85, 17 + i, Sprites.enemy2String[i]);
            }
            // Enemy 3
            for (int i = 0; i < Sprites.enemy3String.Length; i++)
            {
                BufferEditor.WriteWithColor(0, 24 + i, " ", ConsoleColor.Magenta);
                BufferEditor.Write(6, 24 + i, Sprites.enemy3String[i]);
                BufferEditor.Write(85, 24 + i, Sprites.enemy3String[i]);
            }
            // Enemy 4
            for (int i = 0; i < Sprites.enemy4String.Length; i++)
            {
                BufferEditor.WriteWithColor(0, 31 + i, " ", ConsoleColor.Blue);
                BufferEditor.Write(6, 31 + i, Sprites.enemy4String[i]);
                BufferEditor.Write(85, 31 + i, Sprites.enemy4String[i]);
            }
            // Enemy 5
            for (int i = 0; i < Sprites.enemy5String.Length; i++)
            {
                BufferEditor.WriteWithColor(0, 37 + i, " ", ConsoleColor.DarkGreen);
                BufferEditor.Write(6, 37 + i, Sprites.enemy5String[i]);
                BufferEditor.Write(85, 37 + i, Sprites.enemy5String[i]);
            }

            // Display Title
            for (int i = 0; i < Sprites.spaceString.Length; i++)
            {
                BufferEditor.WriteWithColor(0, 21 + i, " ", ConsoleColor.Yellow);
                BufferEditor.Write(21, 21 + i, Sprites.spaceString[i]);
                BufferEditor.Write(45, 21 + i, Sprites.invadersString[i]);
            }

            // Display Buttons
            for (int i = 0; i < Sprites.playString.Length; i++)
            {
                BufferEditor.WriteWithColor(0, 28 + i, " ", ConsoleColor.White);
                BufferEditor.Write(22, 28 + i, Sprites.playString[i]);
                BufferEditor.Write(63, 28 + i, Sprites.quitString[i]);
            }

            // Display Button Selector
            for (int i = 0; i < Sprites.selectionString.Length; i++)
            {
                BufferEditor.WriteWithColor(0, 33 + i, " ", ConsoleColor.White);
                // If we have the play button selected
                if (playSelected)
                {
                    // Draw the ship bellow the play button
                    BufferEditor.Write(PLAY_X_SELECTION, Y_SELECTION + i, Sprites.selectionString[i]);
                    BufferEditor.Write(QUIT_X_SELECTION, Y_SELECTION + i, "      ");
                }
                // If we have the quit button selected
                else if (quitSelected)
                {
                    // Draw the ship bellow the quit button
                    BufferEditor.Write(QUIT_X_SELECTION, Y_SELECTION + i, Sprites.selectionString[i]);
                    BufferEditor.Write(PLAY_X_SELECTION, Y_SELECTION + i, "      ");
                }
            }

            // Tells the double buffer to render the frame
            BufferEditor.DisplayRender();

            // Gets the input from the user
            GetInput();
        }
Exemplo n.º 3
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();
        }
Exemplo n.º 4
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();
        }
Exemplo n.º 5
0
        /// <summary>
        /// The player lost a life
        /// </summary>
        private void LifeLost()
        {
            // Int with the time ammount the blinking will last
            int timer = (lifes == 0) ? 50 : 150;

            // Create a new timer
            counter = new Timer(timer);

            // How long it takes for each blink
            blinkCounter = new Timer(8);

            // If we wan't to display the lifes
            bool displayLife = true;

            // Decrease the ammount of lifes
            lifes--;

            // Set the life lost to true
            ship.LifeLost = true;

            // Reset the Enemies Move Up
            enemies.ResetMoveUp();

            // Set the ship destroyed true
            enemies.shipDestroyed = true;

            // Add an explosion
            explosions.Add(ship.Coordinates, ExplosionType.LARGE);

            // While the counter is counting
            while (counter.IsCounting())
            {
                // Go through all objects in the collection
                for (int i = 0; i < objectsCollection.Count; i++)
                {
                    // Update them
                    (objectsCollection[i] as GameObject).Update();
                }

                // Delay the thread by a certain ammout of time so the game can be precieved
                Thread.Sleep(BASE_DELAY);

                // If the blink counter has stopped counting
                if (!blinkCounter.IsCounting())
                {
                    // If display life is true
                    if (displayLife)
                    {
                        // Set it to false
                        displayLife = false;

                        // Display the lifes
                        NumberManager.WriteLifes(lifes + 1);
                        BufferEditor.DisplayRender();
                        NumberManager.WriteLifes(lifes + 1);
                    }
                    // Else
                    else
                    {
                        // Set it to true
                        displayLife = true;

                        // Delete the lifes
                        NumberManager.DeleteLifes();
                    }
                }

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

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

            // Reset the ship values
            ship.Init(level);

            // Set the life lost to false
            ship.LifeLost = false;

            // Set the ship destroyed to false
            enemies.shipDestroyed = false;

            // Display the lifes
            NumberManager.WriteLifes(lifes);
        }