Advertisement
loleckek228

4.8

Sep 15th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.23 KB | None | 0 0
  1. using System;
  2.  
  3. namespace IMJunior
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int age = 0, strength = 0, agility = 0, intelligence = 0, points = 25;
  10.             string strengthVisual = string.Empty, agilityVisual = string.Empty, intelligenceVisual = string.Empty;
  11.  
  12.             Console.WriteLine("Добро пожаловать в меню выбора создания персонажа!");
  13.             Console.WriteLine("У вас есть 25 очков, которые вы можете распределить по умениям");
  14.             Console.WriteLine("Нажмите любую клавишу чтобы продолжить...");
  15.             Console.ReadKey();
  16.  
  17.             while (points > 0)
  18.             {
  19.                 Console.Clear();
  20.                 strengthVisual = string.Empty;
  21.                 agilityVisual = string.Empty;
  22.                 intelligenceVisual = string.Empty;
  23.                 Pad(ref strengthVisual, strength);
  24.                 Pad(ref agilityVisual, agility);
  25.                 Pad(ref intelligenceVisual, intelligence);
  26.                 Console.WriteLine("Поинтов - {0}", points);
  27.                 PrintSubjects(age, strengthVisual, agilityVisual, intelligenceVisual);
  28.  
  29.                 Console.WriteLine("Какую характеристику вы хотите изменить?");
  30.                 string subject = Console.ReadLine();
  31.  
  32.                 Console.WriteLine(@"Что вы хотите сделать? +\-");
  33.                 string operation = Console.ReadLine();
  34.  
  35.                 Console.WriteLine(@"Колличество поинтов которые следует {0}", operation == "+" ? "прибавить" : "отнять");
  36.  
  37.                 string operandPointsRaw = string.Empty;
  38.                 int operandPoints = 0;
  39.                 TryParse(operandPointsRaw, out operandPoints);
  40.  
  41.                 switch (subject.ToLower())
  42.                 {
  43.                     case "сила":
  44.  
  45.                         Operation(ref strength, ref operandPoints, operation);                  
  46.                         CountSubject(ref strength, ref operandPoints, operation);
  47.                         CountPoints(ref points, ref operandPoints, operation);
  48.                         break;
  49.  
  50.                     case "ловкость":
  51.  
  52.                         Operation(ref agility, ref operandPoints, operation);
  53.                         CountSubject(ref agility, ref operandPoints, operation);
  54.                         CountPoints(ref points, ref operandPoints, operation);
  55.                         break;
  56.  
  57.                     case "интелект":
  58.  
  59.                         Operation(ref intelligence, ref operandPoints, operation);
  60.                         CountSubject(ref intelligence, ref operandPoints, operation);
  61.                         CountPoints(ref points, ref operandPoints, operation);
  62.                         break;
  63.                 }
  64.             }
  65.  
  66.             Console.WriteLine("Вы распределили все очки. Введите возраст персонажа:");
  67.  
  68.             string ageRaw = string.Empty;
  69.             TryParse(ageRaw, out age);
  70.  
  71.             Console.Clear();
  72.             strengthVisual = string.Empty;
  73.             agilityVisual = string.Empty;
  74.             intelligenceVisual = string.Empty;
  75.             Pad(ref strengthVisual, strength);
  76.             Pad(ref agilityVisual, agility);
  77.             Pad(ref intelligenceVisual, intelligence);
  78.             PrintSubjects(age, strengthVisual, agilityVisual, intelligenceVisual);
  79.         }
  80.  
  81.         static void PrintSubjects(int age, string strengthVisual, string agilityVisual, string intelligenceVisual)
  82.         {
  83.             Console.WriteLine("Возраст - {0}\nСила - [{1}]\nЛовкость - [{2}]\nИнтелект - [{3}]",
  84.                 age, strengthVisual, agilityVisual, intelligenceVisual);
  85.         }
  86.  
  87.         static void TryParse(string value, out int number)
  88.         {
  89.             do
  90.             {
  91.                 value = Console.ReadLine();
  92.             } while (!int.TryParse(value, out number));
  93.         }
  94.  
  95.         static void Operation (ref int subject, ref int operandPoints, string operation)
  96.         {
  97.             if (operation == "+")
  98.             {
  99.                 int overhead = operandPoints - (10 - subject);
  100.                 overhead = overhead < 0 ? 0 : overhead;
  101.                 operandPoints -= overhead;
  102.             }
  103.             else
  104.             {
  105.                 int overhead = subject - operandPoints;
  106.                 overhead = overhead < 0 ? overhead : 0;
  107.                 operandPoints += overhead;
  108.             }
  109.         }
  110.  
  111.         static void CountPoints(ref int points, ref int operandPoints, string operation)
  112.         {
  113.             points = operation == "+" ? points - operandPoints : points + operandPoints;
  114.         }
  115.  
  116.         static void CountSubject(ref int subject, ref int operandPoints, string operation)
  117.         {
  118.             subject = operation == "+" ? subject + operandPoints : subject - operandPoints;
  119.         }
  120.  
  121.         static void Pad(ref string subjectVisual, int subject)
  122.         {
  123.             subjectVisual = subjectVisual.PadLeft(subject, '#').PadRight(10, '_');
  124.         }
  125.     }
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement