Ejemplo n.º 1
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.º 2
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.º 3
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);
        }