Esempio n. 1
0
        private void Gameover()   //游戏结束
        {
            if (c.best < c.score) //判断本次成绩是否刷新纪录
            {
                c.best    = c.score;
                best.Text = c.best.ToString();
                Screen();
                message mes4 = new message();
                mes4.a             = "Congratulations!";
                mes4.b             = "新记录!自动为您保存截图。\r\n保存位置:" + ss;
                mes4.StartPosition = FormStartPosition.CenterParent;
                mes4.ShowDialog();
                c.Restart();
                draw();
                pictureBox1.Refresh();
            }
            else
            {
                GameOver g = new GameOver();
                g.b = c.best;
                g.s = c.score;
                DialogResult d = g.ShowDialog();
                switch (d)
                {
                case DialogResult.Retry:
                    c.Restart();
                    draw();
                    pictureBox1.Refresh();
                    score.Text = c.score.ToString();
                    best.Text  = c.best.ToString();
                    break;

                case DialogResult.Abort:
                    Screen();
                    message mes3 = new message();
                    mes3.a             = "Saved successfully!";
                    mes3.b             = "保存位置:" + ss;
                    mes3.StartPosition = FormStartPosition.CenterParent;
                    mes3.ShowDialog();
                    c.Restart();
                    classSave();
                    draw();
                    pictureBox1.Refresh();
                    break;

                case DialogResult.No:
                    c.Restart();
                    this.Close();
                    break;
                }
            }
        }
Esempio n. 2
0
 private void RestartBtn(object sender, EventArgs e)  //重新开始按钮
 {
     c = new Class1();
     c.Restart();
     pictureBox1.Refresh();
     draw();
     pictureBox1.Refresh();
     score.Text = c.score.ToString();
 }
Esempio n. 3
0
        private void Form1_Load(object sender, EventArgs e)
        {
            if (File.Exists("D:\\2048记录"))  //检测是否有存档
            {
                ToLoad();
            }
            else                              //否则为首次进入游戏
            {
                message mes1 = new message();
                mes1.a             = "Welcome!";
                mes1.b             = "玩家可以选择上下左右四个方向,若棋盘内的数字出现位移或合并,视为有效移动。\r\n  玩家选择的方向上若有相同的数字则合并,每次有效移动可以同时合并,但不可以连续合并;合并所得的所有新生成数字相加即为该步的有效得分;玩家选择的方向行或列前方有空格则出现位移。\r\n  棋盘被数字填满,无法进行有效移动,判负,游戏结束;棋盘上出现2048,判胜。\r\n  W、S、A、D:控制方块上下左右移动\r\n  F1:截图并保存\r\n  ESC:退出";
                mes1.StartPosition = FormStartPosition.CenterParent;
                mes1.ShowDialog();
                c = new Class1();
                c.Restart();
            }

            //载入音乐与界面
            SoundPlayer player = new SoundPlayer(Directory.GetCurrentDirectory() + @"\music.wav");

            player.PlayLooping();
            draw();
            pictureBox1.Refresh();
        }