Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///Exercise 1
- using System;
- namespace IMJunior
- {
- public class CharacterStat
- {
- const int MaxPoints = 10;
- public string Name { get; private set; }
- public int value = 0;
- public CharacterStat(string _name) => Name = _name;
- public string GetViewStat() => "".PadLeft(value, '#').PadRight(MaxPoints, '_');
- public int GetAvailable(int sign)
- {
- if (sign == 1 && value == 0 || sign == -1 && value == MaxPoints)
- return MaxPoints;
- else
- return (MaxPoints - sign * value) % MaxPoints;
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- int points = 25;
- int age = 0;
- CharacterStat[] Abilities = new CharacterStat[3]
- {
- new CharacterStat("Сила"),
- new CharacterStat("Ловкость"),
- new CharacterStat("Интелект")
- };
- Console.WriteLine("Добро пожаловать в меню выбора создания персонажа!");
- Console.WriteLine("У вас есть {0} очков, которые вы можете распределить по умениям", points);
- Console.WriteLine("Нажмите любую клавишу чтобы продолжить...");
- Console.ReadKey();
- while (points > 0)
- {
- Console.Clear();
- ViewAllStats();
- Console.WriteLine("Какую характеристику вы хотите изменить?");
- string subject = Console.ReadLine();
- Console.WriteLine(@"Что вы хотите сделать? +\-");
- string operation = Console.ReadLine();
- Console.WriteLine(@"Колличество поинтов которые следует {0}", operation == "+" ? "прибавить" : "отнять");
- int operandPoints = 0;
- ReadIntLine(out operandPoints);
- if (operandPoints < 0)
- operandPoints *= -1;
- ChangeStat(subject, (operation == "+") ? 1 : -1, operandPoints);
- }
- Console.WriteLine("Вы распределили все очки. Введите возраст персонажа:");
- ReadIntLine(out age);
- Console.Clear();
- ViewAllStats();
- Console.ReadLine();
- void ViewAllStats()
- {
- string abilities = $"Поинтов - {points}\nВозраст - {age}\n";
- foreach (var item in Abilities)
- abilities += $"{item.Name} - [{item.GetViewStat()}] \n";
- Console.WriteLine(abilities);
- }
- void ChangeStat(string subject, int sign, int operandPoints)
- {
- subject = subject.ToLower();
- foreach (var item in Abilities)
- {
- if (item.Name.ToLower() == subject)
- {
- int available = item.GetAvailable(sign);
- if (sign == 1)
- available = Math.Min(available, points);
- operandPoints = sign * Math.Min(available, operandPoints);
- item.value += operandPoints;
- points -= operandPoints;
- break;
- }
- }
- }
- void ReadIntLine(out int value)
- {
- string readValue = string.Empty;
- do
- {
- readValue = Console.ReadLine();
- } while (!int.TryParse(readValue, out value));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement