Advertisement
LessTergy

Untitled

Feb 19th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.03 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace IMJunior
  5. {
  6.     internal class Program
  7.     {
  8.         private static Player _player;
  9.         private const int MaxPoints = 25;
  10.  
  11.         private static void Main(string[] args)
  12.         {
  13.             InitPlayer();
  14.             ShowIntroScreen();
  15.  
  16.             InitAbilityPoints();
  17.             InitPlayerAge();
  18.            
  19.             Console.Clear();
  20.             ShowPlayerInfo();
  21.         }
  22.  
  23.         private static void InitPlayer()
  24.         {
  25.             _player = new Player { abilityPoints = MaxPoints, age = 0 };
  26.  
  27.             _player.abilities.Add(new Ability("Сила", 0));
  28.             _player.abilities.Add(new Ability("Ловкость", 0));
  29.             _player.abilities.Add(new Ability("Интеллект", 0));
  30.         }
  31.  
  32.         private static void InitAbilityPoints()
  33.         {
  34.             while (_player.IsHaveAbilityPoints())
  35.             {
  36.                 Console.Clear();
  37.  
  38.                 ShowPoints();
  39.                 ShowPlayerInfo();
  40.  
  41.                 Console.WriteLine("Какую характеристику вы хотите изменить?");
  42.                 string abilityNameInput = Console.ReadLine();
  43.                 abilityNameInput = abilityNameInput.ToLower();
  44.  
  45.                 int pointsDelta = GetPointsDeltaInput();
  46.  
  47.                 foreach (var ability in _player.abilities)
  48.                 {
  49.                     string abilityName = ability.Name.ToLower();
  50.                     if (!abilityName.Equals(abilityNameInput))
  51.                     {
  52.                         continue;
  53.                     }
  54.  
  55.                     int oldPointsValue = ability.Points;
  56.                     ability.IncPoints(pointsDelta);
  57.  
  58.                     int diff = oldPointsValue - ability.Points;
  59.                     _player.abilityPoints += diff;
  60.                 }
  61.             }
  62.         }
  63.  
  64.         private static int GetPointsDeltaInput()
  65.         {
  66.             Console.WriteLine(@"Что вы хотите сделать? +\-");
  67.             string operation = Console.ReadLine();
  68.             Console.WriteLine(@"Колличество поинтов которые следует {0}", operation.Equals("+") ? "прибавить" : "отнять");
  69.  
  70.             int delta = GetIntInput();
  71.             delta *= operation.Equals("+") ? 1 : -1;
  72.             return delta;
  73.         }
  74.  
  75.         private static void InitPlayerAge()
  76.         {
  77.             Console.WriteLine("Вы распределили все очки. Введите возраст персонажа:");
  78.             _player.age = GetIntInput();
  79.         }
  80.  
  81.         private static int GetIntInput()
  82.         {
  83.             string valueRaw;
  84.             int value;
  85.  
  86.             do
  87.             {
  88.                 valueRaw = Console.ReadLine();
  89.             }
  90.             while (!int.TryParse(valueRaw, out value));
  91.  
  92.             return value;
  93.         }
  94.  
  95.         private static void ShowIntroScreen()
  96.         {
  97.             Console.WriteLine("Добро пожаловать в меню выбора создания персонажа!");
  98.             Console.WriteLine("У вас есть " + MaxPoints + " очков, которые вы можете распределить по умениям");
  99.             Console.WriteLine("Нажмите любую клавишу чтобы продолжить...");
  100.             Console.ReadKey();
  101.         }
  102.  
  103.         private static void ShowPoints()
  104.         {
  105.             Console.WriteLine("Поинтов - {0}", _player.abilityPoints);
  106.         }
  107.  
  108.         private static void ShowPlayerInfo()
  109.         {
  110.             //Age
  111.             Console.WriteLine("Возраст - {0}", _player.age);
  112.  
  113.             //Abilities
  114.             foreach (var playerAbility in _player.abilities)
  115.             {
  116.                 Console.WriteLine(playerAbility.GetInfoLine());
  117.             }
  118.         }
  119.  
  120.         //Classes
  121.         public class Player
  122.         {
  123.             public int abilityPoints;
  124.             public int age;
  125.  
  126.             public List<Ability> abilities = new List<Ability>();
  127.  
  128.             public bool IsHaveAbilityPoints()
  129.             {
  130.                 return abilityPoints > 0;
  131.             }
  132.         }
  133.  
  134.         public class Ability
  135.         {
  136.             public string Name { get; }
  137.             public int Points { get; private set; }
  138.  
  139.             public const int MaxPoints = 10;
  140.  
  141.             public Ability(string name, int points)
  142.             {
  143.                 this.Name = name;
  144.                 this.Points = points;
  145.             }
  146.  
  147.             public string GetInfoLine()
  148.             {
  149.                 string pointsInfo = string.Empty;
  150.                 pointsInfo = pointsInfo.PadLeft(Points, '#').PadRight(MaxPoints, '_');
  151.                 return Name + " - " + pointsInfo;
  152.             }
  153.  
  154.             public void IncPoints(int value)
  155.             {
  156.                 Points += value;
  157.                 //Clamp
  158.                 Points = Math.Min(MaxPoints, Points);
  159.                 Points = Math.Max(0, Points);
  160.             }
  161.         }
  162.     }
  163. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement