Exemplo n.º 1
0
        void open(object sender)
        {
            MineSweepPictureBox pb = (MineSweepPictureBox)sender;

            if (pb.Tag == numbers[0])
            {
                int r = pb.R;
                int c = pb.C;
                pb.Image = (Bitmap)pb.Tag;

                if (r - 1 >= 0)
                {
                    if (c - 1 >= 0 && grids[r - 1, c - 1].Image == cover)
                    {
                        open(grids[r - 1, c - 1]);
                    }

                    if (grids[r - 1, c].Image == cover)
                    {
                        open(grids[r - 1, c]);
                    }

                    if (c + 1 < numCol && grids[r - 1, c + 1].Image == cover)
                    {
                        open(grids[r - 1, c + 1]);
                    }
                }

                if (c - 1 >= 0 && grids[r, c - 1].Image == cover)
                {
                    open(grids[r, c - 1]);
                }
                if (c + 1 < numCol && grids[r, c + 1].Image == cover)
                {
                    open(grids[r, c + 1]);
                }

                if (r + 1 < numRow)
                {
                    if (c - 1 >= 0 && grids[r + 1, c - 1].Image == cover)
                    {
                        open(grids[r + 1, c - 1]);
                    }

                    if (grids[r + 1, c].Image == cover)
                    {
                        open(grids[r + 1, c]);
                    }

                    if (c + 1 < numCol && grids[r + 1, c + 1].Image == cover)
                    {
                        open(grids[r + 1, c + 1]);
                    }
                }
            }
        }
Exemplo n.º 2
0
        void SetupCover()
        {
            grids = new MineSweepPictureBox[numRow, numCol];
            int w = (int)((ClientRectangle.Width) * 0.8 / numCol);
            int h = (int)((ClientRectangle.Width) * 0.8 / numCol);

            for (int r = 0; r < numRow; r++)
            {
                for (int c = 0; c < numCol; c++)
                {
                    grids[r, c]          = new MineSweepPictureBox();
                    grids[r, c].Width    = w;
                    grids[r, c].Height   = h;
                    grids[r, c].Top      = 120 + r * h;
                    grids[r, c].Left     = (int)((ClientRectangle.Width) * 0.1 + c * w);
                    grids[r, c].SizeMode = PictureBoxSizeMode.StretchImage;
                    grids[r, c].Image    = cover;
                    grids[r, c].R        = r;
                    grids[r, c].C        = c;
                    Controls.Add(grids[r, c]);
                }
            }
        }
Exemplo n.º 3
0
        private void mouseClick(object sender, MouseEventArgs e)
        {
            MineSweepPictureBox pb = (MineSweepPictureBox)sender;

            switch (e.Button)
            {
            case MouseButtons.Left:

                int opened = numCol * numRow - totalbombnum;
                if (pb.Tag == bomb)
                {
                    pb.Image = (Bitmap)pb.Tag;
                    transparentPanel_lose.Visible = true;
                    endgame();
                }
                else if (pb.Tag == numbers[0])
                {
                    open(pb);
                    for (int r = 0; r < numRow; r++)
                    {
                        for (int c = 0; c < numCol; c++)
                        {
                            //check if the player win the game
                            if (grids[r, c].Image != cover)
                            {
                                opened--;
                            }
                        }
                    }
                    if (opened <= 0)
                    {
                        endgame();
                        transparentPanel_pass.Visible = true;
                    }
                }
                else
                {
                    pb.Image = (Bitmap)pb.Tag;
                    for (int r = 0; r < numRow; r++)
                    {
                        for (int c = 0; c < numCol; c++)
                        {
                            //check if the player win the game
                            if (grids[r, c].Image != cover)
                            {
                                opened--;
                            }
                        }
                    }
                    if (opened <= 0)
                    {
                        endgame();
                        transparentPanel_pass.Visible = true;
                    }
                }
                break;

            case MouseButtons.Right:
                if (pb.Image == cover)
                {
                    pb.Image = flag;
                }
                else if (pb.Image == flag)
                {
                    pb.Image = question;
                }
                else
                {
                    pb.Image = cover;
                }
                break;
            }
        }