Advertisement
Guest User

4.8

a guest
Oct 23rd, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.10 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.            
  11.  
  12.             Console.WriteLine("Добро пожаловать в меню выбора создания персонажа!");
  13.             Console.WriteLine("У вас есть 25 очков, которые вы можете распределить по умениям");
  14.             Console.WriteLine("Нажмите любую клавишу чтобы продолжить...");
  15.             Console.ReadKey();
  16.  
  17.             while (points > 0)
  18.             {
  19.                 DrawStats(strength, agility, intelligence, age, points);
  20.  
  21.                 Console.WriteLine("Какую характеристику вы хотите изменить?");
  22.                 string subject = Console.ReadLine();
  23.  
  24.                 Console.WriteLine(@"Что вы хотите сделать? +\-");
  25.                 string operation = Console.ReadLine();
  26.  
  27.                 Console.WriteLine(@"Колличество поинтов которые следует {0}", operation == "+" ? "прибавить" : "отнять");
  28.  
  29.                 string operandPointsRaw = string.Empty;
  30.                 int operandPoints = 0;
  31.                 do
  32.                 {
  33.                     operandPointsRaw = Console.ReadLine();
  34.                 } while (!int.TryParse(operandPointsRaw, out operandPoints));
  35.  
  36.                 switch (subject.ToLower())
  37.                 {
  38.                         case "сила":
  39.                         strength = Calculations(strength, operation, operandPoints, ref points);
  40.                         break;
  41.                     case "ловкость":
  42.                         agility = Calculations(agility, operation, operandPoints, ref points);
  43.                         break;
  44.                     case "интелект":
  45.                         intelligence = Calculations(intelligence, operation, operandPoints, ref points);
  46.                         break;
  47.                 }
  48.             }
  49.  
  50.             Console.WriteLine("Вы распределили все очки. Введите возраст персонажа:");
  51.             string ageRaw = string.Empty;
  52.             do
  53.             {
  54.                 ageRaw = Console.ReadLine();
  55.             } while (!int.TryParse(ageRaw, out age));
  56.  
  57.             DrawStats(strength, agility, intelligence, age, points);
  58.  
  59.         }
  60.         static void DrawStats(int strength,int agility, int intelligence,int age,int points)
  61.         {
  62.             string strengthVisual = string.Empty, agilityVisual = string.Empty, intelligenceVisual = string.Empty;
  63.  
  64.             Console.Clear();
  65.             strengthVisual = string.Empty;
  66.             agilityVisual = string.Empty;
  67.             intelligenceVisual = string.Empty;
  68.             strengthVisual = strengthVisual.PadLeft(strength, '#').PadRight(10, '_');
  69.             agilityVisual = agilityVisual.PadLeft(agility, '#').PadRight(10, '_');
  70.             intelligenceVisual = intelligenceVisual.PadLeft(intelligence, '#').PadRight(10, '_');
  71.             Console.WriteLine("Поинтов - {0}", points);
  72.             Console.WriteLine("Возраст - {0}\nСила - [{1}]\nЛовкость - [{2}]\nИнтелект - [{3}]", age, strengthVisual, agilityVisual, intelligenceVisual);
  73.         }
  74.         static int Calculations(int stat, string operation, int operandPoints, ref int points)
  75.         {
  76.             if (operation == "+")
  77.             {
  78.                 int overhead = operandPoints - (10 - stat);
  79.                 overhead = overhead < 0 ? 0 : overhead;
  80.                 operandPoints -= overhead;
  81.             }
  82.             else
  83.             {
  84.                 int overhead = stat - operandPoints;
  85.                 overhead = overhead < 0 ? overhead : 0;
  86.                 operandPoints += overhead;
  87.             }
  88.             points = operation == "+" ? points - operandPoints : points + operandPoints;
  89.             return stat = operation == "+" ? stat + operandPoints : stat - operandPoints;
  90.         }
  91.     }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement