예제 #1
0
파일: MainForm.cs 프로젝트: Gudianbu/2048
        /// <summary>
        /// 捕捉键盘事件
        /// </summary>
        /// <param name="sender">键盘模型</param>
        /// <param name="e">键盘事件参数</param>
        private void MainForm_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
                #region 方向键 ↑
            case Keys.Up:
                if (e.Modifiers == Keys.Shift)
                {
                    this.Opacity -= 0.1;
                }
                else
                {
                    g.Up();
                    if (g.change)
                    {
                        g.Add();
                    }
                }
                break;
                #endregion

                #region 方向键 ↓
            case Keys.Down:
                if (e.Modifiers == Keys.Shift)
                {
                    this.Opacity += 0.1;
                }
                else
                {
                    g.Down();
                    if (g.change)
                    {
                        g.Add();
                    }
                }
                break;
                #endregion

                #region 方向键 ←
            case Keys.Left:
                g.Left();
                if (g.change)
                {
                    g.Add();
                }
                break;
                #endregion

                #region 方向键 →
            case Keys.Right:
                g.Right();
                if (g.change)
                {
                    g.Add();
                }
                break;
                #endregion

                #region F1
            case Keys.F1:
                mes.ShowDialog();
                break;
                #endregion

                #region F2
            case Keys.F2:
                this.TopMost = !this.TopMost;
                break;
                #endregion

                #region F3
            case Keys.F3:
                if (this.FormBorderStyle == FormBorderStyle.FixedToolWindow)
                {
                    this.FormBorderStyle = FormBorderStyle.None;
                }
                break;
                #endregion

                #region F4
            case Keys.F4:
                this.ShowInTaskbar = !this.ShowInTaskbar;
                break;
                #endregion

                #region F5
            case Keys.F5:
                g = new Game();
                g.Reset();
                Game_pictureBox.Refresh();
                break;
                #endregion

                #region F6
            case Keys.F6:
                GameScreen();        //截图
                messageBox mes2 = new messageBox();
                mes2.a = "保存成功";
                mes.b  = "保存在" + Directory.GetCurrentDirectory() + "\\成绩截图.bmp";
                mes2.ShowDialog();
                break;
                #endregion

                #region ESC
            case Keys.Escape:
                Close();
                break;
                #endregion
            }
            Drawing();
            Game_pictureBox.Refresh();
            grade.Text = g.grade.ToString(); //当前成绩
            if (g.die)                       //判断游戏是否结束
            {
                GameOver();
            }
        }