Advertisement
RedFlys

Home Work 4.2

Nov 8th, 2019
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.45 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 FifthProject
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             double health = 7;
  14.             double maxHealth = 11;
  15.  
  16.             double healthProcent = ((health / (maxHealth / 100)) / 10)/1 - ((health / (maxHealth / 100)) / 10) % 1;
  17.  
  18.             DrawBar(Convert.ToInt32(healthProcent), 10, ConsoleColor.Red, 0, '#');
  19.  
  20.             Console.ReadKey();
  21.         }
  22.  
  23.         static void DrawBar(int value , int maxValue, ConsoleColor fillColor, int positionY, char fillChar = ' ')
  24.         {
  25.             ConsoleColor defaultColor = Console.BackgroundColor;
  26.             ConsoleColor frontColor = Console.ForegroundColor;
  27.  
  28.             Console.SetCursorPosition(0, 0);
  29.  
  30.             Console.Write('[');
  31.  
  32.             Console.ForegroundColor = fillColor;
  33.             Console.Write(FillBar(0, value, fillChar));
  34.  
  35.             Console.ForegroundColor = defaultColor;
  36.  
  37.             Console.Write(FillBar(value, maxValue, fillChar));
  38.  
  39.             Console.ForegroundColor = frontColor;
  40.  
  41.             Console.Write(']');
  42.         }
  43.  
  44.         static string FillBar(int start, int end, char fillChar)
  45.         {
  46.             string bar = "";
  47.  
  48.             for(int i = start; i < end; i++)
  49.             {
  50.                 bar += fillChar;
  51.             }
  52.  
  53.             return bar;
  54.         }
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement