Exemplo n.º 1
0
        /// <summary>
        /// Moves the enemy based on it's current direction
        /// </summary>
        private void Move()
        {
            // If the enemy is to move down
            if (IncreaseY)
            {
                // Clear the area above the enemy
                BufferEditor.WriteWithColor(0, coordinates.Y, " ", ConsoleColor.Black);
                BufferEditor.Delete(coordinates.X, coordinates.Y, "       ");

                // Moves the enemy down
                coordinates.Y++;

                // Reset the `IncreaseY` back to false
                IncreaseY = false;
            }
            // Else
            else
            {
                // If the movement type is left
                if (MovementType == MoveType.LEFT)
                {
                    // Move the enemy left
                    coordinates.X--;
                }
                // Else if the movement type is right
                else if (MovementType == MoveType.RIGHT)
                {
                    // Move the enemy right
                    coordinates.X++;
                }
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Set's the color for the barriers
 /// </summary>
 public void SetColor()
 {
     for (int i = 0; i < BARRIER_HEIGHT; i++)
     {
         BufferEditor.WriteWithColor(0, coordinates.Y + i - 1, " ", ConsoleColor.Green);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Displays the header
        /// </summary>
        private void DisplayHeader()
        {
            // Set the color to red
            BufferEditor.WriteWithColor(0, 0, " ", ConsoleColor.Red);
            BufferEditor.WriteWithColor(0, 5, " ", ConsoleColor.Red);

            // Loop 100 times
            for (int i = 0; i < 100; i++)
            {
                // Write to the buffer
                BufferEditor.Write(i, 0, "-");
                BufferEditor.Write(i, 5, "-");
            }

            // Change the color to blue
            BufferEditor.WriteWithColor(0, 1, " ", ConsoleColor.Blue);

            // Write to the buffer
            BufferEditor.Write(1, 1, "Score:");
            BufferEditor.Write(30, 1, "Level:");
            BufferEditor.Write(47, 1, "Lifes:");

            // Write the numbers to the buffer
            NumberManager.WriteScore(score);
            NumberManager.WriteLevel(level);
            NumberManager.WriteLifes(lifes);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Write the bullet to the buffer
        /// </summary>
        private void Write()
        {
            // Write to the buffer
            BufferEditor.Delete(coordinates.X, coordinates.Y, bullet.ToString());

            BufferEditor.WriteWithColor(0, coordinates.Y, " ", ConsoleColor.White);
        }
Exemplo n.º 5
0
        public void Delete()
        {
            // Go through the ship sprite array
            for (int i = 0; i < sprite.Length; i++)
            {
                // Write each string to the buffer
                BufferEditor.Delete(coordinates.X, coordinates.Y + i, "         ");

                BufferEditor.WriteWithColor(0, coordinates.Y + i, " ", ConsoleColor.Black);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Writes the ship sprite to the buffer
        /// </summary>
        private void WriteToBuffer()
        {
            // Go through the ship sprite array
            for (int i = 0; i < sprite.Length; i++)
            {
                // Write each string to the buffer
                BufferEditor.Write(coordinates.X, coordinates.Y + i, sprite[i]);

                // Set the color to white
                BufferEditor.WriteWithColor(0, coordinates.Y + i, " ", ConsoleColor.White);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Writes the enemy sprite to the buffer
        /// </summary>
        private void WriteToBuffer()
        {
            // Select the correct sprite to render
            currentSprite = FirstSprite ? sprite1 : sprite2;

            // Go through the array of strings
            for (int i = 0; i < currentSprite.Length; i++)
            {
                // Write a string to the buffer
                BufferEditor.WriteWithColor(0, coordinates.Y + i, " ", myColor);

                // Write each string to the buffer
                BufferEditor.Delete(coordinates.X, coordinates.Y + i, currentSprite[i]);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Writes the ovni to the buffer
        /// </summary>
        public void Write()
        {
            // If the current state is Flying
            if (currentState == State.FLYING)
            {
                // Loop the height of the ovni sprite
                for (int i = 0; i < OVNI_HEIGHT; i++)
                {
                    // Set the color
                    BufferEditor.WriteWithColor(0, coordinates.Y + i, " ", ConsoleColor.DarkMagenta);

                    // Write the ovni to the buffer
                    BufferEditor.Write(coordinates.X, coordinates.Y + i, sprite[i]);
                }
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Writes the number to the buffer
        /// </summary>
        /// <param name="value">
        /// The value it self (number of lifes, score, etc...)</param>
        /// <param name="xOffset">
        /// Offset the number to the right depending on the number of numbers</param>
        /// <param name="x">The x value where the number will be displayed</param>
        private static void WriteNumber(int value, int xOffset, int x)
        {
            // Loops 3 times...
            for (int i = 0; i < NUMBER_ROWS; i++)
            {
                // Change the color depending on the row
                BufferEditor.WriteWithColor(0, i + 2, " ", i == 0 ?
                                            ConsoleColor.White :
                                            i == 1 ?
                                            ConsoleColor.Yellow :
                                            ConsoleColor.DarkYellow);

                // Write each string to the buffer
                BufferEditor.Write(x + xOffset, i + 2, digits[value][i]);
            }
        }
Exemplo n.º 10
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.º 11
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.º 12
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();
        }