Esempio n. 1
0
 //键盘事件
 private void Key_Event(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Left)
     {
         current.MoveLeft();
         if (!game.BorderCheck(current) || !game.CollideCheck(current, canvus))
         {
             current.MoveRight();
         }
     }
     else if (e.KeyCode == Keys.Right)
     {
         current.MoveRight();
         if (!game.BorderCheck(current) || !game.CollideCheck(current, canvus))
         {
             current.MoveLeft();
         }
     }
     else if (e.KeyCode == Keys.Up)
     {
         current.ClockwiseRotation();
         if (!game.BorderCheck(current) || !game.CollideCheck(current, canvus))
         {
             current.AnticlockwiseRotation();
         }
     }
     else if (e.KeyCode == Keys.Down)
     {
         if (game.MoveDownCheck(current, canvus))
         {
             current.MoveDown();
         }
     }
     else if (e.KeyCode == Keys.Escape && !stop)
     {
         stop           = !stop;
         timer1.Enabled = false;
         panel1.Visible = true;
         panel1.Enabled = true;
     }
     SendCurrent();
     pictureBox1.Refresh();
     All_Paint(pe);
 }
Esempio n. 2
0
 /// <summary>
 /// 键盘监听
 /// </summary>
 private void LocalDoubleForm_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.A)
     {
         lcurrent.MoveLeft();
         if (!lgame.BorderCheck(lcurrent) || !lgame.CollideCheck(lcurrent, lcanvus))
         {
             lcurrent.MoveRight();
         }
     }
     else if (e.KeyCode == Keys.D)
     {
         lcurrent.MoveRight();
         if (!lgame.BorderCheck(lcurrent) || !lgame.CollideCheck(lcurrent, lcanvus))
         {
             lcurrent.MoveLeft();
         }
     }
     else if (e.KeyCode == Keys.W)
     {
         lcurrent.ClockwiseRotation();
         if (!lgame.BorderCheck(lcurrent) || !lgame.CollideCheck(lcurrent, lcanvus))
         {
             lcurrent.AnticlockwiseRotation();
         }
     }
     else if (e.KeyCode == Keys.S)
     {
         if (lgame.MoveDownCheck(lcurrent, lcanvus))
         {
             lcurrent.MoveDown();
         }
     }
     pictureBox1.Refresh();
     All_paint(lpe);
     if (e.KeyCode == Keys.Left)
     {
         rcurrent.MoveLeft();
         if (!rgame.BorderCheck(rcurrent) || !rgame.CollideCheck(rcurrent, rcanvus))
         {
             rcurrent.MoveRight();
         }
     }
     else if (e.KeyCode == Keys.Right)
     {
         rcurrent.MoveRight();
         if (!rgame.BorderCheck(rcurrent) || !rgame.CollideCheck(rcurrent, rcanvus))
         {
             rcurrent.MoveLeft();
         }
     }
     else if (e.KeyCode == Keys.Up)
     {
         rcurrent.ClockwiseRotation();
         if (!rgame.BorderCheck(rcurrent) || !rgame.CollideCheck(rcurrent, rcanvus))
         {
             rcurrent.AnticlockwiseRotation();
         }
     }
     else if (e.KeyCode == Keys.Down)
     {
         if (rgame.MoveDownCheck(rcurrent, rcanvus))
         {
             rcurrent.MoveDown();
         }
     }
     else if (e.KeyCode == Keys.Escape && !stop)
     {
         stop           = !stop;
         timer1.Enabled = false;
         panel1.Visible = true;
         panel1.Enabled = true;
     }
     pictureBox2.Refresh();
     All_paint(rpe);
 }