예제 #1
0
 private void frmPacmanGame_KeyDown(object sender, KeyEventArgs e)
 {
     if (game.State == GameState.GAMEPAUSE)
     {
         game.Continue();
     }
     //game.RePaint();
     //game.KeyDown(e);
     if (game == null)
     {
         return;
     }
     if (e.KeyCode == Keys.Left)
     {
         game.setDirection(Direction.LEFT);
     }
     else if (e.KeyCode == Keys.Right)
     {
         game.setDirection(Direction.RIGHT);
     }
     else if (e.KeyCode == Keys.Up)
     {
         game.setDirection(Direction.UP);
     }
     else if (e.KeyCode == Keys.Down)
     {
         game.setDirection(Direction.DOWN);
     }
     else if (e.KeyCode == Keys.Subtract)
     {
         game.PacmanDelay += 5;
         game.GhostDelay  += 5;
     }
     else if (e.KeyCode == Keys.Add)
     {
         game.PacmanDelay -= 5;
         game.GhostDelay  -= 5;
     }
     else if (e.KeyCode == Keys.P)
     {
         if (game.State == GameState.GAMERUN)
         {
             game.Pause();
         }
         else if (game.State == GameState.GAMEPAUSE)
         {
             game.Continue();
         }
     }
 }
예제 #2
0
 private void frmPacmanGame_KeyDown(object sender, KeyEventArgs e)
 {
     if (game == null)
     {
         return;
     }
     if (e.KeyCode == Keys.Left)
     {
         game.SetDirection(Direction.LEFT);
     }
     else if (e.KeyCode == Keys.Right)
     {
         game.SetDirection(Direction.RIGHT);
     }
     else if (e.KeyCode == Keys.Up)
     {
         game.SetDirection(Direction.UP);
     }
     else if (e.KeyCode == Keys.Down)
     {
         game.SetDirection(Direction.DOWN);
     }
     else if (e.KeyCode == Keys.F12)
     {
         cheatEnabled = true;
     }
     else if (e.KeyCode == Keys.F1)
     {
         if (cheatEnabled)
         {
             game.Cheat();
         }
     }
     else if (e.KeyCode == Keys.D1)
     {
         game.coinInserted(true);
     }
     else if (e.KeyCode == Keys.D2)
     {
         if (cheatEnabled)
         {
             game.cheatFruit(true);
         }
     }
     else if (e.KeyCode == Keys.Enter)
     {
         if (game.State == GameState.GAMERUN)
         {
             game.State = GameState.GAMEPAUSE;
             bool result = (MessageBox.Show("Do You want to reset the game?",
                                            "Reset?",
                                            MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes);
             if (result)
             {
                 game.Reset();
             }
         }
         else
         {
             game.Reset();
         }
     }
     else if (e.KeyCode == Keys.Subtract)
     {
         game.PacmanDelay += 5;
         game.GhostDelay  += 5;
     }
     else if (e.KeyCode == Keys.Add)
     {
         game.PacmanDelay -= 5;
         game.GhostDelay  -= 5;
     }
     else if (e.KeyCode == Keys.P || e.KeyCode == Keys.Space)
     {
         if (game.State == GameState.GAMERUN)
         {
             game.Pause();
         }
         else if (game.State == GameState.GAMEPAUSE)
         {
             game.Continue();
         }
     }
 }