Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel.Design;
- using System.Globalization;
- using System.IO;
- namespace ConsoleApp3
- {
- class Program
- {
- static void Main(string[] args)
- {
- Buyer buyer = new Buyer();
- Seller seller = new Seller();
- while (true)
- {
- Console.ForegroundColor = ConsoleColor.Green;
- Console.SetCursorPosition(45, 0);
- Console.WriteLine(buyer.ShowCash());
- Console.SetCursorPosition(0, 0);
- Console.ForegroundColor = ConsoleColor.White;
- Console.WriteLine("<<<Добро пожаловать в магазин>>>");
- Console.WriteLine("Нажмите 1 что бы посмотреть список доступных для покупки товаров");
- Console.WriteLine("Нажмите 2 что бы купить товар");
- Console.WriteLine("Нажмите 3 что бы посмотреть инвентарь");
- Console.WriteLine("Нажмите 4 что бы узнать кассу в магазине\n");
- Console.Write("Выберите функцию: ");
- switch (Convert.ToInt32(Console.ReadLine()))
- {
- case 1:
- seller.ShowProducts();
- break;
- case 2:
- Console.Write("Напишите название товара: ");
- buyer.BuyProduct( seller , Console.ReadLine());
- break;
- case 3:
- buyer.ShowInventory();
- break;
- case 4:
- seller.ShowCash();
- break;
- default:
- Console.WriteLine("Вы ввели неверную функцию, повторите попытку...");
- break;
- }
- Console.ReadLine();
- Console.Clear();
- }
- }
- }
- class Buyer
- {
- private List<string> _inventory = new List<string>();
- private int _money;
- public Buyer()
- {
- Random rnd = new Random();
- _money = rnd.Next(1000, 1500);
- }
- public int ShowCash()
- {
- return _money;
- }
- public void BuyProduct(Seller seller, string product)
- {
- if(_money >= seller.ShowPrice(product))
- {
- _money -= seller.ShowPrice(product);
- seller.GiveProduct(product);
- _inventory.Add(product);
- }
- else
- Console.WriteLine("У вас недостаточно денег");
- }
- public void ShowInventory()
- {
- foreach (var item in _inventory)
- {
- Console.WriteLine(item);
- }
- }
- }
- class Seller : Product
- {
- private int _money;
- public void ShowCash()
- {
- Console.WriteLine("Касса продуктового магазина - " + _money);
- }
- public int ShowPrice(string product)
- {
- return _products[product];
- }
- public void ShowProducts()
- {
- foreach (var product in _products)
- {
- Console.WriteLine($"{product.Key} - {product.Value}");
- }
- }
- public void GiveProduct(string product)
- {
- _money += ShowPrice(product);
- _products.Remove(product);
- }
- }
- class Product
- {
- protected Dictionary<string, int> _products = new Dictionary<string, int>()
- {
- {"Молоко", 50 },
- {"Сигареты", 200 },
- {"Энергетик", 30 }
- };
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement