Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- namespace MemoryGame
- {
- class Program
- {
- static void Main(string[] args)
- {
- var game = Console.ReadLine().Split(' ').ToList();
- int counter = 1;
- string command;
- while ((command = Console.ReadLine()) != "end")
- {
- var index = command.Split(' ').Select(int.Parse).OrderBy(x => x).ToArray();
- if (index[0] >= 0 && index[0] < game.Count && index[1] >= 0 && index[1] < game.Count && index[0] != index[1])
- {
- if (game[index[0]].Equals(game[index[1]]))
- {
- Console.WriteLine($"Congrats! You have found matching elements - {game[index[0]]}!");
- game.RemoveAt(index[1]);
- game.RemoveAt(index[0]);
- if (game.Count == 0)
- {
- Console.WriteLine($"You have won in {counter} turns!");
- Environment.Exit(0);
- }
- }
- else
- {
- Console.WriteLine("Try again!");
- }
- }
- else
- {
- Console.WriteLine("Invalid input! Adding additional elements to the board");
- game.InsertRange(game.Count / 2, new List<string> { $"-{counter}a", $"-{counter}a" });
- }
- counter++;
- }
- Console.WriteLine($"Sorry you lose :(\n{string.Join(" ", game)}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement