コード例 #1
0
        private void cell_Click(object sender, EventArgs e)
        {
            cell c = (cell)sender;

            if (IsWin() == true)
            {
                MessageBox.Show("YOU WON");
                return;
            }
            //  MouseEventArgs me = (MouseEventArgs)e;
            if (c.flag == true)
            {
                return;
            }
            if (c.IsOpen == true)
            {
                return;
            }
            if (c.getnum() == -1)
            {
                MessageBox.Show("GAME OVER");
                for (int ri = 0; ri < dim; ri++)
                {
                    for (int ci = 0; ci < dim; ci++)
                    {
                        if (cs[ri, ci].getnum() == -1)
                        {
                            cs[ri, ci].ForeColor = Color.Red;
                            cs[ri, ci].Text      = "💣";
                        }
                    }
                }
                return;
            }
            else if (c.getnum() != 0)
            {
                c.IsOpen = true;
                // this.Start.ForeColor = System.Drawing.Color.CornflowerBlue;
                if (c.getnum() == 1)
                {
                    c.ForeColor = Color.Blue;
                }
                if (c.getnum() == 2)
                {
                    c.ForeColor = Color.Green;
                }
                if (c.getnum() == 3)
                {
                    c.ForeColor = Color.Red;
                }
                c.Text = c.getnum().ToString();
            }
            else
            {
                Explore(c.ri, c.ci);
            }
        }
コード例 #2
0
        private void LoadCells()
        {
            board.Controls.Clear();
            cs = new cell[dim, dim];
            int H = board.Height / dim - 6;
            int W = board.Width / dim - 6;

            for (int ri = 0; ri < dim; ri++)
            {
                for (int ci = 0; ci < dim; ci++)
                {
                    cell c = new cell(ri, ci, H, W);
                    c.Click += new System.EventHandler(this.cell_Click);
                    board.Controls.Add(c);
                    cs[ri, ci] = c;
                }
            }
            InitMines();
        }