/// <summary>
        /// Создаёт минное со стандартной фабрикой клеток и генератором мин со случайным порядком.
        /// </summary>
        /// <returns></returns>
        public static IMinefield CreateDefaultMinefield()
        {
            IMinefield   field    = new Minefield(DefaultCellFactory, DefaultMinePositionsGenerator);
            SettingsItem settings = new SettingsItem();

            settings.Height    = 10;
            settings.Width     = 10;
            settings.MineCount = 10;
            field.SetGameSettings(settings);
            field.Fill();
            return(field);
        }
Ejemplo n.º 2
0
        public void FillFromSettingsObject()
        {
            SettingsItem            settings  = CreateCustomSettings(10, 11, 9);
            IMinePositionsGenerator generator = new RandomMinePositionGenerator();
            IMinefield field = new Minefield(new CellFactory(), generator);

            field.SetGameSettings(settings);
            field.Fill();

            Assert.AreEqual(10, field.Height);
            Assert.AreEqual(11, field.Width);
            Assert.AreEqual(9, field.MinesCount);
        }
Ejemplo n.º 3
0
        private static IMinefield SetMineToPosition(int x, int y)
        {
            int        mineCount = 1;
            List <int> coords    = new List <int> {
                x, y
            };
            IMinePositionsGenerator generator = new CollectionMinePositionGenerator(coords);
            IMinefield   field    = new Minefield(new CellFactory(), generator);
            SettingsItem settings = CreateCustomSettings(10, 10, mineCount);

            field.SetGameSettings(settings);
            field.Fill();
            return(field);
        }
Ejemplo n.º 4
0
        public void SetMineToCornerAndCheckNearby()
        {
            IEnumerable <int> coords = new List <int>()
            {
                1, 1,
                1, 0,
                0, 1
            };

            IMinePositionsGenerator generator = new CollectionMinePositionGenerator(coords);
            IMinefield   field    = new Minefield(new CellFactory(), generator);
            SettingsItem settings = CreateCustomSettings(10, 10, 3);

            field.SetGameSettings(settings);
            field.Fill();

            int minesCount = field.GetCellMineNearbyCount(field.Cells[0][0]);

            Assert.AreEqual(3, minesCount);
        }
Ejemplo n.º 5
0
        public void MineExplosion_AllCellsAreShowedUp()
        {
            List <int> coords = new List <int> {
                0, 0, 0, 1, 5, 5
            };
            IMinePositionsGenerator generator = new CollectionMinePositionGenerator(coords);
            IMinefield   field    = new Minefield(new CellFactory(), generator);
            SettingsItem settings = CreateCustomSettings(10, 10, 3);

            field.SetGameSettings(settings);
            field.Fill();
            ICell cell = field.GetCellByCoords(1, 0);

            cell.Open();

            ICell cellFlagged = field.GetCellByCoords(0, 1);

            cellFlagged.SetFlag();

            ICell cellWrongFlag = field.GetCellByCoords(2, 2);

            cellWrongFlag.SetFlag();

            // Boom!
            cell = field.GetCellByCoords(5, 5);
            cell.Open();

            // Assertation

            ICell cellOpened = field.GetCellByCoords(9, 9);

            Assert.AreEqual(CellState.Opened, cellOpened.State);

            ICell cellNoFinded = field.GetCellByCoords(0, 0);

            Assert.AreEqual(CellState.NoFindedMine, cellNoFinded.State);

            Assert.AreEqual(CellState.Flagged, cellFlagged.State);

            Assert.AreEqual(CellState.WrongFlag, cellWrongFlag.State);
        }