private void BombButton_Up(object sender, MouseEventArgs e) { if (m_isGameOver) { return; } System.Diagnostics.Debug.WriteLine(e.Button.ToString() + ",Up," + m_bombBtn.m_Pos.ToString()); if (m_IsLeftDown && m_IsRightDown && e.Button == MouseButtons.Right) { m_isDown = false; if (m_bombBtn.m_nState <= 3) { SetRoundBtn(m_bombBtn, 1); if (m_bombBtn.m_nState != 3) { m_bombBtn.SetState(2); } } } if (m_IsLeftDown && !m_IsRightDown && m_isDown) { if (m_bombBtn.m_nState < 3) { if (m_bombBtn.m_IsBoom) { MessageBox.Show("Game Over,你踩到雷了!"); m_bombBtn.SetState(3); //m_isGameOver = true; } else { //开图算法 碰到数字即结束 OpenMap(m_bombBtn); if (m_nRemain == m_nBomb) { MessageBox.Show("赢了!"); } } } //m_bombBtn.SetState(3); } if (!m_IsLeftDown && m_IsRightDown && e.Button == MouseButtons.Right)//右键单击 { m_bombBtn.SetState(m_bombBtn.m_nState == 4?1:4); } if (e.Button == MouseButtons.Left) { m_IsLeftDown = false; m_isDown = true; if (m_bombBtn.m_nState < 3) { m_bombBtn.SetState(1); } } if (e.Button == MouseButtons.Right) { m_IsRightDown = false; } }
private void OpenMap(BombButton btn) { if (btn.m_nState != 3) { m_nRemain--; if (btn.m_nBoomAmount == 0) { btn.SetState(3); int x = btn.m_Pos.X, y = btn.m_Pos.Y; if ((x - 1) >= 0)//开左边 { BombButton tmpBtnLeft = (BombButton)m_arrLattice[(x - 1) * m_nHight + y]; OpenMap(tmpBtnLeft); if ((y - 1) >= 0)//左上 { BombButton tmpBtnLeftUp = (BombButton)m_arrLattice[(x - 1) * m_nHight + (y - 1)]; OpenMap(tmpBtnLeftUp); } if ((y + 1) < m_nHight)//左下 { BombButton tmpBtnLeftUp = (BombButton)m_arrLattice[(x - 1) * m_nHight + (y + 1)]; OpenMap(tmpBtnLeftUp); } } if ((x + 1) < m_nWidth)//开右边 { BombButton tmpBtnRight = (BombButton)m_arrLattice[(x + 1) * m_nHight + y]; OpenMap(tmpBtnRight); if ((y - 1) >= 0)//右上 { BombButton tmpBtnRightUp = (BombButton)m_arrLattice[(x + 1) * m_nHight + (y - 1)]; OpenMap(tmpBtnRightUp); } if ((y + 1) < m_nHight)//右下 { BombButton tmpBtnRightUp = (BombButton)m_arrLattice[(x + 1) * m_nHight + (y + 1)]; OpenMap(tmpBtnRightUp); } } if ((y - 1) >= 0)//开上边 { BombButton tmpBtn = (BombButton)m_arrLattice[x * m_nHight + (y - 1)]; OpenMap(tmpBtn); } if ((y + 1) < m_nHight)//开下边 { BombButton tmpBtn = (BombButton)m_arrLattice[x * m_nHight + (y + 1)]; OpenMap(tmpBtn); } } } btn.SetState(3); }
private void SetRoundBtn(BombButton btn, int state) { //m_bombBtn.SetState(2); int i = m_bombBtn.m_Pos.X * m_nWidth + m_bombBtn.m_Pos.Y; for (int x = m_bombBtn.m_Pos.X - 1; x <= m_bombBtn.m_Pos.X + 1; x++) { for (int y = m_bombBtn.m_Pos.Y - 1; y <= m_bombBtn.m_Pos.Y + 1; y++) { System.Diagnostics.Debug.WriteLine(m_bombBtn.m_Pos.X + "," + m_bombBtn.m_Pos.Y + "--" + x.ToString() + "," + y.ToString()); if (x < 0 || y < 0) { continue; } if (x > (m_nWidth - 1) || y > (m_nHight - 1)) { continue; } int sub = ((x * m_nHight) + y); BombButton tmpBtnAmount = (BombButton)m_arrLattice[sub]; if (tmpBtnAmount.m_nState <= 2) { tmpBtnAmount.SetState(state); } } } }