Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace Shop_ver01
- {
- class Program
- {
- static void Main(string[] args)
- {
- BookHero santa = new BookHero(new List<Product>());
- BookHero badboy = new BookHero(new List<Product>());
- santa.LoadSanataBag();
- bool isOpen = true;
- string userInput;
- while (isOpen)
- {
- Console.WriteLine($"1 - Заглянуть в мешок Санты\n2 - Клянчить подарок\n3 - Посмотреть свои подарки\n4 - Уйти с ёлки");
- Console.Write($"\nВведите номер команды: ");
- userInput = Console.ReadLine();
- switch (userInput)
- {
- case "1":
- Console.WriteLine($"\nпока Санта отвернулся Вы украдкой заглянули в его мешок\n");
- santa.LookInsideBag();
- break;
- case "2":
- string name;
- int price;
- santa.GiveGift(out name, out price);
- badboy.GetGift(name, price);
- break;
- case "3":
- badboy.LookInsideBag();
- break;
- case "4":
- isOpen = false;
- break;
- default:
- Console.WriteLine($"НЕверная команда");
- break;
- }
- Console.WriteLine($"\nлюбую для продолжения ...");
- Console.ReadKey();
- Console.Clear();
- }
- }
- }
- class Product
- {
- public string Name { get; private set; }
- public int Price { get; private set; }
- public Product(string name, int price)
- {
- Name = name;
- Price = price;
- }
- public void ShowDescription()
- {
- Console.WriteLine($"{Name} - {Price} голдов");
- }
- }
- class BookHero
- {
- private List<Product> _gifts;
- public BookHero(List<Product> gifts)
- {
- _gifts = gifts;
- }
- public void LoadSanataBag()
- {
- _gifts.Add(new Product("Шлем бесстрашия", 200));
- _gifts.Add(new Product("Башмаки могучего Пенделя", 400));
- _gifts.Add(new Product("Читерский кубик", 300));
- _gifts.Add(new Product("Дырка от бублика", 500));
- _gifts.Add(new Product("Боевая стремянка", 400));
- _gifts.Add(new Product("Зелье ротовой вони", 100));
- _gifts.Add(new Product("Зелье идиотской храбрости", 100));
- _gifts.Add(new Product("Меч песни и пляски", 400));
- _gifts.Add(new Product("Рапира такнечестности", 600));
- _gifts.Add(new Product("Паленые доспехи", 400));
- }
- public void LookInsideBag()
- {
- for (int i = 0; i < _gifts.Count; i++)
- {
- Console.Write($"{i + 1}. ");
- _gifts[i].ShowDescription();
- }
- if (_gifts.Count == 0)
- {
- Console.WriteLine("\nэтот мешок пуст");
- }
- }
- public void GiveGift(out string name, out int price)
- {
- int index;
- name = "";
- price = 0;
- if (TryGetIndex(out index))
- {
- name = _gifts[index - 1].Name;
- price = _gifts[index - 1].Price;
- Console.Write($"\nСанта достал из мешка ");
- _gifts[index - 1].ShowDescription();
- Console.WriteLine($"и сказал с одесским говором - подходим деточки, покупаем подарочки");
- _gifts.RemoveAt(index - 1);
- }
- else
- {
- Console.WriteLine($"ошибка номера подарка");
- }
- }
- public void GetGift(string name, int price)
- {
- _gifts.Add(new Product(name, price));
- }
- private bool TryReadInt(out int number)
- {
- Console.Write($"Вы промямлили стишок у елки и требовательно тычите пальчиком на подарок под номером: ");
- bool result = int.TryParse(Console.ReadLine(), out number);
- return result;
- }
- private bool TryGetIndex(out int index)
- {
- int number;
- index = 0;
- if (TryReadInt(out number))
- {
- index = number;
- }
- bool isLegalRange = (index > 0 && index <= _gifts.Count);
- return isLegalRange;
- }
- }
- }
Add Comment
Please, Sign In to add comment