public bool RevealButton(Button btn) { //find plate MinePlate plate = MinePlates. FirstOrDefault(predicate: x => Equals(objA: x.BtnButton as Button, objB: btn)); if (plate == null) { throw new NullReferenceException(message: "Plate not found"); } if (plate != null && !plate.IsRevealed && !plate.IsFlagged) { if (plate.IsMined) { SetButtonVisuals(stat: MineStatEnum.IsBombed, btn: btn, plate: plate); RevealAll(); } else if (plate.IntDisplay > 0) { SetButtonVisuals(stat: MineStatEnum.IsNumbered, btn: btn, plate: plate); } else { SetButtonVisuals(stat: MineStatEnum.IsPlane, btn: btn, plate: plate); List <MinePlate> neighbours = GetNeighboursList(plate: plate); foreach (MinePlate neighbour in neighbours) { Button button = neighbour.BtnButton as Button; RevealButton(btn: button); } } } return(CheckGameEndingConditions()); }
private List <MinePlate> GetNeighboursList(MinePlate plate) { return(MinePlates.Where(predicate: x => (x.RowPos <= plate.RowPos + 1 && x.RowPos >= plate.RowPos - 1) && (x.ColumnPos <= plate.ColumnPos + 1 && x.ColumnPos >= plate.ColumnPos - 1) && x != plate) .ToList()); }
public bool MarkButton(Button btn) { //find plate MinePlate plate = MinePlates. FirstOrDefault(predicate: x => Equals(objA: x.BtnButton as Button, objB: btn)); if (plate == null) { throw new NullReferenceException(); } if (plate.IsFlagged) { btn.Background = Brushes.DodgerBlue; plate.IsFlagged = false; MinesLeft++; } else if (MinesLeft > 0) { btn.Background = Brushes.BlueViolet; plate.IsFlagged = true; MinesLeft--; } return(CheckGameEndingConditions()); }
public void AddPlate(Button btnButton, int x, int y) { MinePlate plate = new MinePlate(column: y, row: x, button: btnButton); MinePlates.Add(item: plate); }