Ejemplo n.º 1
0
        private void LoseGame()
        {
            foreach (Button button in buttons)
            {
                Cell correspondingCell = cells.Find(c => c.getXY() == (button.Location.X + " " + button.Location.Y));
                if (correspondingCell.isMine())
                {
                    button.Text      = "💣";
                    button.ForeColor = Color.Red;
                }

                correspondingCell.MakeVisible();
            }
            ChangeStatus(Status.Lost);
        }
Ejemplo n.º 2
0
        private void CheckSurroundingCells(int x, int y, Cell currentCell)
        {
            for (int i = -25; i <= 25; i += 25)
            {
                for (int j = -25; j <= 25; j += 25)
                {
                    var adjacentX = i + x;
                    var adjacentY = j + y;

                    if (adjacentX < 0)
                    {
                        continue;
                    }
                    if (adjacentY < 50)
                    {
                        continue;
                    }
                    if (adjacentX > 475)
                    {
                        continue;
                    }
                    if (adjacentY > 525)
                    {
                        continue;
                    }
                    if (i == 0 && j == 0)
                    {
                        continue;
                    }

                    Cell adjacentCell = cells.Find(c => c.getX() == adjacentX && c.getY() == adjacentY);
                    int  adjacentI = adjacentCell.getI(), adjacentJ = adjacentCell.getJ();

                    if (adjacentCell.isMine() || currentCell.getNumber() != 0)
                    {
                        continue;
                    }
                    buttons_MouseDown(buttons[adjacentI, adjacentJ], new MouseEventArgs(MouseButtons.Left, 0, 0, 0, 0));
                }
            }
        }
Ejemplo n.º 3
0
        private void buttons_MouseDown(object sender, MouseEventArgs e)
        {
            var  current     = sender as Button;
            var  x           = current.Location.X;
            var  y           = current.Location.Y;
            Cell currentCell = cells.Find(c => c.getXY() == (x + " " + y));

            if (currentCell.IsVisible())
            {
                return;
            }

            if (e.Button == MouseButtons.Left)
            {
                if (currentCell.isMine())
                {
                    LoseGame();
                }
                else
                {
                    ClickCell(current, currentCell);
                }
            }
            if (e.Button == MouseButtons.Right)
            {
                if (current.Text == "⚑")
                {
                    IncrementMineCount();
                    current.Text      = " ";
                    current.ForeColor = Color.Black;
                }
                else
                {
                    DecrementMineCount();
                    current.Text      = "⚑";
                    current.ForeColor = Color.Orange;
                }
            }
        }
Ejemplo n.º 4
0
        private int CountSurroundingMines(int x, int y)
        {
            int surroundingMineCount = 0;

            for (int i = -25; i <= 25; i += 25)
            {
                for (int j = -25; j <= 25; j += 25)
                {
                    if (i + x < 0)
                    {
                        continue;
                    }
                    if (j + y < 50)
                    {
                        continue;
                    }
                    if (i + x > 475)
                    {
                        continue;
                    }
                    if (j + y > 525)
                    {
                        continue;
                    }
                    if (i == 0 && j == 0)
                    {
                        continue;
                    }

                    Cell adjacentCell = cells.Find(c => c.getX() == (i + x) && c.getY() == (j + y));
                    if (adjacentCell.isMine())
                    {
                        surroundingMineCount++;
                    }
                }
            }

            return(surroundingMineCount);
        }