/// <summary> /// 鼠标点击事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void use_MouseDown(object sender, MouseEventArgs e) { if (HC_num == 0) { dtstart = DateTime.Now.AddSeconds(-1); timer1.Enabled = true; timer1.Start(); } Button use = (Button)sender; if (MouseButtons.Left == e.Button) { if (use.Text == "卍") { return; } UserControl1 user = (UserControl1)use.Parent; int col = user.Location.X / 20; int row = user.Location.Y / 20; if (boom[row][col] == 9) { timer1.Stop(); game_over(row, col); MessageBox.Show("游戏结束"); } else if (boom[row][col] == 0) { Label lable = new Label(); lable.Text = ""; user.Controls.Add(lable); lable.Location = new Point(3, 2); use.Visible = false; user.BorderStyle = BorderStyle.Fixed3D; HC_num++; if_boom_zero(row - 1, col); if_boom_zero(row, col - 1); if_boom_zero(row, col + 1); if_boom_zero(row + 1, col); if_boom_zero(row - 1, col - 1); if_boom_zero(row - 1, col + 1); if_boom_zero(row + 1, col + 1); if_boom_zero(row + 1, col - 1); if (HC_num + boom_num == row_num * col_num || row_num * col_num - HC_num == boom_count) { timer1.Stop(); MessageBox.Show("恭喜你,找出所有雷,赢得游戏!"); } } else { Label lable = new Label(); lable.Text = boom[row][col].ToString(); user.Controls.Add(lable); lable.Location = new Point(3, 2); use.Visible = false; user.BorderStyle = BorderStyle.Fixed3D; HC_num++; if (HC_num + boom_num == row_num * col_num) { timer1.Stop(); MessageBox.Show("恭喜你,找出所有雷,赢得游戏!"); } } } else if (MouseButtons.Right == e.Button) { if (use.Text == "") { use.Text = "卍"; boom_num++; if (HC_num + boom_num == row_num * col_num || row_num * col_num - HC_num == boom_count) { timer1.Stop(); MessageBox.Show("恭喜你,找出所有雷,赢得游戏!"); } Paint_Num(boom_count - boom_num, this.panel3); } else if (use.Text == "卍") { use.Text = "?"; boom_num--; Paint_Num(boom_count - boom_num, this.panel3); } else if (use.Text == "?") { use.Text = ""; } } }