Advertisement
Guest User

Untitled

a guest
Apr 10th, 2020
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.74 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace ConsoleApp41
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             bool isTrading = true;
  13.             string inputCommand;
  14.             string inputGoodName;
  15.             int inputGoodQuantity;
  16.             Inventory playerInventory = new Inventory(new Goods[1] { new Goods("Чеснок", 2) }, new Player());
  17.             Inventory traderInventory = new Inventory(new Goods[2] { new Goods("Картошка", 5), new Goods("Морковка", 3) }, new Trader());
  18.             playerInventory.ShowAll();
  19.             Console.WriteLine("Добрый день, хотите ли посмотреть товар?");
  20.             while (isTrading)
  21.             {
  22.                 inputCommand = Console.ReadLine();
  23.                 StartTrade(inputCommand, traderInventory, ref isTrading);
  24.                 Console.WriteLine("Какой товар и в каком количестве вы бы хотели купить?");
  25.                 inputGoodName = Console.ReadLine();
  26.                 inputGoodQuantity = Convert.ToInt32(Console.ReadLine());
  27.                 Trading(inputGoodName, inputGoodQuantity, traderInventory, playerInventory);
  28.             }
  29.             traderInventory.ShowAll();
  30.             Console.ReadKey();
  31.         }
  32.  
  33.         static void Trading(string inputGoodName, int inputGoodQuantity, Inventory traderInventory, Inventory playerInventory)
  34.         {
  35.             Goods inputGood = new Goods(inputGoodName, inputGoodQuantity);
  36.             for (int i = 0; i < traderInventory.Goods.Length; i++)
  37.             {
  38.                 if (inputGood.Name == traderInventory.Goods[i].Name && inputGood.Quantity <= traderInventory.Goods[i].Quantity)
  39.                 {
  40.                     Console.WriteLine("товар найден");
  41.                     Inventory tempInventory = new Inventory(new Goods[1] { new Goods(inputGoodName, inputGoodQuantity) }, new Player());
  42.                     traderInventory.Goods[i].Quantity = traderInventory.Goods[i].Quantity - inputGoodQuantity;
  43.                 }
  44.             }
  45.         }
  46.  
  47.         static void StartTrade(string inputCommand, Inventory traderInventory, ref bool isTrading)
  48.         {
  49.             if (inputCommand == "Да")
  50.             {
  51.                 traderInventory.ShowAll();
  52.             }
  53.             else if (inputCommand == "Нет")
  54.             {
  55.                 Console.WriteLine("До свидания, приходите ещё");
  56.                 isTrading = false;
  57.             }
  58.             else
  59.             {
  60.                 Console.WriteLine("Повторите ввод");
  61.             }
  62.         }
  63.     }
  64.     class Trader
  65.     {
  66.  
  67.     }
  68.     class Player
  69.     {
  70.  
  71.     }
  72.  
  73.     class Goods
  74.     {
  75.         public string Name;
  76.         public int Quantity;
  77.         public Goods(string name, int quantity)
  78.         {
  79.             Name = name;
  80.             Quantity = quantity;
  81.         }
  82.  
  83.         public void Show()
  84.         {
  85.             Console.WriteLine($"{Name} в количестве {Quantity} штук");
  86.         }
  87.     }
  88.     class Inventory
  89.     {
  90.         public Goods[] Goods;
  91.         public Player PlayerOwmer;
  92.         public Trader TraderOwner;
  93.         public Inventory(Goods[] goods, Player playerOwmer)
  94.         {
  95.             Goods = goods;
  96.             PlayerOwmer = playerOwmer;
  97.         }
  98.         public Inventory(Goods[] goods, Trader traderOwmer)
  99.         {
  100.             Goods = goods;
  101.             TraderOwner = traderOwmer;
  102.         }
  103.  
  104.         public void ShowAll()
  105.         {
  106.             for (int i = 0; i < Goods.Length; i++)
  107.             {
  108.                 Goods[i].Show();
  109.             }
  110.         }
  111.     }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement