Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using ConsoleApp1;
- using System;
- using System.Buffers;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Linq;
- using System.Net.Http.Headers;
- using System.Runtime.CompilerServices;
- using System.Runtime.InteropServices.ComTypes;
- using System.Security.Cryptography.X509Certificates;
- namespace ConsoleApp1
- {
- class Program
- {
- static void Main(string[] args)
- {
- Seller seller = new Seller();
- Buyer buyer = new Buyer();
- bool exit = true;
- while (exit)
- {
- Console.ForegroundColor = ConsoleColor.Green;
- Console.SetCursorPosition(45, 0);
- buyer.ShowCashBuyer();
- Console.SetCursorPosition(0, 0);
- Console.ForegroundColor = ConsoleColor.White;
- Console.WriteLine("<<<Добро пожаловать в магазин>>>");
- Console.WriteLine("Нажмите 1 что бы посмотреть список доступных для покупки товаров");
- Console.WriteLine("Нажмите 2 что бы купить товар");
- Console.WriteLine("Нажмите 3 что бы посмотреть инвентарь\n");
- Console.Write("Выберите функцию: ");
- switch (Convert.ToInt32(Console.ReadLine()))
- {
- case 1:
- seller.ShowProducts();
- break;
- case 2:
- Console.WriteLine("Напишите название товара");
- buyer.BuyProduct(Console.ReadLine());
- break;
- case 3:
- buyer.ShowInventory();
- break;
- default:
- Console.WriteLine("Вы ввели неверную функцию, повторите попытку...");
- break;
- }
- Console.ReadLine();
- Console.Clear();
- }
- }
- }
- class Buyer
- {
- static Random rnd = new Random();
- private int _money = rnd.Next(500, 1500);
- List<string> _inventory = new List<string>();
- Seller seller = new Seller();
- public void ShowInventory()
- {
- foreach (var item in _inventory)
- {
- Console.WriteLine(item);
- }
- }
- public void ShowCashBuyer()
- {
- Console.WriteLine("Бюджет покупателя = " + _money);
- }
- public void BuyProduct(string product)
- {
- if (_money >= seller.ShowPrice(product))
- {
- _money -= seller.ShowPrice(product);
- seller.SellProduct(product);
- _inventory.Add(product);
- }
- else
- {
- Console.WriteLine("У вас недостаточно денег.");
- }
- }
- }
- class Seller
- {
- private Product products = new Product();
- private int _cash;
- public void ShowCash()
- {
- Console.WriteLine($"Касса у магазина - {_cash}");
- }
- public void SellProduct(string product)
- {
- _cash += ShowPrice(product);
- GiveProduct(product);
- }
- private class Product
- {
- public Dictionary<string, int> _products = new Dictionary<string, int>
- {
- {"Молоко", 100},
- {"Сахар", 60},
- {"Снежок", 80},
- {"Конфеты", 50},
- {"Сникерс", 30},
- {"Mallboro", 175},
- {"Газета", 10},
- {"Соль", 30},
- {"Майонез", 90}
- };
- }
- public void ShowProducts()
- {
- foreach (var item in products._products)
- {
- Console.WriteLine($"{item.Key} - {item.Value}");
- }
- }
- public int ShowPrice(string product)
- {
- return products._products[product];
- }
- public void GiveProduct(string product)
- {
- products._products.Remove(product);
- }
- }
- }
Add Comment
Please, Sign In to add comment