コード例 #1
0
        //Key Detection
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (lost == false)
            {
                if (pause == false)
                {
                    if (e.KeyCode == Keys.W)
                    {
                        MoveUpTimer.Start();

                        MoveDownTimer.Stop();
                        MoveLeftTimer.Stop();
                        MoveRightTimer.Stop();
                    }
                    if (e.KeyCode == Keys.A)
                    {
                        MoveLeftTimer.Start();

                        MoveUpTimer.Stop();
                        MoveDownTimer.Stop();
                        MoveRightTimer.Stop();
                    }
                    if (e.KeyCode == Keys.S)
                    {
                        MoveDownTimer.Start();

                        MoveUpTimer.Stop();
                        MoveLeftTimer.Stop();
                        MoveRightTimer.Stop();
                    }
                    if (e.KeyCode == Keys.D)
                    {
                        MoveRightTimer.Start();

                        MoveUpTimer.Stop();
                        MoveDownTimer.Stop();
                        MoveLeftTimer.Stop();
                    }
                }
            }
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: balee323/TeachingCode
 //KeyDown Event Handler
 private void SpaceForm_KeyDown(object sender, KeyEventArgs e)
 {
     if (!pause)
     {
         if (e.KeyCode == Keys.Right)
         {
             MoveRigthTimer.Start();
         }
         if (e.KeyCode == Keys.Left)
         {
             MoveLeftTimer.Start();
         }
         if (e.KeyCode == Keys.Down)
         {
             MoveDownTimer.Start();
         }
         if (e.KeyCode == Keys.Up)
         {
             MoveTopTimer.Start();
         }
     }
 }