/// <summary> /// Kume sayisinin belirlenmesi /// </summary> private void ClusterCounting() { for(int i = 0; i < this.Cells.GetLength(0); i++) { for (int j = 0; j < this.Cells.GetLength(1); j++) { if (this.Cells[i, j].IsVisited || (this.Cells[i, j].MainGrid.Background as SolidColorBrush).Color == Cell.FreeCellColor) continue; this.Cells[i, j].IsVisited = true; Cluster cluster = new Cluster((this.Cells[i, j].MainGrid.Background as SolidColorBrush).Color); cluster.CellList.Add(this.Cells[i, j]); this.clusterList.Add(cluster); this.ScanAround(i, j, cluster); } } }
/// <summary> /// Bu metod her elemanin etrafini kontrol eder. /// Elemanin etrafinda ayni renkte baska bir eleman varsa bu elemanlar ayni kumeye dahil edilir. /// </summary> /// <param name="i"></param> /// <param name="j"></param> /// <param name="cluster"></param> private void ScanAround(int i, int j, Cluster cluster) { // Üst if(i - 1 >= 0 && !this.Cells[i - 1, j].IsVisited) { // Eğer aynı renkte ise; if((this.Cells[i, j].MainGrid.Background as SolidColorBrush).Color == (this.Cells[i - 1, j].MainGrid.Background as SolidColorBrush).Color) { this.Cells[i - 1, j].IsVisited = true; cluster.CellList.Add(this.Cells[i - 1, j]); this.ScanAround(i - 1, j, cluster); } } // Alt if (i + 1 < this.Cells.GetLength(0) && !this.Cells[i + 1, j].IsVisited) { // Eğer aynı renkte ise; if ((this.Cells[i, j].MainGrid.Background as SolidColorBrush).Color == (this.Cells[i + 1, j].MainGrid.Background as SolidColorBrush).Color) { this.Cells[i + 1, j].IsVisited = true; cluster.CellList.Add(this.Cells[i + 1, j]); this.ScanAround(i + 1, j, cluster); } } // Sol if (j - 1 >= 0 && !this.Cells[i, j - 1].IsVisited) { // Eğer aynı renkte ise; if ((this.Cells[i, j].MainGrid.Background as SolidColorBrush).Color == (this.Cells[i, j - 1].MainGrid.Background as SolidColorBrush).Color) { this.Cells[i, j - 1].IsVisited = true; cluster.CellList.Add(this.Cells[i, j - 1]); this.ScanAround(i, j - 1, cluster); } } // Alt if (j + 1 < this.Cells.GetLength(1) && !this.Cells[i, j + 1].IsVisited) { // Eğer aynı renkte ise; if ((this.Cells[i, j].MainGrid.Background as SolidColorBrush).Color == (this.Cells[i, j + 1].MainGrid.Background as SolidColorBrush).Color) { this.Cells[i, j + 1].IsVisited = true; cluster.CellList.Add(this.Cells[i, j + 1]); this.ScanAround(i, j + 1, cluster); } } }