Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- class Program
- {
- static void Main(string[] args)
- {
- const string ShowInventorySellerCommand = "1";
- const string BuyProductCommand = "2";
- const string ShowInventoryPlayerCommand = "3";
- const string IsExitCommand = "4";
- string userInput;
- bool isWorking = true;
- Seller seller = new Seller();
- Player player = new Player();
- while(isWorking)
- {
- Console.Clear();
- Console.WriteLine("Вы зашли в лавку торговца.");
- Console.WriteLine($"{ShowInventorySellerCommand})Посмотреть товар.\n{BuyProductCommand})Купить товар.\n" +
- $"{ShowInventoryPlayerCommand})Посмотреть свой инвентарь.\n{IsExitCommand})Покинуть лавку.");
- userInput = Console.ReadLine();
- Console.Clear();
- switch (userInput)
- {
- case ShowInventorySellerCommand:
- seller.ShowInventory();
- break;
- case BuyProductCommand:
- player.BuyProduct(seller.SellProduct());
- break;
- case ShowInventoryPlayerCommand:
- player.ShowInventory();
- break;
- case IsExitCommand:
- isWorking = false;
- break;
- }
- }
- }
- }
- class Human
- {
- protected List<Product> Products = new List<Product>();
- public void ShowInventory()
- {
- foreach (Product product in Products)
- {
- Console.WriteLine($"Название:{product.Name}|Цена:{product.Price}|Урон:{product.Damage}|Прочность:{product.Endurance}");
- }
- Console.ReadKey();
- }
- }
- class Seller : Human
- {
- private Product _product;
- public Seller()
- {
- Products.AddRange(new List<Product>() { new Product("WoodKnife", 5, 25, 100), new Product("IronKnife", 15, 50, 150), new Product("GoldKnife", 30, 100, 25) });
- }
- public Product SellProduct()
- {
- Product product = null;
- if (Products.Count <= 0)
- {
- Console.WriteLine("У торговца закончился товар.");
- Console.ReadKey();
- }
- else
- {
- Console.WriteLine("Что бы вы хотели купить?");
- string userInput = Console.ReadLine();
- if (IsAvailable(userInput))
- {
- foreach (var item in Products)
- {
- if (item.Name == userInput)
- {
- product = item;
- break;
- }
- }
- }
- }
- Products.Remove(product);
- return product;
- }
- public bool IsAvailable(string productName)
- {
- foreach (var product in Products)
- {
- if (product.Name == productName)
- {
- return true;
- break;
- }
- }
- Console.WriteLine("Такого товара нет в наличии!");
- Console.ReadKey();
- return false;
- }
- }
- class Player : Human
- {
- public void BuyProduct(Product product)
- {
- if (product != null)
- {
- Products.Add(product);
- }
- }
- }
- class Product
- {
- public Product (string name,int price, int damage, int endurance)
- {
- Name = name;
- Price = price;
- Damage = damage;
- Endurance = endurance;
- }
- public string Name { get; private set; }
- public int Price { get; private set; }
- public int Damage { get; private set; }
- public int Endurance { get; private set; }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement