Advertisement
loleckek228

5.4

Sep 19th, 2019
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.88 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace _5._4
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             Player player = new Player(8000);
  11.             Seller.GoodsList.Add(new Goods("Fanta", 65));
  12.             Seller.GoodsList.Add(new Goods("Стол", 2000));
  13.             Seller.GoodsList.Add(new Goods("Пиво", 70));
  14.             Seller.GoodsList.Add(new Goods("Кружка", 500));
  15.             Seller.GoodsList.Add(new Goods("Диван", 5000));
  16.  
  17.             while (true)
  18.             {
  19.                 Console.Clear();
  20.                 Console.WriteLine("Магазин\n");
  21.                 Console.WriteLine(">Список товаров" +
  22.                     "\n>Купить товар" +
  23.                     "\n>Мои товары");
  24.  
  25.                 string action = Console.ReadLine();
  26.                 Console.Clear();
  27.  
  28.                 if (Seller.GoodsList.Count > 0)
  29.                 {
  30.                     Seller.IsInStock = true;
  31.                 }
  32.                 else
  33.                 {
  34.                     Seller.IsInStock = false;
  35.                 }
  36.  
  37.                 switch (action.ToLower())
  38.                 {
  39.                     case "список товаров":
  40.  
  41.                         Seller.ShowGoods();
  42.                         isDown();
  43.                         break;
  44.  
  45.                     case "купить товар":
  46.  
  47.                         Seller.ShowGoods();
  48.  
  49.                         if (Seller.IsInStock)
  50.                         {
  51.                             Seller.SellGoods(player);
  52.                         }
  53.                         isDown();
  54.                         break;
  55.  
  56.                     case "мои товары":
  57.  
  58.                         player.showPlayerGoods();
  59.                         isDown();
  60.                         break;
  61.                 }
  62.             }
  63.         }
  64.  
  65.         public static void isDown()
  66.         {
  67.             Console.WriteLine("\nНажмите любую кнопку...");
  68.             Console.ReadKey();
  69.         }
  70.     }
  71.  
  72.     class Player
  73.     {
  74.         public  List<Goods> PlayerGoods = new List<Goods>();
  75.         public  int Money;
  76.  
  77.         public Player(int money)
  78.         {
  79.             Money = money;
  80.         }
  81.  
  82.         public void showPlayerGoods()
  83.         {
  84.             if (PlayerGoods.Count > 0)
  85.             {
  86.                 Console.WriteLine("У вас на счету - " + Money);
  87.                 for (int i = 0; i < PlayerGoods.Count; i++)
  88.                 {
  89.                     Console.WriteLine(i + 1 + ") " + "Название товара - " + PlayerGoods[i].GoodsName +
  90.                         "\nЦена товара - " + PlayerGoods[i].GoodsCost);
  91.                     Console.WriteLine();
  92.                 }
  93.             }
  94.             else
  95.             {
  96.                 Console.WriteLine("У вас нет товаров");
  97.             }
  98.         }
  99.     }
  100.  
  101.     static class Seller
  102.     {
  103.         public static List<Goods> GoodsList = new List<Goods>();
  104.         public static bool IsInStock;
  105.  
  106.  
  107.         public static void SellGoods(Player player)
  108.         {
  109.             Console.WriteLine("Введите номер товара, который хотите приобрести");
  110.             int goodsNumber = Convert.ToInt32(Console.ReadLine()) - 1;
  111.  
  112.             if (goodsNumber >= 0 && goodsNumber < GoodsList.Count)
  113.             {
  114.                 if (player.Money >= GoodsList[goodsNumber].GoodsCost)
  115.                 {
  116.  
  117.                     player.Money -= GoodsList[goodsNumber].GoodsCost;
  118.                     player.PlayerGoods.Add(GoodsList[goodsNumber]);
  119.                     GoodsList.RemoveAt(goodsNumber);
  120.                     Console.WriteLine("Товар успешно приобретен");
  121.                 }
  122.                 else
  123.                 {
  124.                     Console.WriteLine("У вас недостаточно денег");
  125.                 }
  126.             }
  127.             else
  128.             {
  129.                 Console.WriteLine("Ошибка ввода");
  130.             }
  131.         }
  132.  
  133.         public static void ShowGoods()
  134.         {
  135.             if (IsInStock)
  136.             {
  137.                 for (int i = 0; i < GoodsList.Count; i++)
  138.                 {
  139.                     Console.WriteLine(i + 1 + ") " + "Название товара - " + GoodsList[i].GoodsName +
  140.                         "\nЦена товара - " + GoodsList[i].GoodsCost);
  141.                     Console.WriteLine();
  142.                 }
  143.             }
  144.             else
  145.             {
  146.                 Console.WriteLine("В магазине нет товаров");
  147.             }
  148.         }
  149.     }
  150.  
  151.     class Goods
  152.     {
  153.         public string GoodsName;
  154.         public int GoodsCost;
  155.  
  156.         public Goods(string goodsName, int goodsCost)
  157.         {
  158.             GoodsName = goodsName;
  159.             GoodsCost = goodsCost;
  160.         }
  161.     }
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement