Пример #1
0
        private void Form1_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Up || e.KeyCode == Keys.Down || e.KeyCode == Keys.Left || e.KeyCode == Keys.Right)
            {
                //备份,用于恢复上一步
                for (int i = 0; i < 4; i++)
                {
                    for (int j = 0; j < 4; j++)
                    {
                        old_qz[i, j] = qz[i, j].Value;
                    }
                }

                //开始合并
                bool b = false;
                switch (e.KeyCode)
                {
                case Keys.Up:
                    b = CL.up(qz);
                    break;

                case Keys.Down:
                    b = CL.down(qz);
                    break;

                case Keys.Left:
                    b = CL.left(qz);
                    break;

                case Keys.Right:
                    b = CL.right(qz);
                    break;
                }

                if (b)
                {
                    this.scores.Text     = (int.Parse(this.scores.Text) + CL.Score).ToString();//计算总得分
                    this.restore.Enabled = true;

                    CL.zj(qz);         //增加一粒棋子
                    if (CL.isover(qz)) //判断是否结束
                    {
                        MessageBox.Show("游戏结束,你的得分是" + this.scores.Text + "。", "提示");
                        this.reset_Click(sender, e);
                    }
                }
            }
        }
Пример #2
0
        private void start()
        {
            RegistryHelper rh = new RegistryHelper();

            //是否修改最高得分
            if (int.Parse(this.scores.Text) > int.Parse(this.maxScores.Text))
            {
                rh.SetRegistryData(Registry.CurrentUser, "SOFTWARE\\2048", "MaxScores", this.scores.Text);
                this.maxScores.Text = this.scores.Text;
            }

            //重置界面
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    qz[i, j].Value = 0;
                }
            }
            this.restore.Enabled = false;
            this.scores.Text     = "0";
            CL.zj(qz);
            CL.zj(qz);
        }