Garloon

4.8

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