Anonim_999

WTF

Jul 12th, 2021 (edited)
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.51 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. namespace ConsoleApp1
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string userInput;
  10.             Seller seller = new Seller();
  11.             Player player = new Player();
  12.  
  13.             while (true)
  14.             {
  15.                 Console.ReadKey();
  16.                 Console.Clear();
  17.                 seller.ShowProducts();
  18.                 Console.Write("\nВведите название продукта: ");
  19.                 userInput = Console.ReadLine();
  20.                 seller.SellProduct(userInput);
  21.                 player.ShowInventory();
  22.             }
  23.         }
  24.  
  25.         class Player
  26.         {
  27.             private List<Product> _playerInventory = new List<Product>();
  28.  
  29.             public void AddProduct(string item)
  30.             {
  31.                 _playerInventory.Add(new Product(item));
  32.             }
  33.  
  34.             public void ShowInventory()
  35.             {
  36.                 for (int i = 0; i < _playerInventory.Count; i++)
  37.                 {
  38.                     _playerInventory[i].ShowProduct();
  39.                 }
  40.             }
  41.         }
  42.  
  43.         class Seller
  44.         {
  45.             Player player = new Player();
  46.             private List<string> _products = new List<string>() { "Руда", "Альманах", "Руна телепортации", "Глаз Инноса" };
  47.            
  48.             public void ShowProducts()
  49.             {
  50.                 for (int i = 0; i < _products.Count; i++)
  51.                 {
  52.                     Console.WriteLine($"{i+1}.{_products[i]}");
  53.                 }
  54.             }
  55.  
  56.             public void SellProduct(string userInput)
  57.             {
  58.                 bool isFind = false;
  59.                 foreach (string item in _products)
  60.                 {
  61.                     if (item == userInput)
  62.                     {
  63.                         player.AddProduct(item);
  64.                         isFind = true;
  65.                         break;
  66.                     }
  67.                 }
  68.                 if (isFind == false)
  69.                 {
  70.                     Console.WriteLine("Продукт в списке не найден");
  71.                 }
  72.             }
  73.         }
  74.  
  75.         class Product
  76.         {
  77.             private string _name;
  78.  
  79.             public Product(string name)
  80.             {
  81.                 _name = name;
  82.             }
  83.  
  84.             public void ShowProduct()
  85.             {
  86.                 Console.WriteLine(_name);
  87.             }
  88.         }
  89.     }
  90. }
Add Comment
Please, Sign In to add comment