Example #1
0
        private void InternalLeftButtonClick(ButtonInfo info)
        {
            if (info.Button.CurrentCellType == CellType.Button)
            {
                if (CellDataProvider[info.X, info.Y])
                {
                    info.Button.SetType(CellType.BombExplode);
                    CellDataProvider.EndTypeUpdated(EndType.YouHaveLost, 0);
                }
                else
                {
                    info.Button.SetType(CellType.Empty);
                    int bombsNear = GetBombsAround(info.X, info.Y, (x, y) => CellDataProvider[x, y]);
                    if (bombsNear == 0)
                    {
                        var marked = new HashSet <ButtonInfo>();
                        MarkEmptyAround(info, marked);
                    }
                    else
                    {
                        info.Button.SetType((CellType)Enum.Parse(typeof(CellType), $"Near{bombsNear}"));
                    }
                }
            }

            CheckGameStatus();
        }
Example #2
0
        private void CheckGameStatus()
        {
            bool anyClosed    = false;
            int  foundedBombs = 0;

            _buttons.ForEach(
                (button, x, y) =>
            {
                if (button.CurrentCellType == CellType.Flagged)
                {
                    foundedBombs++;
                }

                if (button.CurrentCellType == CellType.Button)
                {
                    anyClosed = true;
                }
            });

            if (anyClosed)
            {
                CellDataProvider.EndTypeUpdated(EndType.ButtonPressed, foundedBombs);
                return;
            }


            int closedFields = 0;

            _buttons.ForEach(
                (button, x, y) =>
            {
                if (button.CurrentCellType == CellType.Button)
                {
                    closedFields++;
                }
            });

            if (foundedBombs == CellDataProvider.BombsCount && closedFields == 0)
            {
                // Show up all bombs. You have won
                CellDataProvider.EndTypeUpdated(EndType.YouHaveWon, 0);
            }
        }