Advertisement
Yurka21

hw bar

Dec 17th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 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. namespace ConsoleApp3
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. Console.WriteLine("Укажите позицию Х в которой хотите нарисовать bar");
  14. int positionY = Convert.ToInt32(Console.ReadLine());
  15.  
  16. Console.WriteLine("Укажите позицию У в которой хотите нарисовать bar");
  17. int positionX = Convert.ToInt32(Console.ReadLine());
  18.  
  19. Console.WriteLine("Укажите значение для закрашивания");
  20. int health = Convert.ToInt32(Console.ReadLine());
  21.  
  22. Console.WriteLine("Укажите максимальное значение бара");
  23. int maxHealth = Convert.ToInt32(Console.ReadLine());
  24. Console.Clear();
  25.  
  26. DrawBar(health, maxHealth, ConsoleColor.Red, positionY, positionX);
  27. }
  28. static void DrawBar(int value, int maxValue, ConsoleColor color, int positionY, int positionX)
  29. {
  30. ConsoleColor defaultColor = Console.BackgroundColor;
  31. string bar = "";
  32. for (int i = 0; i < value; i++)
  33. {
  34. bar += '_';
  35. }
  36. Console.SetCursorPosition(positionY, positionX);
  37. Console.Write("[");
  38. Console.BackgroundColor = color;
  39. Console.Write(bar);
  40. Console.BackgroundColor = defaultColor;
  41.  
  42. bar = "";
  43. for (int i = value; i < maxValue; i++)
  44. {
  45. bar += '_';
  46. }
  47. Console.Write(bar + ']' + "\n\n");
  48. }
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement