public void TestConstructorWhenPassNullShouldThrowException()
        {
            var rng = new RandomNumberGenerator();
            SmallPlayfield playfield = null;

            var memento = new Memento(playfield);
        }
        public void TestMediumPlayfieldGetCellMethodShouldProperlyReturnSymbol()
        {
            var playfield = new MediumPlayfield();
            var rng = new RandomNumberGenerator();
            playfield.FillPlayfield(rng);

            playfield.SetCell(0, 0, "@");
            string actual = playfield.GetCell(0, 0);
            string expected = "@";

            Assert.AreEqual(expected, actual, "At position 0,0 the symbol should be @");
        }
        public void TestMediumPlayfieldSetCellMethodUsingIPositionShouldProperlySetSymbolInGridAndGetMethodShouldReturnIt()
        {
            var playfield = new MediumPlayfield();
            IPosition position = new Position(0, 0);

            var rng = new RandomNumberGenerator();
            playfield.FillPlayfield(rng);

            playfield.SetCell(position.Row, position.Col, "@");
            string actual = playfield.GetCell(position.Row, position.Col);
            string expected = "@";

            Assert.AreEqual(expected, actual, "At position 0,0 the symbol should be @");
        }
        public void TestConstructorShouldCopyCorrectPlayfield()
        {
            var rng = new RandomNumberGenerator();
            var playfield = new SmallPlayfield();
            playfield.FillPlayfield(rng);

            var memento = new Memento(playfield);
            bool areEqual = true;

            for (int row = 0; row < playfield.Size; row++)
            {
                for (int col = 0; col < playfield.Size; col++)
                {
                    if (playfield.GetCell(row, col) != memento.Grid[row, col])
                    {
                        areEqual = false;
                    }
                }
            }

            Assert.IsTrue(areEqual);
        }
        private static void ProceedCommand(string command)
        {
            var randomNumberGenerator = new RandomNumberGenerator();
            var reader = new ConsoleReader();
            var renderer = new ConsoleRenderer();
            var factory = new PlayfieldFactory();

            switch (command)
            {
                case "New game":
                    Playfield playfield;
                    Console.Clear();
                    Console.WriteLine(ChooseSizeMessage);

                    string size = Console.ReadLine();

                    playfield = factory.CreatePlayfield(size);
                    playfield.FillPlayfield(randomNumberGenerator);

                    if (playfield == null)
                    {
                        Console.Clear();
                        Console.WriteLine(ChooseSizeMessage);
                        ProceedCommand("New game");
                    }
                    else
                    {
                        var game = new GameEngine(reader, renderer, playfield);
                        game.Run();
                    }

                    break;
                case "Load game":
                    try
                    {
                        var fileSerializer = new FileSerializer();
                        var memento = fileSerializer.DeserializeObject(GameLocation);
                        playfield = factory.CreatePlayfield(ConvertNumberToString(memento.Grid.GetLength(0)));
                        playfield.RestoreMemento(memento);

                        File.Delete(GameLocation);

                        var game = new GameEngine(reader, renderer, playfield);
                        game.Run();
                    }
                    catch (Exception ex)
                    {
                        Console.Clear();
                        Console.WriteLine(ex.Message);
                        Console.WriteLine(WelcomeMessage);
                        ProceedCommand(Console.ReadLine());
                    }

                    break;
                case "Exit":
                    Environment.Exit(0);
                    break;
                default:
                    Console.Clear();
                    Console.WriteLine(WelcomeMessage);
                    ProceedCommand(Console.ReadLine());
                    break;
            }
        }