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 ConsoleApp41
- {
- class Program
- {
- static void Main(string[] args)
- {
- bool isTrading = true;
- string inputCommand;
- string inputGoodName;
- int inputGoodQuantity;
- Inventory playerInventory = new Inventory(new Goods[1] { new Goods("Чеснок", 2) }, new Player());
- Inventory traderInventory = new Inventory(new Goods[2] { new Goods("Картошка", 5), new Goods("Морковка", 3) }, new Trader());
- playerInventory.ShowAll();
- Console.WriteLine("Добрый день, хотите ли посмотреть товар?");
- while (isTrading)
- {
- inputCommand = Console.ReadLine();
- StartTrade(inputCommand, traderInventory, ref isTrading);
- Console.WriteLine("Какой товар и в каком количестве вы бы хотели купить?");
- inputGoodName = Console.ReadLine();
- inputGoodQuantity = Convert.ToInt32(Console.ReadLine());
- Trading(inputGoodName, inputGoodQuantity, traderInventory, playerInventory);
- }
- traderInventory.ShowAll();
- Console.ReadKey();
- }
- static void Trading(string inputGoodName, int inputGoodQuantity, Inventory traderInventory, Inventory playerInventory)
- {
- Goods inputGood = new Goods(inputGoodName, inputGoodQuantity);
- for (int i = 0; i < traderInventory.Goods.Length; i++)
- {
- if (inputGood.Name == traderInventory.Goods[i].Name && inputGood.Quantity <= traderInventory.Goods[i].Quantity)
- {
- Console.WriteLine("товар найден");
- Inventory tempInventory = new Inventory(new Goods[1] { new Goods(inputGoodName, inputGoodQuantity) }, new Player());
- traderInventory.Goods[i].Quantity = traderInventory.Goods[i].Quantity - inputGoodQuantity;
- }
- }
- }
- static void StartTrade(string inputCommand, Inventory traderInventory, ref bool isTrading)
- {
- if (inputCommand == "Да")
- {
- traderInventory.ShowAll();
- }
- else if (inputCommand == "Нет")
- {
- Console.WriteLine("До свидания, приходите ещё");
- isTrading = false;
- }
- else
- {
- Console.WriteLine("Повторите ввод");
- }
- }
- }
- class Trader
- {
- }
- class Player
- {
- }
- class Goods
- {
- public string Name;
- public int Quantity;
- public Goods(string name, int quantity)
- {
- Name = name;
- Quantity = quantity;
- }
- public void Show()
- {
- Console.WriteLine($"{Name} в количестве {Quantity} штук");
- }
- }
- class Inventory
- {
- public Goods[] Goods;
- public Player PlayerOwmer;
- public Trader TraderOwner;
- public Inventory(Goods[] goods, Player playerOwmer)
- {
- Goods = goods;
- PlayerOwmer = playerOwmer;
- }
- public Inventory(Goods[] goods, Trader traderOwmer)
- {
- Goods = goods;
- TraderOwner = traderOwmer;
- }
- public void ShowAll()
- {
- for (int i = 0; i < Goods.Length; i++)
- {
- Goods[i].Show();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement