MrVeiran

ошибка

Jun 6th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.71 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.IO;
  7.  
  8. namespace Game
  9. {
  10.     class Program
  11.     {
  12.  
  13.         static Invertory[] Invertory = new Invertory[0];
  14.         static string[] Shop = File.ReadAllLines("Shop.txt");
  15.  
  16.  
  17.         static Shop[] ShopItems = new Shop[Shop.Length];
  18.  
  19.         static void Main(string[] args)
  20.         {
  21.             Console.WriteLine("Мы идем в магазин или идем в инвертарь?");
  22.             int change = int.Parse(Console.ReadLine());
  23.             if (change == 1)
  24.             {
  25.                 DisplayShop();
  26.             }
  27.             if (change == 2)
  28.             {
  29.                 DisplayInvertory();
  30.             }
  31.             Console.ReadKey();
  32.         }
  33.  
  34.         private static void DisplayInvertory()
  35.         {
  36.             if (Invertory.Length == 0)
  37.             {
  38.                 Console.WriteLine("У вас пустой инвертарь!");
  39.             }
  40.             else
  41.             {
  42.                 for (int i = 0; i < Invertory.Length; i++)
  43.                 {
  44.                     Console.WriteLine($"{i + 1})  {Invertory[i].Name} {Invertory[i].Type} {Invertory[i].Description} {Invertory[i].Price} {Invertory[i].Rarity}");
  45.                 }
  46.             }
  47.         }
  48.  
  49.         private static void DisplayShop()
  50.         {
  51.             int Number = 0;
  52.             int i = 0;
  53.             foreach (string Line in Shop)
  54.             {
  55.                 string[] Parts = Line.Split(';');
  56.                 ShopItems[i] = new Shop();
  57.                 ShopItems[i].Name = Parts[0];
  58.                 ShopItems[i].Type = Parts[1];
  59.                 ShopItems[i].Description = Parts[2];
  60.                 ShopItems[i].Price = int.Parse(Parts[3]);
  61.                 ShopItems[i].Rarity = Parts[4];
  62.                 i++;
  63.             }
  64.             Console.WriteLine("Добро поржаловать в наш магазин!\nВот наш ассортимент!\n");
  65.  
  66.             for (i = 0; i < Shop.Length; i++)
  67.             {
  68.                 Console.WriteLine($"{i + 1})  {ShopItems[i].Name} {ShopItems[i].Type} {ShopItems[i].Description } {ShopItems[i].Price } {ShopItems[i].Rarity}");
  69.             }
  70.  
  71.             Console.WriteLine();
  72.             Console.WriteLine("Чтобы бы вы хотели бы приобрести?");
  73.  
  74.             Number = int.Parse(Console.ReadLine()) - 1;
  75.             BuyItems(Number);
  76.             DisplayInvertory();
  77.         }
  78.  
  79.         private static void BuyItems(int Number)
  80.         {
  81.             Array.Resize(ref Invertory, Invertory.Length + 1);
  82.  
  83.             Invertory[Invertory.Length - 1] = ShopItems[Number];
  84.         }
  85.     }
  86. }
Add Comment
Please, Sign In to add comment