Beispiel #1
0
        private void Pic_MouseUp(object sender, MouseEventArgs e)
        {
            if (GameOver)
            {
                return;
            }
            int x = e.X / Size, y = e.Y / Size;

            if (inrange(x, y))
            {
                if (e.Button == MouseButtons.Left && RightDown || e.Button == MouseButtons.Right && LeftDown || e.Button == MouseButtons.Middle)
                {
                    LeftDown = RightDown = false;
                    if (Show[x, y])
                    {
                        int FlagCount = 0;
                        for (int i = x - 1; i <= x + 1; i++)
                        {
                            for (int j = y - 1; j <= y + 1; j++)
                            {
                                if (inrange(i, j) && !Show[i, j] && Flag[i, j])
                                {
                                    FlagCount++;
                                }
                            }
                        }
                        if (FlagCount == Num[x, y])
                        {
                            for (int i = x - 1; i <= x + 1; i++)
                            {
                                for (int j = y - 1; j <= y + 1; j++)
                                {
                                    if (inrange(i, j) && !Show[i, j] && !Flag[i, j])
                                    {
                                        Click(i, j);
                                    }
                                }
                            }
                        }
                    }
                }
                else if (e.Button == MouseButtons.Left)
                {
                    LeftDown = false;
                    Click(x, y);
                }
                else if (e.Button == MouseButtons.Right)
                {
                    RightDown  = false;
                    Flag[x, y] = !Flag[x, y];
                }
            }
            Pic.Invalidate();
        }
Beispiel #2
0
 private void Click(int x, int y)
 {
     if (inrange(x, y) && !Show[x, y] && !Flag[x, y])
     {
         if (!Started)
         {
             GenMap(x, y);
             Started = true;
             Time    = 0;
             ShowTime();
             timer1.Start();
             Click(x, y);
         }
         else if (Map[x, y])//it is mine!
         {
             for (int i = 0; i < W; i++)
             {
                 for (int j = 0; j < H; j++)
                 {
                     Show[i, j] = true;
                 }
             }
             GameOver = true;
             timer1.Stop();
             Pic.Invalidate();
             MessageBox.Show("You lose!");
         }
         else
         {
             Show[x, y] = true;
             if (Num[x, y] == 0)
             {
                 for (int i = -1; i <= 1; i++)
                 {
                     for (int j = -1; j <= 1; j++)
                     {
                         Click(x + i, y + j);
                     }
                 }
             }
             if (!GameOver)
             {
                 JudgeWin();
             }
         }
     }
 }
Beispiel #3
0
 public void NewGame()
 {
     Show     = new bool[W, H];
     Flag     = new bool[W, H];
     GameOver = false;
     Started  = false;
     Win      = false;
     LeftDown = RightDown = false;
     timer1.Stop();
     Time = 0;
     ShowTime();
     toolStripStatusLabel3.Text = W.ToString() + "x" + H.ToString();
     //resize window
     Pic.Left   = 0;
     Pic.Top    = menuStrip1.Height;
     Pic.Width  = W * Size;
     Pic.Height = H * Size + statusStrip1.Height;
     Pic.Invalidate();
 }
Beispiel #4
0
 private void JudgeWin()
 {
     Win = true;
     for (int i = 0; i < W; i++)
     {
         for (int j = 0; j < H; j++)
         {
             if (!Map[i, j] && !Show[i, j])
             {
                 Win = false;
             }
         }
     }
     if (Win)
     {
         GameOver = true;
         timer1.Stop();
         Pic.Invalidate();
         MessageBox.Show("You win within " + Time.ToString() + " second" + (Time > 1 ? "s" : "") + "!");
     }
 }