Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace ConsoleApp1
- {
- class Program
- {
- static void Main(string[] args)
- {
- string userInput;
- Seller seller = new Seller();
- Player player = new Player();
- while (true)
- {
- Console.ReadKey();
- Console.Clear();
- seller.ShowProducts();
- Console.Write("\nВведите название продукта: ");
- userInput = Console.ReadLine();
- seller.SellProduct(userInput);
- player.ShowInventory();
- }
- }
- class Player
- {
- private List<Product> _playerInventory = new List<Product>();
- public void AddProduct(string item)
- {
- _playerInventory.Add(new Product(item));
- }
- public void ShowInventory()
- {
- for (int i = 0; i < _playerInventory.Count; i++)
- {
- _playerInventory[i].ShowProduct();
- }
- }
- }
- class Seller
- {
- Player player = new Player();
- private List<string> _products = new List<string>() { "Руда", "Альманах", "Руна телепортации", "Глаз Инноса" };
- public void ShowProducts()
- {
- for (int i = 0; i < _products.Count; i++)
- {
- Console.WriteLine($"{i+1}.{_products[i]}");
- }
- }
- public void SellProduct(string userInput)
- {
- bool isFind = false;
- foreach (string item in _products)
- {
- if (item == userInput)
- {
- player.AddProduct(item);
- isFind = true;
- break;
- }
- }
- if (isFind == false)
- {
- Console.WriteLine("Продукт в списке не найден");
- }
- }
- }
- class Product
- {
- private string _name;
- public Product(string name)
- {
- _name = name;
- }
- public void ShowProduct()
- {
- Console.WriteLine(_name);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment