protected void openRegion(FieldButton bt) { //Открывает все 0 ячейки в округе, если нажата ячейка с 0 var str = bt.Name.Split(' '); var x1 = Convert.ToInt32(str[0]) - bWidth; var x2 = x1 + bWidth * 3; var y1 = Convert.ToInt32(str[1]) - bHight; var y2 = y1 + bHight * 3; var buttons = new List <FieldButton>(); for (int i = x1; i < x2; i += bWidth) { for (int j = y1; j < y2; j += bHight) { FieldButton tempBt = fb.Find(button => button.Name == $"{i} {j}"); if (tempBt != null && tempBt.isClicable && !tempBt.Bomb()) { int b = bombAround(tempBt); openCell(tempBt, b); if (b == 0) { buttons.Add(tempBt); } } } } foreach (FieldButton button in buttons) { openRegion(button); } }
protected int bombAround(FieldButton bt) { //Считает бомбы вокруг нажатой кнопки int bombs = 0; var str = bt.Name.Split(' '); var x1 = Convert.ToInt32(str[0]) - bWidth; var x2 = x1 + bWidth * 3; var y1 = Convert.ToInt32(str[1]) - bHight; var y2 = y1 + bHight * 3; for (int i = x1; i < x2; i += bWidth) { for (int j = y1; j < y2; j += bHight) { FieldButton tempBt = fb.Find(button => button.Name == $"{i} {j}"); if (tempBt != null && tempBt.Bomb()) { bombs++; } } } return(bombs); }