Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.27 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.                 Console.WriteLine("Поинтов - {0}", points);
  21.                 WritePlayerStatus(ref strengthVisual, ref agilityVisual, ref intelligenceVisual,
  22.                                   ref age, ref strength, ref agility, ref intelligence);
  23.  
  24.                 Console.WriteLine("Какую характеристику вы хотите изменить?");
  25.                 string subject = Console.ReadLine();
  26.                 string operation;
  27.                 bool correctOperation;
  28.                 do
  29.                 {
  30.                     Console.WriteLine(@"Что вы хотите сделать? +\-");
  31.                     operation = Console.ReadLine();
  32.  
  33.                     if (operation == "+") { correctOperation = true; }
  34.                     else if (operation == "-") { correctOperation = true; }
  35.                     else { Console.WriteLine("Введена неверная операция"); correctOperation = false; }
  36.  
  37.                 } while (!correctOperation);
  38.  
  39.  
  40.                 Console.WriteLine(@"Количество поинтов которые следует {0}", operation == "+" ? "прибавить" : "отнять");
  41.  
  42.                 string operandPointsRaw;
  43.                 int operandPoints;
  44.                 do
  45.                 {
  46.                     operandPointsRaw = Console.ReadLine();
  47.                 } while (!int.TryParse(operandPointsRaw, out operandPoints));
  48.  
  49.                 switch (subject.ToLower())
  50.                 {
  51.                     case "сила":
  52.                         if (operation == "+")
  53.                         {
  54.                             operandPoints = OperandPlus(operandPoints, strength, ref points);
  55.                         }
  56.                         else if (operation == "-")
  57.                         {
  58.                             operandPoints = OperandMinus(operandPoints, strength);
  59.                         }
  60.  
  61.                         strength = FinalizePoints(strength, operation, operandPoints, ref points);
  62.                         break;
  63.                     case "ловкость":
  64.                         if (operation == "+")
  65.                         {
  66.                             operandPoints = OperandPlus(operandPoints, agility, ref points);
  67.                         }
  68.                         else
  69.                         {
  70.                             operandPoints = OperandMinus(operandPoints, agility);
  71.                         }
  72.  
  73.                         agility = FinalizePoints(agility, operation, operandPoints, ref points);
  74.                         break;
  75.                     case "интеллект":
  76.                         if (operation == "+")
  77.                         {
  78.                             operandPoints = OperandPlus(operandPoints, intelligence, ref points);
  79.                         }
  80.                         else
  81.                         {
  82.                             operandPoints = OperandMinus(operandPoints, intelligence);
  83.                         }
  84.  
  85.                         intelligence = FinalizePoints(intelligence, operation, operandPoints, ref points);
  86.                         break;
  87.                 }
  88.             }
  89.  
  90.             Console.WriteLine("Вы распределили все очки. Введите возраст персонажа:");
  91.             string ageRaw;
  92.             do
  93.             {
  94.                 ageRaw = Console.ReadLine();
  95.             } while (!int.TryParse(ageRaw, out age));
  96.  
  97.             age = Convert.ToInt32(ageRaw);
  98.  
  99.             Console.Clear();
  100.             WritePlayerStatus(ref strengthVisual, ref agilityVisual, ref intelligenceVisual,
  101.                                   ref age, ref strength, ref agility, ref intelligence);
  102.         }
  103.  
  104.         static int OperandPlus(int operandPoints, int ability, ref int points)
  105.         {
  106.             int overhead = operandPoints - (10 - ability);
  107.             overhead = overhead < 0 ? 0 : overhead;
  108.             operandPoints -= overhead;
  109.             operandPoints = operandPoints > points ? points : operandPoints;
  110.  
  111.             return operandPoints;
  112.         }
  113.  
  114.         static int OperandMinus(int operandPoints, int ability)
  115.         {
  116.             int overhead = ability - operandPoints;
  117.             overhead = overhead < 0 ? overhead : 0;
  118.             operandPoints += overhead;
  119.  
  120.             return operandPoints;
  121.         }
  122.  
  123.         static int FinalizePoints(int ability, string operation, int operandPoints, ref int points)
  124.         {
  125.             ability = operation == "+" ? ability + operandPoints : ability - operandPoints;
  126.             points = operation == "+" ? points - operandPoints : points + operandPoints;
  127.  
  128.             return ability;
  129.         }
  130.  
  131.         static void WritePlayerStatus(ref string strengthVisual, ref string agilityVisual, ref string intelligenceVisual,
  132.                                       ref int age, ref int strength, ref int agility, ref int intelligence)
  133.         {
  134.             strengthVisual = string.Empty;
  135.             agilityVisual = string.Empty;
  136.             intelligenceVisual = string.Empty;
  137.             strengthVisual = strengthVisual.PadLeft(strength, '#').PadRight(10, '_');
  138.             agilityVisual = agilityVisual.PadLeft(agility, '#').PadRight(10, '_');
  139.             intelligenceVisual = intelligenceVisual.PadLeft(intelligence, '#').PadRight(10, '_');
  140.             Console.WriteLine("Возраст - {0}\nСила - [{1}]\nЛовкость - [{2}]\nИнтеллект - [{3}]", age, strengthVisual, agilityVisual, intelligenceVisual);
  141.         }
  142.     }
  143. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement