Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _03._MemoryGame
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<string> memoryGame = Console.ReadLine()
- .Split()
- .ToList();
- int numberOfMoves = 0;
- string command = Console.ReadLine();
- while (command != "end")
- {
- string[] currentCommand = command.Split();
- int index1 = int.Parse(currentCommand[0]);
- int index2 = int.Parse(currentCommand[1]);
- numberOfMoves += 1;
- if ((index1 == index2)
- || (index1 < 0 || memoryGame.Count - 1 < index1)
- || (index2 < 0 || memoryGame.Count - 1 < index2))
- {
- Console.WriteLine("Invalid input! Adding additional elements to the board");
- memoryGame.Insert(memoryGame.Count / 2, $"-{numberOfMoves}a");
- memoryGame.Insert(memoryGame.Count / 2, $"-{numberOfMoves}a");
- command = Console.ReadLine();
- continue;
- }
- if (memoryGame[index1] == memoryGame[index2])
- {
- string print = memoryGame[index1];
- memoryGame.Remove(print);
- memoryGame.Remove(print);
- Console.WriteLine($"Congrats! You have found matching elements - {print}!");
- }
- else if (memoryGame[index1] != memoryGame[index2])
- {
- Console.WriteLine("Try again!");
- }
- command = Console.ReadLine();
- if (memoryGame.Count == 0)
- {
- Console.WriteLine($"You have won in {numberOfMoves} turns!");
- return;
- }
- }
- Console.WriteLine("Sorry you lose :(");
- Console.WriteLine(string.Join(' ', memoryGame));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment