Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace IMJunior
- {
- class Program
- {
- static void Main(string[] args)
- {
- WriteGreetings();
- var hero = new Hero();
- while (hero.FreePoints > 0)
- {
- Console.Clear();
- Console.WriteLine("Поинтов - {0}", hero.FreePoints);
- Console.WriteLine(hero);
- var action = ReadUserAction();
- ApplyUserAction(hero, action);
- }
- Console.WriteLine("Вы распределили все очки. Введите возраст персонажа:");
- hero.Age = ReadInt();
- Console.Clear();
- Console.WriteLine(hero);
- Console.WriteLine("Нажмите любую клавишу чтобы продолжить...");
- Console.ReadKey();
- }
- private static void ApplyUserAction(Hero hero, UserAction action)
- {
- Stat stat;
- if (hero.Stats.TryGetValue(action.Subject.ToLower(), out stat))
- {
- var oldValue = stat.Value;
- ChangeStat(stat, action.Operation, action.OperandPoints);
- UpdateFreePoints(hero, oldValue, stat.Value);
- }
- }
- private static void ChangeStat(Stat stat, string operation, int operandPoints)
- {
- if (operation == "+")
- {
- int overhead = operandPoints - (10 - stat.Value);
- overhead = overhead < 0 ? 0 : overhead;
- operandPoints -= overhead;
- stat.Value += operandPoints;
- }
- else
- {
- int overhead = stat.Value - operandPoints;
- overhead = overhead < 0 ? overhead : 0;
- operandPoints += overhead;
- stat.Value -= operandPoints;
- }
- }
- private static void UpdateFreePoints(Hero hero, int oldStatValue, int newStatValue)
- {
- if (oldStatValue > newStatValue)
- {
- hero.FreePoints += oldStatValue - newStatValue;
- }
- else
- {
- hero.FreePoints -= newStatValue - oldStatValue;
- }
- }
- private static UserAction ReadUserAction()
- {
- var action = new UserAction();
- Console.WriteLine("Какую характеристику вы хотите изменить?");
- action.Subject = Console.ReadLine();
- Console.WriteLine(@"Что вы хотите сделать? +\-");
- action.Operation = Console.ReadLine();
- Console.WriteLine(@"Колличество поинтов которые следует {0}", action.Operation == "+" ? "прибавить" : "отнять");
- action.OperandPoints = ReadInt();
- return action;
- }
- private static int ReadInt()
- {
- int intData = 0;
- string data;
- do
- {
- data = Console.ReadLine();
- } while (!int.TryParse(data, out intData));
- return intData;
- }
- private static void WriteGreetings()
- {
- Console.WriteLine("Добро пожаловать в меню выбора создания персонажа!");
- Console.WriteLine("У вас есть 25 очков, которые вы можете распределить по умениям");
- Console.WriteLine("Нажмите любую клавишу чтобы продолжить...");
- Console.ReadKey();
- }
- }
- //----------------------------------------------------------------------------------------------------------------------------------------
- public class Hero
- {
- public Dictionary<string, Stat> Stats { get; set; } =
- new Dictionary<string, Stat>
- {
- { "сила", new Stat() },
- { "ловкость", new Stat() },
- { "интелект", new Stat() }
- };
- public int FreePoints { get; set; } = 25;
- public int Age { get; set; }
- public override string ToString()
- {
- return $"Возраст - {Age}\nСила - [{Stats["сила"]}]\nЛовкость - [{Stats["ловкость"]}]\nИнтелект - [{Stats["интелект"]}]";
- }
- }
- //----------------------------------------------------------------------------------------------------------------------------------------
- public class Stat
- {
- public int Value { get; set; }
- public override string ToString()
- {
- return Value.ToString().PadLeft(Value, '#').PadRight(10, '_');
- }
- }
- //----------------------------------------------------------------------------------------------------------------------------------------
- public class UserAction
- {
- public string Subject { get; internal set; }
- public string Operation { get; internal set; }
- public int OperandPoints { get; internal set; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement