TargeTPoweR

HealthBar

Mar 28th, 2020
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 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 Tasks
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. int health = 5;
  14. int maxHealth = 20;
  15. Console.WriteLine("Здравствуйте, в какой позиции вы хотите нарисовать шкалу?");
  16. Console.WriteLine("Последовательно введите координаты по осям X и Y.");
  17.  
  18. int xPos = Convert.ToInt32(Console.ReadLine());
  19. int yPos = Convert.ToInt32(Console.ReadLine());
  20.  
  21. Console.SetCursorPosition(xPos, yPos);
  22. PaintBar(health, maxHealth, ConsoleColor.Green);
  23. }
  24.  
  25. static void PaintBar(int value, int maxValue, ConsoleColor color)
  26. {
  27. ConsoleColor oldColor = Console.ForegroundColor;
  28. Console.Write("[");
  29. int empty = maxValue - value;
  30.  
  31. for (int i = 0; i <= value; i++)
  32. {
  33. Console.ForegroundColor = color;
  34. Console.Write("*");
  35. }
  36.  
  37. for (int j = 0; j < empty; j++)
  38. {
  39. Console.ForegroundColor = Console.BackgroundColor;
  40. Console.Write(" ");
  41. }
  42.  
  43. Console.ForegroundColor = oldColor;
  44. Console.WriteLine("]");
  45. }
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment