Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace _5._4
- {
- class Program
- {
- static void Main(string[] args)
- {
- Player player = new Player(8000);
- Seller.GoodsList.Add(new Goods("Fanta", 65));
- Seller.GoodsList.Add(new Goods("Стол", 2000));
- Seller.GoodsList.Add(new Goods("Пиво", 70));
- Seller.GoodsList.Add(new Goods("Кружка", 500));
- Seller.GoodsList.Add(new Goods("Диван", 5000));
- while (true)
- {
- Console.Clear();
- Console.WriteLine("Магазин\n");
- Console.WriteLine(">Список товаров" +
- "\n>Купить товар" +
- "\n>Мои товары");
- string action = Console.ReadLine();
- Console.Clear();
- if (Seller.GoodsList.Count > 0)
- {
- Seller.IsInStock = true;
- }
- else
- {
- Seller.IsInStock = false;
- }
- switch (action.ToLower())
- {
- case "список товаров":
- Seller.ShowGoods();
- isDown();
- break;
- case "купить товар":
- Seller.ShowGoods();
- if (Seller.IsInStock)
- {
- Seller.SellGoods(player);
- }
- isDown();
- break;
- case "мои товары":
- player.showPlayerGoods();
- isDown();
- break;
- }
- }
- }
- public static void isDown()
- {
- Console.WriteLine("\nНажмите любую кнопку...");
- Console.ReadKey();
- }
- }
- class Player
- {
- public List<Goods> PlayerGoods = new List<Goods>();
- public int Money;
- public Player(int money)
- {
- Money = money;
- }
- public void showPlayerGoods()
- {
- if (PlayerGoods.Count > 0)
- {
- Console.WriteLine("У вас на счету - " + Money);
- for (int i = 0; i < PlayerGoods.Count; i++)
- {
- Console.WriteLine(i + 1 + ") " + "Название товара - " + PlayerGoods[i].GoodsName +
- "\nЦена товара - " + PlayerGoods[i].GoodsCost);
- Console.WriteLine();
- }
- }
- else
- {
- Console.WriteLine("У вас нет товаров");
- }
- }
- }
- static class Seller
- {
- public static List<Goods> GoodsList = new List<Goods>();
- public static bool IsInStock;
- public static void SellGoods(Player player)
- {
- Console.WriteLine("Введите номер товара, который хотите приобрести");
- int goodsNumber = Convert.ToInt32(Console.ReadLine()) - 1;
- if (goodsNumber >= 0 && goodsNumber < GoodsList.Count)
- {
- if (player.Money >= GoodsList[goodsNumber].GoodsCost)
- {
- player.Money -= GoodsList[goodsNumber].GoodsCost;
- player.PlayerGoods.Add(GoodsList[goodsNumber]);
- GoodsList.RemoveAt(goodsNumber);
- Console.WriteLine("Товар успешно приобретен");
- }
- else
- {
- Console.WriteLine("У вас недостаточно денег");
- }
- }
- else
- {
- Console.WriteLine("Ошибка ввода");
- }
- }
- public static void ShowGoods()
- {
- if (IsInStock)
- {
- for (int i = 0; i < GoodsList.Count; i++)
- {
- Console.WriteLine(i + 1 + ") " + "Название товара - " + GoodsList[i].GoodsName +
- "\nЦена товара - " + GoodsList[i].GoodsCost);
- Console.WriteLine();
- }
- }
- else
- {
- Console.WriteLine("В магазине нет товаров");
- }
- }
- }
- class Goods
- {
- public string GoodsName;
- public int GoodsCost;
- public Goods(string goodsName, int goodsCost)
- {
- GoodsName = goodsName;
- GoodsCost = goodsCost;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement