Esempio n. 1
0
        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());
        }
Esempio n. 2
0
        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());
        }