Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class Program
- {
- #region Fields
- private static int age,
- strength,
- agility,
- intelligence,
- points = 25;
- #endregion
- #region General methods
- private static void Main(string[] args)
- {
- Intro();
- DistributePointsLoop();
- Outro();
- }
- private static void Intro()
- {
- PrintLines(
- "Добро пожаловать в меню выбора создания персонажа!",
- "У вас есть 25 очков, которые вы можете распределить по умениям"
- );
- ReadKey("Нажмите любую клавишу чтобы продолжить...");
- }
- private static void DistributePointsLoop()
- {
- while (points > 0)
- DistributePoints();
- }
- private static void DistributePoints()
- {
- ClearConsole();
- PrintLines(
- "Поинтов - " + points,
- "Возраст - " + age,
- "Сила - " + GetProgressBar(strength),
- "Ловкость - " + GetProgressBar(agility),
- "Интеллект - " + GetProgressBar(intelligence)
- );
- string subject = ReadLine("Какую характеристику вы хотите изменить?");
- string operation = ReadLine("Что вы хотите сделать? +\\-");
- int operandPoints = ReadInt("Колличество поинтов которые следует " + (operation == "+" ? "прибавить" : "отнять"));
- if (operation == "-") operandPoints *= -1;
- else if (operation != "+") operandPoints = 0;
- switch (subject.ToLower())
- {
- case "сила": points += strength - (strength = GetCorrectProgress(strength, operandPoints, points)); break;
- case "ловкость": points += agility - (agility = GetCorrectProgress(agility, operandPoints, points)); break;
- case "интелект": points += intelligence - (intelligence = GetCorrectProgress(intelligence, operandPoints, points)); break;
- }
- }
- private static void Outro()
- {
- age = ReadInt("Вы распределили все очки. Введите возраст персонажа:");
- ClearConsole();
- PrintAllСharacteristics();
- ReadKey();
- }
- #endregion
- #region Local utility
- private static void PrintAllСharacteristics()
- {
- PrintLines(
- "Поинтов - " + points,
- "Возраст - " + age,
- "Сила - " + GetProgressBar(strength),
- "Ловкость - " + GetProgressBar(agility),
- "Интеллект - " + GetProgressBar(intelligence)
- );
- }
- private static int GetCorrectProgress(int progress, int shift, int points, int max = 10)
- {
- int shiftedProgress = progress + shift;
- if (shiftedProgress < 0 || shiftedProgress > max || shift > points)
- return progress;
- else return shiftedProgress;
- }
- private static string GetProgressBar(int progress, int max = 10)
- {
- return "[" + new string('#', progress) + new string('_', max - progress) + "]";
- }
- #endregion
- #region Console I/O
- private static int ReadInt(string msg)
- {
- Print(msg);
- return ReadInt();
- }
- private static int ReadInt()
- {
- int result;
- //4.0, "out int result" - exception :)
- while (!int.TryParse(ReadLine(), out result)) { }
- return result;
- }
- private static string ReadLine(string msg)
- {
- Print(msg);
- return ReadLine();
- }
- private static string ReadLine()
- {
- return Console.ReadLine();
- }
- private static void ReadKey(string msg)
- {
- Print(msg);
- ReadKey();
- }
- private static void ReadKey()
- {
- Console.ReadKey(true);
- }
- private static void PrintLines(params string[] lines)
- {
- Print(string.Join<string>("\n", lines));
- }
- private static void Print(string msg, bool newLine = true)
- {
- if (newLine) msg += '\n';
- Console.Write(msg);
- }
- private static void ClearConsole()
- {
- Console.Clear();
- }
- #endregion
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement