コード例 #1
0
    /**
     * get all buttons in the menu and add them to the list.
     * the adding is done by index. meanning that the order of the buttons is determend by their order in the hierarchy.
     */
    private void AddAllButtons()
    {
        Transform parent = transform.parent;

        for (int i = 0; i < parent.childCount; ++i)
        {
            Transform currentChild = parent.GetChild(i);

            _Button button = currentChild.GetComponent <_Button>();
            if (null != button)
            {
                Buttons.Add(button);
            }
        }
    }
コード例 #2
0
        /// <summary>
        /// 设计器支持所需的方法 - 不要修改
        /// 使用代码编辑器修改此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {
            //this.button1 = new System.Windows.Forms.Button();
            //this.SuspendLayout();
            //
            // button1
            //
            //this.button1.Location = new System.Drawing.Point(359, 12);
            //this.button1.Name = "button1";
            //this.button1.Size = new System.Drawing.Size(75, 23);
            //this.button1.TabIndex = 0;
            //this.button1.Text = "button1";
            //this.button1.UseVisualStyleBackColor = true;
            //this.button1.Click += new System.EventHandler(this.Button1_Click);
            //
            // Form1
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F);
            this.AutoScaleMode       = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize          = new System.Drawing.Size(550, 550);
            this.FormBorderStyle     = System.Windows.Forms.FormBorderStyle.FixedSingle;
            this.MaximizeBox         = false;
            this.Name = "Form1";
            this.Text = "Form1";
            this.ResumeLayout(false);

            for (int i = 0; i < 100; i++)
            {
                buttons[i]          = new _Button();
                buttons[i].TabIndex = i;
                buttons[i].Width    = 50;
                buttons[i].Height   = 50;
                buttons[i].Text     = " ";
                buttons[i].Left     = Left + 25;
                buttons[i].Top      = Top + 25;
                //buttons[i].MouseDoubleClick += new MouseEventHandler(ButtonDoubleClick);
                buttons[i].MouseDown += new MouseEventHandler(ButtonSingleClick);
                this.Controls.Add(buttons[i]);
                Left += 50;
                if (Left >= 500)
                {
                    Left = 0;
                    Top += 50;
                }
            }
        }
コード例 #3
0
        private void MouseLeftButtonClick(object sender, MouseEventArgs e)
        {
            _Button CurrentButton = sender as _Button;

            if (CurrentButton.IsClicked)
            {
                return;
            }
            int Position = CurrentButton.TabIndex;

            if (!Initialized)
            {
                InitMinePanel(Position);
                Initialized = true;
            }
            if (buttons[Position].ContainsMine)
            {
                foreach (var i in MinesPosition)
                {
                    buttons[i].Image = bitmaps[9];
                }
                MessageBox.Show("游戏结束!");
                Application.Exit();
            }
            else
            {
                if (buttons[Position].AroundNumber != 0)
                {
                    buttons[Position].Image     = bitmaps[buttons[Position].AroundNumber];
                    buttons[Position].IsClicked = true;
                    buttons[Position].Status    = Enumbuttonstatus.Opened;
                    --UnopenedButtons;
                }
                else if (buttons[Position].AroundNumber == 0)
                {
                    buttons[Position].Enabled   = false;
                    buttons[Position].IsClicked = true;
                    buttons[Position].Status    = Enumbuttonstatus.Opened;
                    --UnopenedButtons;
                    BreadthFirstSearch(Position);
                }
            }
        }
コード例 #4
0
        private void MouseRightButtonClick(object sender, MouseEventArgs e)
        {
            _Button button = sender as _Button;

            if (button.Status == Enumbuttonstatus.Unopened)
            {
                button.Status = Enumbuttonstatus.Marked;
                button.Image  = bitmaps[10];
            }
            else if (button.Status == Enumbuttonstatus.Marked)
            {
                button.Status = Enumbuttonstatus.Suspected;
                button.Image  = bitmaps[0];
            }
            else if (button.Status == Enumbuttonstatus.Suspected)
            {
                button.Status = Enumbuttonstatus.Unopened;
                button.Image  = bitmaps[11];
            }
            else
            {
            }
        }