radidim

P03.Inventory_03 (C# Shell App Paste)

May 30th, 2020
861
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.25 KB | None | 0 0
  1. //Disclaimer: The creator of 'C# Shell (C# Offline Compiler)' is in no way responsible for the code posted by any user.
  2. using System;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Collections.Generic;
  6.  
  7. namespace CSharp_Shell
  8. {
  9.  
  10.     public static class Program
  11.     {
  12.        
  13.         public static void Main()
  14.         {
  15.            var journal = Console.ReadLine().Split(new []{',',' '},StringSplitOptions.RemoveEmptyEntries).ToArray();
  16.            var exists = false;
  17.            var index = -1;
  18.            
  19.            
  20.            while(true)
  21.            {
  22.             var input = Console.ReadLine();
  23.            
  24.             if(input == "exit")
  25.             {
  26.                 break;
  27.             }
  28.            
  29.             var commands = input.Split(" - ");
  30.             string command = commands[0];
  31.            
  32.             if(command == "Collect")
  33.             {
  34.                 string item = commands[1];
  35.                 if(Exists(exists, journal, item) == false)
  36.                 {
  37.                     var newJournal = new string[journal.Length + 1];
  38.                     for(int i=0;i<journal.Length;i++)
  39.                     {
  40.                         newJournal[i]=journal[i];
  41.                     }
  42.                
  43.                     newJournal[newJournal.Length-1] = item;
  44.                     journal = newJournal;
  45.                 }
  46.             }
  47.            
  48.             if(command == "Drop")
  49.             {
  50.                 string item = commands[1];
  51.                 if (Exists(exists, journal, item))
  52.                 {
  53.                     journal = RemoveAt(journal, Index(exists, journal, item, index));
  54.                     //string[] newJournal = new string[journal.Length - 1];
  55.                     //if( Index(exists,journal, item, index) > 0 )
  56.                     //{
  57.                     //  for(int  i = 0;i<Index(exists, journal, item, index);i++)
  58.                     //  {
  59.                     //      newJournal[i] = journal[i];
  60.                     //  }
  61.                     //}
  62.                        
  63.                     //if( Index(exists, journal, item, index) < journal.Length - 1 )
  64.                     //{
  65.                     //  for(int i=Index(exists, journal, item, index);i<journal.Length-Index(exists, journal,item, index)-1;i++)
  66.                     //  {
  67.                     //      newJournal[Index(exists, journal, item, index)] = journal[Index(exists, journal, item, index)+1];
  68.                     //  }
  69.                     //}
  70.                     // 
  71.                     //  journal = newJournal;
  72.                 }
  73.             }
  74.            
  75.             if(command == "Combine Items")
  76.             {
  77.                 var items = commands[1].Split(':');
  78.                 var oldItem = items[0];
  79.                 var newItem = items[1];
  80.                 if(Exists(exists, journal, oldItem))
  81.                 {
  82.                     var newJournal = new string[journal.Length+1];
  83.                    
  84.                 }
  85.             }
  86.            
  87.             if(command=="Renew")
  88.             {
  89.                 string item = commands[1];
  90.            
  91.                
  92.             }
  93.            
  94.            }
  95.            for(int  i=0;i<journal.Length-1;i++)
  96.            {
  97.             Console.Write(journal[i] + ", ");
  98.            
  99.            }
  100.             Console.Write(journal[journal.Length-1]);
  101.             Console.WriteLine(" ");
  102.         }
  103.        
  104.         public static bool Exists(bool exists, string[] journal, string item)
  105.         {
  106.             for(int i=0;i<journal.Length;i++)
  107.                 {
  108.                     if(item == journal[i])
  109.                     {
  110.                         exists = true;
  111.                     }
  112.                    
  113.                 }
  114.                 return exists;
  115.         }
  116.         public static int Index(bool exists, string[] journal, string item, int index)
  117.         {
  118.             for(int i=0;i<journal.Length;i++)
  119.                 {
  120.                     if(item == journal[i])
  121.                     {
  122.                         exists = true;
  123.                         index = i;
  124.                     }
  125.                    
  126.                 }
  127.                 return index;
  128.         }
  129.         //public static T[] RemoveAt<T>(this T[] journal, int index)
  130.         //{
  131.         //  T[] dest = new T[journal.Length - 1];
  132.         //  if( index > 0 )
  133.         //  Array.Copy(journal, 0, dest, 0, index);
  134.         //  if( index < journal.Length - 1 )
  135.         //  Array.Copy(journal, index + 1, dest, index, journal.Length - index - 1);
  136.         //  return dest;
  137.         //}
  138.         public static string[] RemoveAt(string[] journal, int index)
  139.         {
  140.             string[] dest = new string[journal.Length - 1];
  141.             if( index > 0 )
  142.             Array.Copy(journal, 0, dest, 0, index);
  143.             if( index < journal.Length - 1 )
  144.             Array.Copy(journal, index + 1, dest, index, journal.Length - index - 1);
  145.             return dest;
  146.         }
  147.     }
  148. }
Advertisement
Add Comment
Please, Sign In to add comment