Exemple #1
0
        private void Form1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            string result = e.KeyData.ToString();

            Invalidate(TheEater.GetFrame());
            switch (result)
            {
            case "Left":
                TheEater.MoveLeft(ClientRectangle);
                Invalidate(TheEater.GetFrame());
                break;

            case "Right":
                TheEater.MoveRight(ClientRectangle);
                Invalidate(TheEater.GetFrame());
                break;

            case "Up":
                TheEater.MoveUp(ClientRectangle);
                Invalidate(TheEater.GetFrame());
                break;

            case "Down":
                TheEater.MoveDown(ClientRectangle);
                Invalidate(TheEater.GetFrame());
                break;

            default:
                break;
            }

            int hit = CheckIntersection();

            if (hit != -1)
            {
                TheScore.Increment();

                PlaySoundInThread("hit.wav");
                Invalidate(TheScore.GetFrame());
                Invalidate(((Stone)Stones[hit]).GetFrame());
                Stones.RemoveAt(hit);
                if (Stones.Count == 0)
                {
                    MessageBox.Show("ÄãÓ®ÁË£¡\nÓÃʱ " + TheTime.TheString + "Ãë¡£", "³Ô¶¹×ÓÓÎÏ·");
                    Application.Exit();
                }
            }
        }
Exemple #2
0
        private void HandleLatestKey()
        {
            if (m_bGameDone)
            {
                return;                  // precondition
            }
//			string result = e.KeyData.ToString();
            string result = LatestKey;

            Invalidate(TheEater.GetFrame());
            switch (result)
            {
            case "Left":
                if (CanEaterMove(Side.left))
                {
                    TheEater.MoveLeft(ClientRectangle);
                }
                Invalidate(TheEater.GetFrame());
                break;

            case "Right":
                if (CanEaterMove(Side.right))
                {
                    TheEater.MoveRight(ClientRectangle);
                }
                Invalidate(TheEater.GetFrame());
                break;

            case "Up":
                if (CanEaterMove(Side.top))
                {
                    TheEater.MoveUp(ClientRectangle);
                }
                Invalidate(TheEater.GetFrame());
                break;

            case "Down":
                if (CanEaterMove(Side.bottom))
                {
                    TheEater.MoveDown(ClientRectangle);
                }
                Invalidate(TheEater.GetFrame());
                break;

            default:
                break;
            }

            int hit = CheckIntersection();

            if (hit != -1)
            {
                TheScore.Increment();

                PlaySoundInThread("hit.wav");
                Invalidate(TheScore.GetFrame());
                Invalidate(((Stone)Stones[hit]).GetFrame());
                Stones.RemoveAt(hit);
                if (Stones.Count == 0)
                {
                    MessageBox.Show("You Win!\nYour time is " + TheTime.TheString + " seconds.");
                    Application.Exit();
                }
            }
        }