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