示例#1
0
文件: MainForm.cs 项目: Gudianbu/2048
        /// <summary>
        /// 游戏结束
        /// </summary>
        private void GameOver()
        {
            if (g.grade < g.bestGrade)
            {
                g.grade        = g.bestGrade; //当前成绩赋值于最好成绩
                bestgrade.Text = g.bestGrade.ToString();
                GameScreen();                 //截图保存
                messageBox mes3 = new messageBox();
                mes3.a = "恭喜!";
                mes3.b = "新的记录!自动为您保存截图。\r\n保存在" + bitfile;
                mes3.ShowDialog();
                g.Reset();
                Drawing();
                Game_pictureBox.Refresh();
            }
            else
            {
                Game_OverFrom game = new Game_OverFrom();
                game.bg = g.bestGrade;
                game.gv = g.grade;
                DialogResult d = game.ShowDialog();
                switch (d)
                {
                case DialogResult.Abort:
                    GameScreen();
                    messageBox mes2 = new messageBox();
                    mes2.a = "保存成功";
                    mes2.b = "保存在" + bitfile;
                    mes2.ShowDialog();
                    g.Reset();
                    classSave();
                    Drawing();
                    Game_pictureBox.Refresh();
                    break;

                case DialogResult.No:
                    g.Reset();
                    this.Close();
                    break;

                case DialogResult.Retry:
                    g.Reset();
                    Drawing();
                    Game_pictureBox.Refresh();
                    grade.Text     = g.grade.ToString();
                    bestgrade.Text = g.bestGrade.ToString();
                    break;
                }
            }
        }
示例#2
0
文件: MainForm.cs 项目: Gudianbu/2048
 //string sb = @"save/2048Save";
 /// <summary>
 /// 应用启动时
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void MainForm_Load(object sender, EventArgs e)
 {
     //MessageBox.Show(paths);
     if (File.Exists(paths))//监测是否有存档
     {
         ToLoad();
     }
     else//没有存档生成新游戏
     {
         messageBox mes1 = new messageBox();
         mes1.a             = "提示";
         mes1.b             = "检测到您是第一次打开,可按F1打开帮助。\r\n    游戏为无限模式,直到GameOver才会终止。";
         mes1.StartPosition = FormStartPosition.CenterScreen;//窗体居中
         mes1.ShowDialog();
         g = new Game();
         g.Reset();
     }
     mes.a = "提示";
     mes.b = "F2:窗口总在最前\r\nF3:解锁/锁定窗口\r\nF4:隐藏任务栏图标\r\nF5:重新开始\r\nF6:截图并保存\r\nShife + ↑↓:调整透明度\r\n↑↓←→:控制方块移动\r\nESC:退出\r\n作者:Ch\r\nQQ:153563565";
     Drawing();
     Game_pictureBox.Refresh();
 }
示例#3
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();
            }
        }