kwest87

Untitled

Nov 9th, 2022
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. /*
  7. * Разработайте функцию, которая рисует некий бар (Healthbar, Manabar) в определённой позиции. Она также принимает некий закрашенный процент.
  8. *
  9. * При 40% бар выглядит так:
  10. *
  11. * [####______]
  12. *
  13. */
  14.  
  15.  
  16. namespace ConsoleApp1
  17. {
  18. internal class Program
  19. {
  20. static void Main(string[] args)
  21. {
  22. int healthBar = 10;
  23. int manaBar = 10;
  24. int healthPoint = 8;
  25. int manaPoint = 6;
  26. int positionHealth = 0;
  27. int positionMana = 12;
  28. int barPosition = 1;
  29. string health = " HP";
  30. string mana = " MANA";
  31. DrawResourse(health, ConsoleColor.Red, positionHealth);
  32. DrawResourse(mana, ConsoleColor.Blue, positionMana);
  33. DrawBar(healthBar, healthPoint, ConsoleColor.Red, positionHealth, barPosition);
  34. DrawBar(manaBar, manaPoint, ConsoleColor.Blue, positionMana, barPosition);
  35. }
  36.  
  37. static void DrawResourse(string text, ConsoleColor color, int position)
  38. {
  39. Console.SetCursorPosition(position, 0);
  40. Console.ForegroundColor = color;
  41. Console.WriteLine("" + text);
  42. Console.ForegroundColor = ConsoleColor.White;
  43. }
  44.  
  45. static void DrawBar(int maxValue, int value, ConsoleColor color, int position, int barPosition)
  46. {
  47. Console.SetCursorPosition(position, barPosition);
  48. string bar = " ";
  49. ConsoleColor defaultColor = Console.BackgroundColor;
  50. Console.Write("[");
  51. Console.BackgroundColor = color;
  52.  
  53. for (int i = 0; i < value; i++)
  54. {
  55. Console.Write(bar);
  56. }
  57.  
  58. Console.BackgroundColor = defaultColor;
  59.  
  60. for (int i = value; i < maxValue; i++)
  61. {
  62. Console.Write(bar);
  63. }
  64.  
  65. Console.WriteLine("]");
  66. }
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment