Ejemplo n.º 1
0
        private void Form1_KeyDown(object sender, KeyEventArgs e)  //各按键对应的响应,每次按键后刷新界面、判断胜负
        {
            switch (e.KeyCode)
            {
            case Keys.W:
                c.Up();
                if (c.change)            //成功移动便随机一个位置添加数字,下同
                {
                    c.Add();
                }
                break;

            case Keys.S:
                c.Down();
                if (c.change)
                {
                    c.Add();
                }
                break;

            case Keys.A:
                c.Left();
                if (c.change)
                {
                    c.Add();
                }
                break;

            case Keys.D:
                c.Right();
                if (c.change)
                {
                    c.Add();
                }
                break;

            case Keys.F1:
                Screen();
                message mes3 = new message();
                mes3.a             = "Saved successfully!";
                mes3.b             = "保存位置:" + Directory.GetCurrentDirectory() + "\\screenshot.png";
                mes3.StartPosition = FormStartPosition.CenterParent;
                mes3.ShowDialog();
                break;

            case Keys.Escape:
                this.Close();
                break;
            }
            draw();
            pictureBox1.Refresh();
            score.Text = c.score.ToString();
            for (int x = 1; x <= 4; x++)
            {
                for (int y = 1; y <= 4; y++)
                {
                    if (c.i[x, y] == 2048 && c.First2048 == true)
                    {
                        isWin();
                        c.First2048 = false;
                    }
                }
            }
            if (c.die)
            {
                Gameover();
            }
        }