Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace ЦветочныйМагазин
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- Session session = new Session();
- session.Make();
- }
- }
- class Session
- {
- private Seller _seller;
- private Player _player;
- public Session()
- {
- _seller = new Seller();
- _player = new Player();
- }
- public void Make()
- {
- string showWalletMenu = "1";
- string shoppingMenu = "2";
- string showPurchasesMenu = "3";
- string finishGameMenu = "4";
- bool isOpen = true;
- string userInput;
- while (isOpen)
- {
- Console.WriteLine("Игра \"Цветочный магазин\"\n\nМеню:");
- Console.WriteLine($"{showWalletMenu} - посмотреть баланс кошелька");
- Console.WriteLine($"{shoppingMenu} - пойти за покупками");
- Console.WriteLine($"{showPurchasesMenu} - посмотреть свои покупки");
- Console.WriteLine($"{finishGameMenu} - закончить игру");
- Console.Write("\nНаберите нужную цифру меню: ");
- userInput = Console.ReadLine();
- if (userInput == showWalletMenu)
- _player.ShowBalance();
- else if (userInput == shoppingMenu)
- GoBuying();
- else if (userInput == showPurchasesMenu)
- _player.ShowFlowers();
- else if (userInput == finishGameMenu)
- isOpen = false;
- else
- ShowErrorMessage();
- if (userInput != shoppingMenu && userInput != finishGameMenu)
- ShowOfferToContinue();
- Console.Clear();
- }
- }
- private void GoBuying()
- {
- string showProductsMenu = "1";
- string tradingMenu = "2";
- string goOutMenu = "3";
- bool isBuying = true;
- string userInput;
- Console.Clear();
- while (isBuying)
- {
- Console.WriteLine("Мы рады видеть вас в нашем цветочном магазине! Уверены, вы останетесь довольны!\n");
- Console.WriteLine($"{showProductsMenu} - покажите товары!");
- Console.WriteLine($"{tradingMenu} - хочу купить!");
- Console.WriteLine($"{goOutMenu} - выйти из магазина!");
- Console.Write("\nНаберите нужную цифру меню: ");
- userInput = Console.ReadLine();
- if (userInput == showProductsMenu)
- _seller.ShowFlowers();
- else if (userInput == tradingMenu)
- Trade();
- else if (userInput == goOutMenu)
- isBuying = false;
- else
- ShowErrorMessage();
- if (userInput != goOutMenu)
- ShowOfferToContinue();
- Console.Clear();
- }
- }
- private void Trade()
- {
- Product chosenFlower = _seller.GetProduct();
- if (_seller.IsFlowerExist(chosenFlower))
- {
- if (_player.IsEnoughMoneyToBuy(chosenFlower))
- {
- Console.WriteLine($"\nВы выбрали замечательный цветок - {chosenFlower.Name}\nС вас {chosenFlower.Price} руб.");
- _seller.SellFlower(chosenFlower);
- _player.BuyFlower(chosenFlower);
- }
- else
- {
- Console.WriteLine("\nУ вас недостаточно денег!");
- }
- }
- else
- {
- Console.WriteLine("\nИзвините, эти цветы закончились! Приходите завтра!");
- }
- }
- private void ShowOfferToContinue()
- {
- Console.WriteLine("\nДля продолжения нажмите любую клавишу.");
- Console.ReadKey();
- }
- private void ShowErrorMessage()
- {
- Console.WriteLine("\nКажется, вы ввели что-то не то.");
- }
- }
- class Seller
- {
- private List<Product> _flowers;
- private Random _random = new Random();
- public Seller()
- {
- _flowers = new List<Product>();
- FillShop();
- }
- private void FillShop()
- {
- _flowers.Add(new Product(FlowerType.Роза, GetRandomPrice(FlowerType.Роза)));
- _flowers.Add(new Product(FlowerType.Хризантема, GetRandomPrice(FlowerType.Хризантема)));
- _flowers.Add(new Product(FlowerType.Пион, GetRandomPrice(FlowerType.Пион)));
- _flowers.Add(new Product(FlowerType.Лилия, GetRandomPrice(FlowerType.Лилия)));
- _flowers.Add(new Product(FlowerType.Тюльпан, GetRandomPrice(FlowerType.Тюльпан)));
- _flowers.Add(new Product(FlowerType.Колокольчик, GetRandomPrice(FlowerType.Колокольчик)));
- _flowers.Add(new Product(FlowerType.Ромашка, GetRandomPrice(FlowerType.Ромашка)));
- }
- public void ShowFlowers()
- {
- int orderNumber = 1;
- Console.ForegroundColor = ConsoleColor.DarkGreen;
- Console.WriteLine("\nО, у нас чудные цветы! Выбирайте любые!");
- Console.ResetColor();
- foreach (Product flower in _flowers)
- {
- Console.WriteLine($"{orderNumber}. {flower.Name} - цена за штуку: {flower.Price} руб. Всего: {flower.Amount} шт.");
- orderNumber++;
- }
- }
- public void SellFlower(Product chosenFlower)
- {
- ChangeAmount(chosenFlower);
- }
- public bool IsFlowerExist(Product flower)
- {
- return flower.Amount != 0;
- }
- public Product GetProduct()
- {
- int index;
- ShowFlowers();
- Console.Write("\nКакой цветок хотите? Напишите цифру: ");
- while (int.TryParse(Console.ReadLine(), out index) == false || index < 1 || index > _flowers.Count)
- {
- Console.WriteLine("Вы ввели что-то не то, попробуйте еще раз!");
- }
- return _flowers[index - 1];
- }
- private void ChangeAmount(Product flower)
- {
- //item.DecreaseCount();
- }
- private int GetRandomAmount()
- {
- int minAmount = 0;
- int maxAmount = 6;
- return _random.Next(minAmount, maxAmount);
- }
- private int GetRandomPrice(FlowerType flowerName)
- {
- Dictionary<FlowerType, RandomTuple> pricesByType = new();
- pricesByType.Add(FlowerType.Роза, new RandomTuple(500, 1000));
- if (pricesByType.ContainsKey(flowerName))
- {
- int minPrice = pricesByType[flowerName].Min;
- int maxPrice = pricesByType[flowerName].Max;
- return _random.Next(minPrice, maxPrice);
- }
- return 0;
- }
- }
- class RandomTuple
- {
- public RandomTuple(int min, int max)
- {
- Min = min;
- Max = max;
- }
- public int Min { get; }
- public int Max { get; }
- }
- class Randomizer
- {
- public static Random rand = new Random();
- public static int GenerateInt(int min, int max)
- {
- return rand.Next();
- }
- }
- class Player
- {
- private List<Product> _bag;
- private Random _random = new Random();
- private int _money;
- public Player()
- {
- _money = SetMoneyAmount();
- _bag = new List<Product>();
- }
- public void ShowBalance()
- {
- Console.WriteLine($"\nУ вас на счету: {_money} руб.");
- }
- public void ShowFlowers()
- {
- int orderNumber = 1;
- Console.WriteLine("В сумке:");
- foreach (Product flower in _bag)
- {
- Console.WriteLine($"{orderNumber}. {flower.Name}. Всего: {flower.Amount} шт.");
- orderNumber++;
- }
- }
- public void BuyFlower(Product chosenFlower)
- {
- _money -= chosenFlower.Price;
- if (_bag.Count == 0)
- {
- AddNewFlower(chosenFlower);
- }
- else
- {
- int flowersCount = _bag.Count;
- int foundFlowers = 0;
- for (int i = 0; i < flowersCount; i++)
- {
- if (_bag[i].Name == chosenFlower.Name)
- {
- _bag[i].Amount++;
- foundFlowers = 1;
- }
- }
- if (foundFlowers == 0)
- {
- AddNewFlower(chosenFlower);
- }
- }
- }
- public bool IsEnoughMoneyToBuy(Product flower)
- {
- return _money - flower.Price > 0;
- }
- private void AddNewFlower(Product chosenFlower)
- {
- _bag.Add(chosenFlower);
- }
- private int SetMoneyAmount()
- {
- int minMoneyAmount = 1000;
- int maxMoneyAmount = 7001;
- return _random.Next(minMoneyAmount, maxMoneyAmount);
- }
- }
- class Product
- {
- public Product(FlowerType name, int price)
- {
- Name = name;
- Price = price;
- }
- public Product()
- {
- }
- public FlowerType Name { get; private set; }
- public int Price { get; private set; }
- }
- class Cell
- {
- public Cell(Product product, int count)
- {
- Product = product;
- Count = count;
- }
- public Product Product { get; private set; }
- public int Count { get; private set; }
- public void Decrease(int amount)
- {
- Count -= amount;
- }
- //public int Count => _products.Count;
- //public void Add(int amount)
- //{
- // for (int i = 0; i < amount; i++)
- // {
- // //_products.Add(new Product());
- // }
- //}
- //public void Remove(int amount)
- //{
- // for (int i = 0; i < amount; i++)
- // {
- // _products.RemoveAt(_products.Count - i);
- // }
- //}
- }
- enum FlowerType
- {
- Роза,
- Хризантема,
- Пион,
- Ромашка,
- Тюльпан,
- Лилия,
- Колокольчик
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement