Exemple #1
0
        /// <summary>
        /// Handles the drawing part of the scene
        /// </summary>
        /// <param name="game">Game manager</param>
        public void Draw(Game game)
        {
            // Game is a generic class, so make sure to convert it to ConsoleGame
            ConsoleGame consoleGame = (ConsoleGame)game;
            // ConsoleGame has a screen to draw whereas Game doesn't
            ConsoleScreen consoleScreen = consoleGame.Screen;

            // Clears the whole screen
            consoleScreen.Clear();

            // Draws STATUS on the top of the screen
            consoleScreen.DrawText(2, 2, "STATUS");

            // Then draws each status and their bars on the bottom of each
            consoleScreen.DrawText(2, 4, "Hunger");
            MakeBar(consoleScreen, 2, 5, GameGlobals.Pet.Hunger, true);

            consoleScreen.DrawText(2, 7, "Energy");
            MakeBar(consoleScreen, 2, 8, GameGlobals.Pet.Energy, false);

            consoleScreen.DrawText(2, 10, "Fat");
            MakeBar(consoleScreen, 2, 11, GameGlobals.Pet.Fat, true);

            consoleScreen.DrawText(2, 13, "Happiness");
            MakeBar(consoleScreen, 2, 14, GameGlobals.Pet.Happiness, false);

            // When we're done drawing everything we needed, updates the screen
            consoleScreen.Show();
        }
 /// <summary>
 /// Draws the sprite on the screen
 /// </summary>
 /// <param name="screen">Console screen</param>
 public void Draw(ConsoleScreen screen)
 {
     // If it's visible and it's holding a map
     if (Visible && (Map != null))
         // Then draws it on the screen
         screen.DrawMap(
             (int)Math.Round(Position.X - Origin.X),
             (int)Math.Round(Position.Y - Origin.Y),
             Map
         );
 }
Exemple #3
0
 /// <summary>
 /// Draws the sprite on the screen
 /// </summary>
 /// <param name="screen">Console screen</param>
 public void Draw(ConsoleScreen screen)
 {
     // If it's visible and it's holding a map
     if (Visible && (Map != null))
     {
         // Then draws it on the screen
         screen.DrawMap(
             (int)Math.Round(Position.X - Origin.X),
             (int)Math.Round(Position.Y - Origin.Y),
             Map
             );
     }
 }
        /// <summary>
        /// Handles the drawing part of the scene
        /// </summary>
        /// <param name="game">Game manager</param>
        public void Draw(Game game)
        {
            // Game is a generic class, so make sure to convert it to ConsoleGame
            ConsoleGame consoleGame = (ConsoleGame)game;
            // ConsoleGame has a screen to draw whereas Game doesn't
            ConsoleScreen consoleScreen = consoleGame.Screen;

            // Clears the whole screen
            consoleScreen.Clear();

            // Draws "Please enter your pet's name"
            consoleScreen.DrawText(8, 6, "Please enter your\n   pet's name:");
            // Centers and draw the the current pet's name
            consoleScreen.DrawText((32 - _Name.Length) / 2, 8, _Name);

            // When we're done drawing everything we needed, updates the screen
            consoleScreen.Show();
        }
Exemple #5
0
        /// <summary>
        /// Function to draw the bars on the screen
        /// </summary>
        /// <param name="screen">Console screen</param>
        /// <param name="offsetX">Horizontal offset</param>
        /// <param name="offsetY">Vertical offset</param>
        /// <param name="value">A value from -1 to 1</param>
        /// <param name="highIsBad">Is a high value bad?</param>
        public void MakeBar(ConsoleScreen screen, int offsetX, int offsetY, float value, bool highIsBad = false)
        {
            // Transforms the value from -1 to 1 TO 0 to 1
            double percentage = 0.5 * (100 * value + 100);

            // Creates a right-sized string for the percentage
            string outputString = new string(
                '█',
                // There are only 28 blocks to draw, so that's why there's a 0.28 there
                (int)(Math.Round(percentage * 0.28))
                );

            // Calculates the right color for the bar
            ConsoleColor color;

            // If a high value is bad
            if (highIsBad)
            {
                // If it's less than 50%
                if (percentage <= 50)
                {
                    // Makes the bar green
                    color = ConsoleColor.Green;
                }
                // If it's less than 75%
                else if (percentage <= 75)
                {
                    // Makes the bar yellow
                    color = ConsoleColor.Yellow;
                }
                // If it's more than that
                else
                {
                    // Makes the bar red
                    color = ConsoleColor.Red;
                }
            }
            // If a high value is good
            else
            {
                // Does the opposite
                if (percentage < 25)
                {
                    color = ConsoleColor.Red;
                }
                else if (percentage < 50)
                {
                    color = ConsoleColor.Yellow;
                }
                else
                {
                    color = ConsoleColor.Green;
                }
            }

            // Draws the bar on the screen with the appropriate color
            screen.DrawText(offsetX, offsetY, outputString, (x, y, i, block, a, b, c, chr) =>
            {
                return(new ConsoleBlock(ConsoleColor.Black, color, chr));
            });
        }
        /// <summary>
        /// Handles the drawing part of the scene
        /// </summary>
        /// <param name="game">Game manager</param>
        public void Draw(Game game)
        {
            // Game is a generic class, so make sure to convert it to ConsoleGame
            ConsoleGame consoleGame = (ConsoleGame)game;
            // ConsoleGame has a screen to draw whereas Game doesn't
            ConsoleScreen consoleScreen = consoleGame.Screen;

            // Saves the animation value for later use
            float animationValue = _Animation.Value;

            // Clears the whole screen
            consoleScreen.Clear();

            // Checks what step we are to draw the right thing
            switch (_Step)
            {
            // This step is the one that the ASCII text art goes from right to left
            case 0:
                // It draws the art on the screen
                // The X offset is the animation value because only that axis is the one that's going to move
                // The Y offset (3) is constant
                // This animation value in this case goes from 32 to -360
                consoleScreen.DrawText((int)Math.Round(animationValue), 3, _TitleArt);
                break;

            // This step happens when the text is fading in
            case 1:
            // This step happens when the text is fading out
            case 3:
                // The fade animation is actually a little trick
                ConsoleColor titleColor;

                // The animation value in this part goes from 0 to 1 or 1 to 0
                // So we check the value to use an appropriate color
                if (animationValue < 0.25f)
                {
                    // If the value is too low, we set the text color to black
                    titleColor = ConsoleColor.Black;
                }
                // If it's reaching the middle of the animation
                else if (animationValue < 0.5f)
                {
                    // Sets it to dark gray
                    titleColor = ConsoleColor.DarkGray;
                }
                // If it's almost done
                else if (animationValue < 0.75f)
                {
                    // Sets it to gray
                    titleColor = ConsoleColor.Gray;
                }
                // When it's really almost there
                else
                {
                    // Just set it to white
                    titleColor = ConsoleColor.White;
                }

                // The standard draw text function uses black background and white foreground by default
                // So if the fourth argument is given, you can make something different happen
                consoleScreen.DrawText(7, 4, "Tamagottagettemall\n  by Bruno Tamer", (x, y, i, block, a, b, c, chr) =>
                {
                    // On this case, we use the color that we 'calculated' before
                    return(new ConsoleBlock(ConsoleColor.Black, titleColor, chr));
                });

                break;

            // If it's on the "PRESS START" part
            default:
                // Draws the fully opaque title
                consoleScreen.DrawText(7, 4, "Tamagottagettemall\n  by Bruno Tamer");

                // The animation value in this case means wether the press start is visible or not
                // If it is
                if (animationValue == 1.0f)
                {
                    // Then just draw it
                    consoleScreen.DrawText(11, 12, "PRESS START");
                }

                break;
            }

            // When we're done drawing everything we needed, updates the screen
            consoleScreen.Show();
        }
Exemple #7
0
        /// <summary>
        /// Handles the drawing part of the scene
        /// </summary>
        /// <param name="game">Game manager</param>
        public void Draw(Game game)
        {
            // Game is a generic class, so make sure to convert it to ConsoleGame
            ConsoleGame consoleGame = (ConsoleGame)game;
            // ConsoleGame has a screen to draw whereas Game doesn't
            ConsoleScreen consoleScreen = consoleGame.Screen;

            // Saves the animation value for later use
            float animationValue = _Animation.Value;

            // Clears the whole screen
            consoleScreen.Clear();

            // Checks at what scene step it is
            switch (_Step)
            {
            // This is the part where the current day is displayed
            case 0:
                // Builds the day string
                // It's GameGlobals.Days + 1 because that variable starts at 0
                string       dayText = string.Format("Day {0}", GameGlobals.Days + 1);
                ConsoleColor dayTextColor;

                // Gets the right color for the fade animation
                if (animationValue < 0.25f)
                {
                    dayTextColor = ConsoleColor.Black;
                }
                else if (animationValue < 0.5f)
                {
                    dayTextColor = ConsoleColor.DarkGray;
                }
                else if (animationValue < 0.75f)
                {
                    dayTextColor = ConsoleColor.Gray;
                }
                else
                {
                    dayTextColor = ConsoleColor.White;
                }

                // Centers and draws the text on the screen
                consoleScreen.DrawText((32 - dayText.Length) / 2, 8, dayText, (x, y, i, block, a, b, c, chr) =>
                {
                    return(new ConsoleBlock(ConsoleColor.Black, dayTextColor, chr));
                });
                break;

            // This is the part where you select an action
            case 1:
                // Draws the pet art on the screen
                consoleScreen.DrawText(1, 1, _PetArt);
                // Draws "Please select an action" and the amount of actions you have left
                consoleScreen.DrawText(5, 10, string.Format("Please select an action\nYou have {0} actions left", _ActionsLeft));
                // Draws the action box
                consoleScreen.DrawText(5, 12, _ActionsBox);
                // Draws the current selected action
                // Animation value in this case points to the string index of the selected action
                consoleScreen.DrawText(8, 13, Utils.StringRoulette(_ActionsString, 16, (int)Math.Round(animationValue * 10)));
                break;

            // This is the part where you see the pet feedback
            case 2:
            // This is the part where it's moving to the report scene
            case 3:
            // This is the part where it's moving to the gameover scene
            case 4:

                ConsoleColor textColor;
                Func <int, int, int, ConsoleBlock, int, int, int, char, ConsoleBlock> func = null;

                // If it is on the the feedback step
                if (_Step == 2)
                {
                    // Then just uses white for the texts
                    textColor = ConsoleColor.White;
                }
                else
                {
                    // If it's on any other step, it means that it's fading out
                    // Then we have to get the appropriate color for the texts
                    if (animationValue < 0.25f)
                    {
                        textColor = ConsoleColor.Black;
                    }
                    else if (animationValue < 0.5f)
                    {
                        textColor = ConsoleColor.DarkGray;
                    }
                    else if (animationValue < 0.75f)
                    {
                        textColor = ConsoleColor.Gray;
                    }
                    else
                    {
                        textColor = ConsoleColor.White;
                    }

                    // We have to prepare a function to color the texts to later user
                    func = (x, y, i, block, a, b, c, chr) =>
                    {
                        return(new ConsoleBlock(ConsoleColor.Black, textColor, chr));
                    };
                }

                // Draws the pet art on the screen
                consoleScreen.DrawText(1, 1, _PetArt, func);

                // Gets the pet name and status
                string petName   = GameGlobals.Pet.Name;
                string petStatus = GameGlobals.Pet.Status;

                // And their length
                int petNameLength   = petName.Length;
                int petStatusLength = petStatus.Length;

                // And adjust them on the screen in order to center both
                if (petNameLength > petStatusLength)
                {
                    consoleScreen.DrawText(
                        (32 - petNameLength) / 2,
                        9,
                        petName + "\n" + Utils.StringPadBoth(petStatus, petNameLength),
                        func
                        );
                }
                else
                {
                    consoleScreen.DrawText(
                        (32 - petStatusLength) / 2,
                        9,
                        Utils.StringPadBoth(petName, petStatusLength) + "\n" + petStatus,
                        func
                        );
                }

                // If it's on the feedback part, tells the player that they can proceed to select another action
                if (_Step == 2)
                {
                    consoleScreen.DrawText(10, 14, "PRESS ANY KEY");
                }

                break;
            }

            // When we're done drawing everything we needed, updates the screen
            consoleScreen.Show();
        }