public void ChangeFlagTypeTest()
        {
            Cell cell = new Cell();
            var flagType = PassDifferentFlagType(cell,FlagType.None);
            Assert.IsTrue(flagType == FlagType.Mine, "Flag Type is changed to Mine when None is flagged");

            flagType = PassDifferentFlagType(cell, FlagType.Mine);
            Assert.IsTrue(flagType == FlagType.Flag, "Flag Type is changed to Flag a Mine is flagged?");

            flagType = PassDifferentFlagType(cell, FlagType.Flag);
            Assert.IsTrue(flagType == FlagType.None, "Flag Type is changed to None when flagged?");
        }
示例#2
0
 public static IEnumerable<Cell> CalculateFlippedCell(Cell cell)
 {
     var result = new List<Cell>();
     cell.FlagType = FlagType.Flip;
     //If any adjacent is a Mine, mark as flipped
     foreach (var b in cell.AllAdjacentCells.Where(x => x.IsCountable))
     {
         b.FlagType = FlagType.Flip;
     }
     result.Add(cell);
     //If any adjacent cell is not a Mine, recurse to open other adjacent cells
     foreach (var b in cell.AllAdjacentCells.Where(x => x.IsFlippable))
     {
         result.AddRange(CalculateFlippedCell(b));
     }
     return result;
 }
示例#3
0
        /*   Method to open a current cell,
         *   if Mine -> Flip
         *   if Not Mine -> Calculate adjacent cells
         * */
        public static void OpenCurrentCell(Cell cell)
        {
            if (cell.CellType == CellType.Mine)
            {
                cell.FlagType = FlagType.Flip;

            }
            else if (cell.FlagType == FlagType.None)
            {
                Board.CalculateFlippedCell(cell);
            }
        }
示例#4
0
 public static FlagType ChangeFlagType(Cell cell)
 {
     switch (cell.FlagType)
     {
         case FlagType.None:
             cell.FlagType = FlagType.Mine;
             break;
         case FlagType.Mine:
             cell.FlagType = FlagType.Flag;
             break;
         case FlagType.Flag:
             cell.FlagType = FlagType.None;
             break;
         default:
             break;
     }
     return cell.FlagType;
 }
 private static FlagType PassDifferentFlagType(Cell cell, FlagType flagType)
 {
     cell.FlagType = flagType;
     var flagTypeValue = Cell.ChangeFlagType(cell);
     return flagTypeValue;
 }