Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.37 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace Task2
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             Console.WriteLine("Сколько % жизней у вашего героя?");
  13.             int health = Convert.ToInt32(Console.ReadLine());
  14.  
  15.             DrawHealtBar(health);
  16.             Console.ReadKey();
  17.         }
  18.  
  19.         static void DrawHealtBar(int health, char fillSymbol = '#', char voidSymbol = '_', int left = 55, int top = 0)
  20.         {
  21.             Console.SetCursorPosition(left, top);
  22.  
  23.             char[] simbols = new char[10];
  24.  
  25.             for (int i = 0; i < simbols.Length; i++)
  26.             {
  27.                 simbols[i] = voidSymbol;
  28.             }
  29.  
  30.             if (health <= 100)
  31.             {
  32.                 string bar = "";
  33.  
  34.                 for (int i = 0; i < health / 10; i++)
  35.                 {
  36.                     simbols[i] = fillSymbol;
  37.                 }
  38.  
  39.                 for (int i = 0; i < simbols.Length; i++)
  40.                 {
  41.                     bar += simbols[i];
  42.                 }
  43.  
  44.                 Console.WriteLine("[" + bar + "]");
  45.             }
  46.             else
  47.             {
  48.                 Console.WriteLine("Это не проценты!");
  49.             }
  50.  
  51.             Console.SetCursorPosition(0, 2);
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement