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 NewYearParty_02
- {
- class Program
- {
- static void Main(string[] args)
- {
- Santa santa = new Santa(new List<Gift>());
- Boy boy = new Boy(new List<Gift>());
- bool isOpen = true;
- string userInput;
- while (isOpen)
- {
- Console.WriteLine($"Новогодний детский утренник\n");
- Console.WriteLine($"1 - Заглянуть в мешок Санты\n2 - Клянчить подарок\n3 - Посмотреть в свой карман\n4 - Уйти с ёлки");
- Console.Write($"\nВведите номер команды: ");
- userInput = Console.ReadLine();
- switch (userInput)
- {
- case "1":
- Console.WriteLine($"\nпока Санта отвернулся Вы украдкой заглянули в его мешок...");
- Console.WriteLine($"надпись на отвороте мешка гласила: спонсор подарков настольная карточная игра \"Манчкин\"\n");
- santa.ShowInfo();
- break;
- case "2":
- Console.WriteLine($"Вы промямлили стишок у ёлки про Деда Мороза, какую-то бороду из ваты и горбатого человека,");
- Console.Write($"после чего с надеждой смотрите на подарок номер: ");
- if (santa.GiveGift(out Gift present))
- {
- boy.TakeGift(present);
- }
- else
- {
- Console.WriteLine($"ошибка номера подарка");
- }
- break;
- case "3":
- boy.ShowInfo();
- break;
- case "4":
- isOpen = false;
- break;
- default:
- Console.WriteLine($"НЕверная команда");
- break;
- }
- Console.WriteLine($"\nлюбую для продолжения ...");
- Console.ReadKey();
- Console.Clear();
- }
- }
- }
- class Actor
- {
- protected List<Gift> Gifts;
- public Actor(List<Gift> gifts)
- {
- Gifts = gifts;
- }
- public void ShowInfo()
- {
- for (int i = 0; i < Gifts.Count; i++)
- {
- Console.Write($"{i + 1}. ");
- Gifts[i].ShowDescription();
- }
- if (Gifts.Count == 0)
- {
- Console.WriteLine($"\n здесь пусто");
- }
- }
- public bool TryGetGiftIndex(out int index)
- {
- int number;
- index = 0;
- if (TryReadInt(out number))
- {
- index = number;
- }
- bool isLegalRange = (index > 0 && index <= Gifts.Count);
- return isLegalRange;
- }
- private bool TryReadInt(out int number)
- {
- bool result = int.TryParse(Console.ReadLine(), out number);
- return result;
- }
- }
- class Santa : Actor
- {
- public Santa(List<Gift> gifts) : base(gifts)
- {
- gifts.Add(new Gift("Шлем бесстрашия"));
- gifts.Add(new Gift("Башмаки могучего Пенделя"));
- gifts.Add(new Gift("Читерский кубик"));
- gifts.Add(new Gift("Боевая стремянка"));
- gifts.Add(new Gift("Зелье ротовой вони"));
- gifts.Add(new Gift("Зелье идиотской храбрости"));
- gifts.Add(new Gift("Меч песни и пляски"));
- gifts.Add(new Gift("Рапира такнечестности"));
- gifts.Add(new Gift("Паленые доспехи"));
- gifts.Add(new Gift("Паленые доспехи"));
- }
- public bool GiveGift(out Gift present)
- {
- bool result = false;
- present = null;
- if (TryGetGiftIndex(out int index))
- {
- present = Gifts[index - 1];
- result = true;
- Gifts.RemoveAt(index - 1);
- }
- return result;
- }
- }
- class Boy : Actor
- {
- public Boy(List<Gift> gifts) : base(gifts)
- {
- gifts.Add(new Gift("Чистый носовой платочек"));
- gifts.Add(new Gift("Жук в коробочке"));
- }
- public void TakeGift(Gift present)
- {
- Gifts.Add(new Gift(present.Name));
- Console.WriteLine($"Вы получили подарок - {present.Name}");
- }
- }
- class Gift
- {
- public string Name { get; private set; }
- public Gift(string name)
- {
- Name = name;
- }
- public void ShowDescription()
- {
- Console.WriteLine($"{Name}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement