Advertisement
radidim

P03.Inventory (C# Shell App Paste)

May 23rd, 2020
1,636
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.85 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.            
  17.                        
  18.            while(true)
  19.            {
  20.             var input = Console.ReadLine().ToLower();
  21.            
  22.             if(input == "exit")
  23.             {
  24.                 break;
  25.             }
  26.            
  27.             var commands = input.Split(" - ");
  28.             string command = commands[0];
  29.            
  30.             if(command =="collect")
  31.             {
  32.                 string item = commands[1];
  33.            
  34.                 var newJournal = new string[journal.Length+1];
  35.                
  36.                 for(int i=0;i<journal.Length;i++)
  37.                 {
  38.                    
  39.                    
  40.                     if(item == journal[i])
  41.                     {
  42.                         break;
  43.                     }
  44.                     newJournal[i]=journal[i];
  45.                 }
  46.                 newJournal[newJournal.Length-1]=item;
  47.                 journal=newJournal;
  48.             }
  49.            
  50.             if(command == "drop")
  51.             {
  52.                 string item = commands[1];
  53.            
  54.                 var newJournal = new string[journal.Length-1];
  55.                 for(int i=0;i<journal.Length-1;i++)
  56.                 {
  57.                     if(item != journal[i])
  58.                     {
  59.                         newJournal[i]=journal[i];
  60.                     }
  61.                     else
  62.                     {
  63.                         newJournal[i]=journal[i+1];
  64.                     }
  65.                 }
  66.                
  67.                 journal=newJournal;
  68.             }
  69.            
  70.             if(command=="combine items")
  71.             {
  72.                 var items = commands[1].Split(':');
  73.                 var oldItem = items[0];
  74.                 var newItem = items[1];
  75.                 Console.WriteLine(oldItem);
  76.                 Console.WriteLine(newItem);
  77.             }
  78.            
  79.             if(command=="renew")
  80.             {
  81.                 string item = commands[1];
  82.            
  83.                
  84.             }
  85.            
  86.            }
  87.            for(int  i=0;i<journal.Length-1;i++)
  88.            {
  89.             Console.Write(journal[i] + ", ");
  90.            
  91.            }
  92.             Console.Write(journal[journal.Length-1]);
  93.             Console.WriteLine(" ");
  94.         }
  95.         public static T[] RemoveAt<T>(this T[] source, int index)
  96.         {
  97.             T[] dest = new T[source.Length - 1];
  98.             if( index > 0 )
  99.             Array.Copy(source, 0, dest, 0, index);
  100.  
  101.             if( index < source.Length - 1 )
  102.             Array.Copy(source, index + 1, dest, index, source.Length - index - 1);
  103.  
  104.             return dest;
  105.         }
  106.     }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement