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();
- seller.Addroduct();
- Player player = new Player();
- bool isContinue = true;
- while (isContinue)
- {
- Console.ReadKey();
- Console.Clear();
- Console.WriteLine("Меню: \n1.Посмотреть товар\n2.Купить товар\n3.Открыть инвентарь\n4.Выход");
- userInput = Console.ReadLine();
- switch (userInput)
- {
- case "1":
- seller.ShowProducts();
- break;
- case "2":
- Console.Write("\nВведите название товара: ");
- userInput = Console.ReadLine();
- seller.SellProduct(userInput, player);
- break;
- case "3":
- player.ShowInventory();
- break;
- case "4":
- isContinue = false;
- break;
- default:
- Console.WriteLine("Нет такой команды");
- break;
- }
- }
- }
- class Player
- {
- private List<Product> _inventory = new List<Product>();
- public void AddProduct(string item)
- {
- _inventory.Add(new Product(item));
- }
- public void ShowInventory()
- {
- Console.WriteLine("Инвентарь:");
- for (int i = 0; i < _inventory.Count; i++)
- {
- _inventory[i].ShowProduct();
- }
- }
- }
- class Seller
- {
- private List<string> _products = new List<string>();
- public void Addroduct()
- {
- _products.AddRange(new string[] { "Руда","Альманах", "Руна телепортации", "Глаз Инноса"});
- }
- public void ShowProducts()
- {
- if (_products.Count >= 1)
- {
- Console.WriteLine("Товары:");
- for (int i = 0; i < _products.Count; i++)
- {
- Console.WriteLine($"{i + 1}.{_products[i]}");
- }
- }
- else
- {
- Console.WriteLine("Товаров нет в наличии");
- }
- }
- public void SellProduct(string userInput, Player player)
- {
- bool isFind = false;
- foreach (string product in _products)
- {
- if (product == userInput)
- {
- player.AddProduct(product);
- _products.Remove(product);
- Console.WriteLine($"Товар {product} - куплен");
- 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);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment