예제 #1
0
        public void TestCreatePlayfieldWithSomeDifferentAsParameterShouldCreateNull()
        {
            string            typeOfPlayfield = "wrong";
            IPlayfieldFactory factory         = new PlayfieldFactory();
            var playfield = factory.CreatePlayfield(typeOfPlayfield);

            Assert.IsNull(playfield, "CreatePlayfield with wrong argument should create null ");
        }
예제 #2
0
        public void TestCreatePlayfieldWithLargeAsParameterShouldCreateNewLargePlayfieldObject()
        {
            string            typeOfPlayfield = "large";
            IPlayfieldFactory factory         = new PlayfieldFactory();
            var playfield = factory.CreatePlayfield(typeOfPlayfield);
            var actual    = playfield.GetType() == typeof(LargePlayfield);

            Assert.IsTrue(actual, "CreatePlayfield with large as argument should create new LargePlayfield Object");
        }
예제 #3
0
        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;
            }
        }