Пример #1
0
        public void SetRecursiveSurroundingHitCount(CoOrdinate coOrd)
        {
//            var gridCell = Grid[coOrd.XCord, coOrd.YCord];
//            if (gridCell.IsBomb)
//            {
//                return;
//            }
            var hitCount = GetSurroundingHitCount(coOrd);

            SetAsDug(coOrd, hitCount);
            if (hitCount > 0)
            {
                return;
            }

            foreach (var surround in AllVaidBorderCoordinates(coOrd))
            {
                var surroundGridCell = Grid[surround.XCord, surround.YCord];

                if (surroundGridCell.IsBomb == false && surroundGridCell.hasBeenDug == false && surroundGridCell.ProximityCount == 0)
                {
                    var subHitcount = GetSurroundingHitCount(surroundGridCell.CoOrd);
                    SetAsDug(surroundGridCell.CoOrd, subHitcount);
                    if (subHitcount == 0)
                    {
                        SetRecursiveSurroundingHitCount(surroundGridCell.CoOrd);
                    }
                }
            }
        }
Пример #2
0
        private void SetAsDug(CoOrdinate coOrd, int hitCount)
        {
            var cell = Grid[coOrd.XCord, coOrd.YCord];

            cell.hasBeenDug     = true;
            cell.ProximityCount = SetProximityCount(hitCount);
        }
Пример #3
0
        public bool DigAndCheckIsBomb(CoOrdinate coOrd)
        {
            var gridCell = Grid[coOrd.XCord, coOrd.YCord];

            if (gridCell.IsBomb)
            {
                gridCell.IsExplosion = true;
                return(true);
            }
            SetRecursiveSurroundingHitCount(coOrd);
            return(false);
        }
Пример #4
0
        public int GetSurroundingHitCount(CoOrdinate coOrd)
        {
            var hitCount = 0;

            foreach (var surround in AllVaidBorderCoordinates(coOrd))
            {
                if (Grid[surround.XCord, surround.YCord].IsBomb == true)
                {
                    hitCount++;
                }
            }
            return(hitCount);
        }
Пример #5
0
 private IEnumerable <CoOrdinate> AllVaidBorderCoordinates(CoOrdinate coOrd)
 {
     for (var xCord = coOrd.XCord - 1; xCord <= coOrd.XCord + 1; xCord++)
     {
         for (var yCord = coOrd.YCord - 1; yCord <= coOrd.YCord + 1; yCord++)
         {
             var surroundCoord = new CoOrdinate(xCord, yCord);
             if (IsCurrentPosition(coOrd, surroundCoord))
             {
                 continue;
             }
             if (IsInsideGrid(surroundCoord) == false)
             {
                 continue;
             }
             yield return(surroundCoord);
         }
     }
 }
Пример #6
0
 private bool IsInsideGrid(CoOrdinate coOrd)
 {
     return(coOrd.XCord >= 0 && coOrd.XCord < Width && coOrd.YCord >= 0 && coOrd.YCord < Height);
 }
Пример #7
0
 private static bool IsCurrentPosition(CoOrdinate currCoOrd, CoOrdinate targetCoOrd)
 {
     return(currCoOrd.XCord == targetCoOrd.XCord && currCoOrd.YCord == targetCoOrd.YCord);
 }