/// <summary>
        /// This method implements the factory design pattern for instantiating a playfield
        /// with the user desired dimensions.
        /// </summary>
        /// <returns></returns>
        private Playfield InitializePlayfield()
        {
            int       playfieldSize = ConsoleIOFacade.ReadPlayfieldSize();
            Playfield playfield     = null;

            bool isPlayfieldSizeIncorrect = true;

            while (isPlayfieldSizeIncorrect)
            {
                PlayfieldFactory playfiledFactory = null;

                switch (playfieldSize)
                {
                case 1:
                    playfiledFactory         = new SmallPlayfieldFactory();
                    playfield                = playfiledFactory.CreatePlayfield();
                    isPlayfieldSizeIncorrect = false;
                    break;

                case 2:
                    playfiledFactory         = new MediumPlayfieldFactory();
                    playfield                = playfiledFactory.CreatePlayfield();
                    isPlayfieldSizeIncorrect = false;
                    break;

                case 3:
                    playfiledFactory         = new LargePlayfieldFactory();
                    playfield                = playfiledFactory.CreatePlayfield();
                    isPlayfieldSizeIncorrect = false;
                    break;

                default:
                    // Extract to consoleIO
                    Console.WriteLine("You have entered incorrect field size");
                    break;
                }
            }

            return(playfield);
        }
Beispiel #2
0
        /// <summary>
        /// This method implements the factory design pattern for instantiating a playfield
        /// with the user desired dimensions.
        /// </summary>
        /// <returns></returns>
        private Playfield InitializePlayfield()
        {
            int playfieldSize = ConsoleIOFacade.ReadPlayfieldSize();
            Playfield playfield = null;

            bool isPlayfieldSizeIncorrect = true;

            while (isPlayfieldSizeIncorrect)
            {
                PlayfieldFactory playfiledFactory = null;

                switch (playfieldSize)
                {
                    case 1:
                        playfiledFactory = new SmallPlayfieldFactory();
                        playfield = playfiledFactory.CreatePlayfield();
                        isPlayfieldSizeIncorrect = false;
                        break;
                    case 2:
                        playfiledFactory = new MediumPlayfieldFactory();
                        playfield = playfiledFactory.CreatePlayfield();
                        isPlayfieldSizeIncorrect = false;
                        break;
                    case 3:
                        playfiledFactory = new LargePlayfieldFactory();
                        playfield = playfiledFactory.CreatePlayfield();
                        isPlayfieldSizeIncorrect = false;
                        break;
                    default:
                        // Extract to consoleIO
                        Console.WriteLine("You have entered incorrect field size");
                        break;
                }
            }

            return playfield;
        }