Esempio n. 1
0
 public void mineinitial(int x, int y, int mines)
 {
     clean();
     this.x = x;
     this.y = y;
     setmine(x, y, mines);
     matrix = new MineControl[x*y];
     for (int i = 0; i < x; i++)
     {
         for (int j = 0; j < y; j++)
         {
             MineControl btn = new MineControl();
             btn.Width = btnSize;
             btn.Height = btnSize;
             btn.Top = btnSize * i + 25;
             btn.Left = btnSize * j;
             btn.Visible = true;
             btn.value = mine[i, j];
             btn.MouseStatusDown += mousedown;
             btn.MouseStatusUp += mouseup;
             btn.Lx = i;
             btn.Ly = j;
             this.Controls.Add(btn);
             matrix[i * y + j] = btn;
         }
     }
     this.Width = 10 + btnSize * y;
     this.Height = 45 + btnSize * x + btnSize;
     this.Refresh();
 }
Esempio n. 2
0
 public void mineinitial(int x, int y, int mines)
 {
     clean();
     this.x = x;
     this.y = y;
     setmine(x, y, mines);
     matrix = new MineControl[x * y];
     for (int i = 0; i < x; i++)
     {
         for (int j = 0; j < y; j++)
         {
             MineControl btn = new MineControl();
             btn.Width            = btnSize;
             btn.Height           = btnSize;
             btn.Top              = btnSize * i + 25;
             btn.Left             = btnSize * j;
             btn.Visible          = true;
             btn.value            = mine[i, j];
             btn.MouseStatusDown += mousedown;
             btn.MouseStatusUp   += mouseup;
             btn.Lx = i;
             btn.Ly = j;
             this.Controls.Add(btn);
             matrix[i * y + j] = btn;
         }
     }
     this.Width  = 10 + btnSize * y;
     this.Height = 45 + btnSize * x + btnSize;
     this.Refresh();
 }
Esempio n. 3
0
        private void mousedown(object sender, EventArgs e)
        {
            MineControl btn = (MineControl)sender;

            switch (btn.mouseStatus)
            {
            case 1:
                btn.Press();
                break;

            case 2:
                btn.Putflag();
                if (checkwin())
                {
                    MessageBox.Show("You Win!! O(∩_∩)O");
                    break;
                }
                break;

            case 3:
                for (int i = btn.Lx - 1; i <= btn.Lx + 1; i++)
                {
                    if (btn.Lx < 0 || btn.Lx > x)
                    {
                        continue;
                    }
                    for (int j = btn.Ly - 1; j <= btn.Ly + 1; j++)
                    {
                        if (btn.Ly < 0 || btn.Ly > y)
                        {
                            continue;
                        }
                        {
                            if (checkround(i, j))
                            {
                                matrix[i * x + j].Press();
                            }
                        }
                    }
                }
                //btn.Press();
                break;
            }
        }
Esempio n. 4
0
        private void mouseup(object sender, EventArgs e)
        {
            MineControl btn = (MineControl)sender;

            switch (btn.mouseStatus)
            {
            case 4:
                btn.Open();
                if (mine[btn.Lx, btn.Ly] == 9 && !matrix[btn.Lx * x + btn.Ly].IsFlag)
                {
                    MessageBox.Show("You Lose!! %>_<%");
                    foreach (MineControl m in matrix)
                    {
                        if (mine[m.Lx, m.Ly] == 9)
                        {
                            m.Open();
                        }
                    }
                    break;
                }
                else if (checkwin())
                {
                    MessageBox.Show("You Win!! O(∩_∩)O");
                    break;
                }
                if (btn.value == 0)
                {
                    fill(btn.Lx, btn.Ly);
                }
                break;

            case 5:
                break;

            case 6:
                bool f = false;
                if (openfield(btn.Lx, btn.Ly))
                {
                    for (int i = btn.Lx - 1; i <= btn.Lx + 1; i++)
                    {
                        if (f)
                        {
                            break;
                        }
                        if (btn.Lx < 0 || btn.Lx > x)
                        {
                            continue;
                        }
                        for (int j = btn.Ly - 1; j <= btn.Ly + 1; j++)
                        {
                            if (btn.Ly < 0 || btn.Ly > y)
                            {
                                continue;
                            }
                            {
                                if (checkround(i, j))
                                {
                                    if (mine[i, j] == 9 && !matrix[i * x + j].IsFlag)
                                    {
                                        matrix[i * x + j].Open();
                                        MessageBox.Show("You Lose!! %>_<%");
                                        foreach (MineControl m in matrix)
                                        {
                                            if (mine[m.Lx, m.Ly] == 9)
                                            {
                                                m.Open();
                                            }
                                        }
                                        f = true;
                                    }
                                    else
                                    {
                                        matrix[i * x + j].Open();
                                        fill(i, j);
                                        if (checkwin())
                                        {
                                            MessageBox.Show("You Win!! O(∩_∩)O");
                                            f = true;
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                else
                {
                    for (int i = btn.Lx - 1; i <= btn.Lx + 1; i++)
                    {
                        if (btn.Lx < 0 || btn.Lx > x)
                        {
                            continue;
                        }
                        for (int j = btn.Ly - 1; j <= btn.Ly + 1; j++)
                        {
                            if (btn.Ly < 0 || btn.Ly > y)
                            {
                                continue;
                            }
                            {
                                if (checkround(i, j))
                                {
                                    matrix[i * x + j].UnPress();
                                }
                            }
                        }
                    }
                }
                break;
            }
        }