Beispiel #1
0
        private void Form1_Click(object sender, MouseEventArgs e)
        {
            MineButton btn = sender as MineButton;

            switch (e.Button)
            {
            case MouseButtons.Left:
                // Left click
                if (btn.Mine)
                {
                    //죽음 게임 종료
                    smile.Text = ":(";
                    btn.Text   = "*";
                    for (int i = 0; i < 5; i++)
                    {
                        for (int y = 0; y < 5; y++)
                        {
                            bnt[i, y].MouseDown -= Form1_Click;
                            Label complete = new Label();
                            complete.Text     = "YOU DIE.";
                            complete.Font     = new Font("bntribntl", 20, FontStyle.Bold);
                            complete.Size     = new Size(150, 35);
                            complete.Location = new Point(100, 150);

                            Controls.Add(complete);
                            complete.BringToFront();
                        }
                    }
                }
                else
                {
                    btn.showHint();
                    btn.Enabled = false;
                }
                break;

            case MouseButtons.Right:
                // Right click
                btn.Text = "#";
                if (ChkFlag())
                {
                    Label complete = new Label();
                    complete.Text     = "complete";
                    complete.Font     = new Font("bntribntl", 20, FontStyle.Bold);
                    complete.Size     = new Size(140, 35);
                    complete.Location = new Point(100, 150);

                    Controls.Add(complete);
                    complete.BringToFront();
                }
                break;
            }
        }
Beispiel #2
0
 public void InitGame()
 {
     for (int i = 0; i < 5; i++)
     {
         for (int y = 0; y < 5; y++)
         {
             bnt[i, y]            = new MineButton();
             bnt[i, y].Mine       = maps[i, y];
             bnt[i, y].Text       = "  ";
             bnt[i, y].TabStop    = false;
             bnt[i, y].Size       = new Size(width, height);
             bnt[i, y].Font       = new Font("bntribntl", 15, FontStyle.Bold);
             bnt[i, y].Location   = new Point(i * 50 + 50, y * 50 + 50);
             bnt[i, y].Enabled    = true;
             bnt[i, y].MouseDown += new MouseEventHandler(Form1_Click);
             Controls.Add(bnt[i, y]);
         }
     }
     for (int i = 0; i < 5; i++)
     {
         for (int y = 0; y < 5; y++)
         {
             try { if (bnt[i - 1, y].Mine)
                   {
                       bnt[i, y].Mhint++;
                   }
             } catch { }
             try { if (bnt[i + 1, y].Mine)
                   {
                       bnt[i, y].Mhint++;
                   }
             } catch { }
             try { if (bnt[i, y - 1].Mine)
                   {
                       bnt[i, y].Mhint++;
                   }
             } catch { }
             try { if (bnt[i, y + 1].Mine)
                   {
                       bnt[i, y].Mhint++;
                   }
             } catch { }
             try { if (bnt[i - 1, y - 1].Mine)
                   {
                       bnt[i, y].Mhint++;
                   }
             } catch { }
             try { if (bnt[i - 1, y + 1].Mine)
                   {
                       bnt[i, y].Mhint++;
                   }
             } catch { }
             try { if (bnt[i + 1, y - 1].Mine)
                   {
                       bnt[i, y].Mhint++;
                   }
             } catch { }
             try { if (bnt[i + 1, y + 1].Mine)
                   {
                       bnt[i, y].Mhint++;
                   }
             } catch { }
         }
     }
 }