Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApp3
- {
- class Program
- {
- static void Main(string[] args)
- {
- bool isRun = true;
- Player player = new Player();
- while(isRun)
- {
- Console.WriteLine("[1] - Создать персонажа\n[2] - показать персонажа\n[3] - выход");
- Console.Write("Ввод: ");
- switch (Console.ReadLine())
- {
- case "1":
- player.SetInfo();
- break;
- case "2":
- player.ShowInfo();
- break;
- case "3":
- isRun = false;
- break;
- default:
- Console.WriteLine("Ошибка!");
- break;
- }
- }
- }
- }
- class Player
- {
- private string _name;
- private int _health;
- private int _money;
- public Player()
- {
- _name = "Без имени";
- _health = 100;
- _money = 10;
- }
- public void SetInfo()
- {
- Console.Write("Введите имя: ");
- _name = Console.ReadLine();
- Console.Write("Введите кол-во единиц здоровья: ");
- if (int.TryParse(Console.ReadLine(), out _health) == false)
- {
- Console.WriteLine("Ошибка!");
- SetDefaultInfo();
- return;
- }
- Console.Write("Введите кол-во денег: ");
- if (int.TryParse(Console.ReadLine(), out _money) == false)
- {
- Console.WriteLine("Ошибка!");
- SetDefaultInfo();
- return;
- }
- }
- public void ShowInfo()
- {
- Console.WriteLine($"Имя: {_name}\nЗдоровье: {_health}\nДеньги: {_money}");
- }
- private void SetDefaultInfo()
- {
- _name = "Без имени";
- _health = 100;
- _money = 10;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement