Advertisement
TeT91

ДЗ: UIElement

May 16th, 2024 (edited)
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. using System;
  2.  
  3. namespace CSLight
  4. {
  5. internal class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. int health = 3;
  10. int maxHealth = 10;
  11. int healthBarPositionX = 0;
  12. int healthBarPositionY = 0;
  13.  
  14. int mana = 20;
  15. int maxMana = 100;
  16. int manaBarPositionX = 0;
  17. int manaBarPositionY = 1;
  18.  
  19. DrawBar(health, maxHealth, ConsoleColor.Red, healthBarPositionX, healthBarPositionY);
  20. DrawBar(mana, maxMana, ConsoleColor.Blue, manaBarPositionX, manaBarPositionY);
  21. Console.ReadKey();
  22.  
  23. }
  24. private static void DrawBar(int value, int maxValue, ConsoleColor color, int positionX, int positionY)
  25. {
  26. int barSize = 10;
  27. char barSymbol = ' ';
  28. ConsoleColor barColor = color;
  29.  
  30. float maxPercent = 100;
  31. float valuePercent = Convert.ToSingle( value) / maxValue * maxPercent;
  32. float fulnessPercent = valuePercent / Convert.ToSingle(barSize);
  33.  
  34. Console.Write("[");
  35. Console.BackgroundColor = barColor;
  36.  
  37. DrawBarBlock(0, fulnessPercent, barSymbol);
  38.  
  39. Console.ResetColor();
  40.  
  41. DrawBarBlock(fulnessPercent, barSize, barSymbol);
  42.  
  43. Console.ResetColor();
  44.  
  45. Console.Write("]");
  46. Console.WriteLine();
  47. }
  48.  
  49. private static void DrawBarBlock(float startDraw,float endDraw, char symbol)
  50. {
  51. for (float i = startDraw; i < endDraw; i++)
  52. {
  53. Console.Write(symbol);
  54. }
  55. }
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement