Vapio

task19

Apr 6th, 2021 (edited)
619
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.71 KB | None | 0 0
  1. using System;
  2.  
  3. public class Program
  4. {
  5.     public static void Main()
  6.     {
  7.         DrawHealthBar(0.60f, 0.1f, 4, 1);
  8.         DrawHealthBar(0.75f, 0.1f, 1, 4);
  9.     }
  10.  
  11.     public static void DrawHealthBar(float percent, float percentPerCell, int positionX, int positionY, char sign = '#')
  12.     {
  13.         int cellsAmount = (int) (1.0f / percentPerCell);
  14.  
  15.         Console.SetCursorPosition(positionX, positionY);
  16.         Console.Write("[");
  17.         for (int i = 0; i < cellsAmount; ++i, percent -= percentPerCell)
  18.         {
  19.             if (percent > percentPerCell)
  20.                 Console.Write(sign);
  21.             else
  22.                 Console.Write("_");
  23.         }
  24.         Console.Write("]\n");
  25.     }
  26. }
Add Comment
Please, Sign In to add comment