Advertisement
TwinFrame

UIElement_HealthBar

Jan 16th, 2020
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Clight_18_UIElement_HealthBar
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. int health = 40;
  10. int healthMax = 100;
  11. int lenghtBar = 10;
  12.  
  13. while (true)
  14. {
  15. DrawBar(health, healthMax, lenghtBar);
  16.  
  17. Console.SetCursorPosition(0, 3);
  18. Console.Write($"Введите значение жизни от 0 до {healthMax}: ");
  19. string numUser = Console.ReadLine();
  20.  
  21. bool result = int.TryParse(numUser, out int goodHealth);
  22. if (result == true && (goodHealth <= healthMax && goodHealth >=0))
  23. {
  24. health = goodHealth;
  25. }
  26. else
  27. {
  28. Console.WriteLine("Введите корректное число");
  29. Console.ReadKey();
  30. }
  31. Console.Clear();
  32. }
  33.  
  34. static void DrawBar(int value, int valueMax, int lenghtBar, char symbolHealth = '#', char symbolEmpty = '_')
  35. {
  36. float step = valueMax / lenghtBar;
  37. Console.Write("[");
  38. for (int i = 0; i < lenghtBar; i++)
  39. {
  40. if (value > i*step)
  41. {
  42. Console.Write(symbolHealth);
  43. }
  44. else
  45. {
  46. Console.Write(symbolEmpty);
  47. }
  48. }
  49. Console.Write("]");
  50. }
  51. }
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement