Advertisement
Guest User

Untitled

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