Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace IMJunior
- {
- internal class Program
- {
- private static Player _player;
- private const int MaxPoints = 25;
- private static void Main(string[] args)
- {
- InitPlayer();
- ShowIntroScreen();
- InitAbilityPoints();
- InitPlayerAge();
- Console.Clear();
- ShowPlayerInfo();
- }
- private static void InitPlayer()
- {
- _player = new Player { abilityPoints = MaxPoints, age = 0 };
- _player.abilities.Add(new Ability("Сила", 0));
- _player.abilities.Add(new Ability("Ловкость", 0));
- _player.abilities.Add(new Ability("Интеллект", 0));
- }
- private static void InitAbilityPoints()
- {
- while (_player.IsHaveAbilityPoints())
- {
- Console.Clear();
- ShowPoints();
- ShowPlayerInfo();
- Console.WriteLine("Какую характеристику вы хотите изменить?");
- string abilityNameInput = Console.ReadLine();
- abilityNameInput = abilityNameInput.ToLower();
- int pointsDelta = GetPointsDeltaInput();
- foreach (var ability in _player.abilities)
- {
- string abilityName = ability.Name.ToLower();
- if (!abilityName.Equals(abilityNameInput))
- {
- continue;
- }
- int oldPointsValue = ability.Points;
- ability.IncPoints(pointsDelta);
- int diff = oldPointsValue - ability.Points;
- _player.abilityPoints += diff;
- }
- }
- }
- private static int GetPointsDeltaInput()
- {
- Console.WriteLine(@"Что вы хотите сделать? +\-");
- string operation = Console.ReadLine();
- Console.WriteLine(@"Колличество поинтов которые следует {0}", operation.Equals("+") ? "прибавить" : "отнять");
- int delta = GetIntInput();
- delta *= operation.Equals("+") ? 1 : -1;
- return delta;
- }
- private static void InitPlayerAge()
- {
- Console.WriteLine("Вы распределили все очки. Введите возраст персонажа:");
- _player.age = GetIntInput();
- }
- private static int GetIntInput()
- {
- string valueRaw;
- int value;
- do
- {
- valueRaw = Console.ReadLine();
- }
- while (!int.TryParse(valueRaw, out value));
- return value;
- }
- private static void ShowIntroScreen()
- {
- Console.WriteLine("Добро пожаловать в меню выбора создания персонажа!");
- Console.WriteLine("У вас есть " + MaxPoints + " очков, которые вы можете распределить по умениям");
- Console.WriteLine("Нажмите любую клавишу чтобы продолжить...");
- Console.ReadKey();
- }
- private static void ShowPoints()
- {
- Console.WriteLine("Поинтов - {0}", _player.abilityPoints);
- }
- private static void ShowPlayerInfo()
- {
- //Age
- Console.WriteLine("Возраст - {0}", _player.age);
- //Abilities
- foreach (var playerAbility in _player.abilities)
- {
- Console.WriteLine(playerAbility.GetInfoLine());
- }
- }
- //Classes
- public class Player
- {
- public int abilityPoints;
- public int age;
- public List<Ability> abilities = new List<Ability>();
- public bool IsHaveAbilityPoints()
- {
- return abilityPoints > 0;
- }
- }
- public class Ability
- {
- public string Name { get; }
- public int Points { get; private set; }
- public const int MaxPoints = 10;
- public Ability(string name, int points)
- {
- this.Name = name;
- this.Points = points;
- }
- public string GetInfoLine()
- {
- string pointsInfo = string.Empty;
- pointsInfo = pointsInfo.PadLeft(Points, '#').PadRight(MaxPoints, '_');
- return Name + " - " + pointsInfo;
- }
- public void IncPoints(int value)
- {
- Points += value;
- //Clamp
- Points = Math.Min(MaxPoints, Points);
- Points = Math.Max(0, Points);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement