Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace ConsoleApp1
- {
- using System;
- using System.Text;
- public class Startup
- {
- public static void Main()
- {
- string[] labelsForBars = new string[]
- {
- "Health",
- "Energy"
- };
- const char BarBoard = '|';
- const char FullSymbol = '|';
- const char EmptySymbol = '.';
- string name = Console.ReadLine();
- StringBuilder result = new StringBuilder();
- result.AppendLine($"Name: {name}");
- for (int indexOfBarLabel = 0; indexOfBarLabel < labelsForBars.Length; indexOfBarLabel++)
- {
- string currentBarLabel = labelsForBars[indexOfBarLabel];
- int currentValue = int.Parse(Console.ReadLine());
- int maxValue = int.Parse(Console.ReadLine());
- string createdBar = CreateBar(currentBarLabel,
- currentValue,
- maxValue,
- BarBoard,
- FullSymbol,
- EmptySymbol);
- result.AppendLine(createdBar);
- }
- Console.WriteLine(result.ToString().Trim());
- }
- private static string CreateBar(string label,
- int currValue,
- int maxValue,
- char barBoard,
- char fullSymbol,
- char emptySymbol)
- {
- StringBuilder createdBar = new StringBuilder();
- createdBar.Append($"{label}: {barBoard}");
- int countOfFull = Math.Min(currValue, maxValue);
- int countOfEmpty = Math.Min(maxValue - currValue, maxValue);
- string repeatedFullSymbols = RepeatSymbol(fullSymbol, countOfFull);
- string repeatedEmptySymbols = RepeatSymbol(emptySymbol, countOfEmpty);
- createdBar.Append(repeatedFullSymbols);
- createdBar.Append(repeatedEmptySymbols);
- createdBar.Append(barBoard);
- return createdBar.ToString();
- }
- private static string RepeatSymbol(char symbolToRepeat, int timesToRepeat)
- {
- StringBuilder repeatedSymbol = new StringBuilder();
- for (int i = 0; i < timesToRepeat; i++)
- {
- repeatedSymbol.Append(symbolToRepeat);
- }
- return repeatedSymbol.ToString();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement