Exemplo n.º 1
0
 private void Form_KeyDown(object sender, KeyEventArgs e)
 {
     if (status == Status.playing)
     {
         if (GameKeys.interpret(e.KeyCode) == GameBehaviors.pause)
         {
             gameTimer.Stop();
             animationTimer.Stop();
             status = Status.pause;
         }
     }
     else if (status == Status.pause)
     {
         if (GameKeys.interpret(e.KeyCode) == GameBehaviors.pause)
         {
             gameTimer.Start();
             animationTimer.Start();
             status = Status.playing;
         }
     }
     if (!keysPressed.Contains(e.KeyCode))
     {
         keysPressed.Add(e.KeyCode);
     }
 }
Exemplo n.º 2
0
        private void Form_KeyUp(object sender, KeyEventArgs e)
        {
            if (GameKeys.interpret(e.KeyCode) == GameBehaviors.quit)
            {
                System.Environment.Exit(0);
            }
            if (status == Status.beginning)
            {
                welcomeShutDown();
            }

            keysPressed.RemoveAll(k => k == e.KeyCode);
        }
Exemplo n.º 3
0
        private void gameTimer_Tick(object sender, EventArgs e)
        {
            game.go();
            if (this.status == Status.playing)
            {
                foreach (Keys i in keysPressed)
                {
                    switch (GameKeys.interpret(i))
                    {
                    case GameBehaviors.moveUp:
                        game.movePlayer(Direction.up);
                        break;

                    case GameBehaviors.moveDown:
                        game.movePlayer(Direction.down);
                        break;

                    case GameBehaviors.moveLeft:
                        game.movePlayer(Direction.left);
                        break;

                    case GameBehaviors.moveRight:
                        game.movePlayer(Direction.right);
                        break;

                    case GameBehaviors.shot:
                        game.shot();
                        break;



                    default:
                        break;
                    }
                }
            }


            this.playerShip.Location = game.getPlayerPoisition();
            this.currentScore.Text   = game.currentScore.ToString();
            this.playerLife.Text     = "X" + game.getPlayerLife().ToString();

            this.Refresh();
        }