TheBulgarianWolf

Wizard Poker

Feb 3rd, 2021
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.66 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace WizardPoker
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             Console.WriteLine("Enter your cards separated with \":\" :");
  12.             string[] cards = Console.ReadLine().Split(":");
  13.             List<string> deck = new List<string>();
  14.            
  15.             string command;
  16.             while((command = Console.ReadLine()) != "Ready")
  17.             {
  18.                 string[] commandSplit = command.Split(" ");
  19.                 string comName = commandSplit[0];
  20.                 string index1 = commandSplit[1];
  21.                 string index = "";
  22.                 switch (comName)
  23.                 {
  24.                     case "Add":
  25.                         if (cards.Contains(index1))
  26.                         {
  27.                             deck.Add(index1);
  28.                         }
  29.                         else
  30.                         {
  31.                             Console.WriteLine("Card not found!");
  32.                         }
  33.                         break;
  34.                     case "Insert":
  35.                         index = commandSplit[2];
  36.                         if (cards.Contains(index1))
  37.                         {
  38.                             deck.Insert(int.Parse(index), index1);
  39.                         }
  40.                         else
  41.                         {
  42.                             Console.WriteLine("Error!");
  43.                         }
  44.                         break;
  45.                     case "Remove":
  46.                         if (cards.Contains(index1))
  47.                         {
  48.                             deck.Remove(index1);
  49.                         }
  50.                         else
  51.                         {
  52.                             Console.WriteLine("Card not found!");
  53.                         }
  54.                         break;
  55.                     case "Swap":
  56.                         index = commandSplit[2];
  57.                         string firstCard = index1;
  58.                         string secondCard = index;
  59.                         int firstIndex = deck.IndexOf(firstCard);
  60.                         int secondIndex = deck.IndexOf(secondCard);
  61.                         deck.Remove(firstCard);
  62.                         deck.Remove(secondCard);
  63.                         deck.Insert(firstIndex, secondCard);
  64.                         deck.Insert(secondIndex, firstCard);
  65.                         break;
  66.                     case "Shuffle deck":
  67.                         deck.Reverse();
  68.                         break;
  69.                 }
  70.             }
  71.             Console.WriteLine(String.Join(" ", deck));
  72.         }
  73.     }
  74. }
Add Comment
Please, Sign In to add comment