示例#1
0
 public void SetNextWinningDestination()
 {
     if (this.AtWinningDestiation())
     {
         CurrentWinningDestination.CurrentWinningCell = false;
         CurrentWinningDestination = WinningDestinations[WinningDestinations.IndexOf(CurrentWinningDestination) + 1 == WinningDestinations.Count ? 0 : WinningDestinations.IndexOf(CurrentWinningDestination) + 1];
         CurrentWinningDestination.CurrentWinningCell = true;
     }
 }
        private void RemoveCells(Cell cellToRemove, bool removeDiagonals, ref List <Cell> cells)
        {
            cells.Remove(cellToRemove);
            //Remove adjacent cells
            cells.Remove(cells.FirstOrDefault(c => c.X == cellToRemove.X - 1 && c.Y == cellToRemove.Y));
            cells.Remove(cells.FirstOrDefault(c => c.X == cellToRemove.X + 1 && c.Y == cellToRemove.Y));
            cells.Remove(cells.FirstOrDefault(c => c.X == cellToRemove.X && c.Y == cellToRemove.Y - 1));
            cells.Remove(cells.FirstOrDefault(c => c.X == cellToRemove.X && c.Y == cellToRemove.Y + 1));

            //Remove diagonal adjacent cells
            if (removeDiagonals)
            {
                cells.Remove(cells.FirstOrDefault(c => c.X == cellToRemove.X + 1 && c.Y == cellToRemove.Y + 1));
                cells.Remove(cells.FirstOrDefault(c => c.X == cellToRemove.X + 1 && c.Y == cellToRemove.Y - 1));
                cells.Remove(cells.FirstOrDefault(c => c.X == cellToRemove.X - 1 && c.Y == cellToRemove.Y + 1));
                cells.Remove(cells.FirstOrDefault(c => c.X == cellToRemove.X - 1 && c.Y == cellToRemove.Y - 1));
            }

            //Never have more than two winning cells in the same row or column.
            if (WinningDestinations.Count(c => c.X == cellToRemove.X) == 2)
            {
                List <Cell> cellsInSameRowToRemove = new List <Cell>();
                foreach (Cell cell in cells.Where(c => c.X == cellToRemove.X))
                {
                    cellsInSameRowToRemove.Add(cell);
                }
                foreach (Cell cell in cellsInSameRowToRemove)
                {
                    cells.Remove(cell);
                }
            }

            if (WinningDestinations.Count(c => c.Y == cellToRemove.Y) == 2)
            {
                List <Cell> cellsInSameColumnToRemove = new List <Cell>();
                foreach (Cell cell in cells.Where(c => c.Y == cellToRemove.Y))
                {
                    cellsInSameColumnToRemove.Add(cell);
                }
                foreach (Cell cell in cellsInSameColumnToRemove)
                {
                    cells.Remove(cell);
                }
            }
        }