Esempio n. 1
0
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Q)
            {
                Application.Exit();
            }

            //press escape to pause game
            if (e.KeyCode == Keys.Escape)
            {
                pause_Interface.Visible = true;
                gameTimer.Stop();
            }

            if (e.KeyCode == Keys.S)
            {
                // code to reset the game
                gameOver       = false;
                game           = new Game(random, FormArea);
                game.GameOver += new EventHandler(game_GameOver);
                gameTimer.Start();
                return;
            }
            if (e.KeyCode == Keys.Space)
            {
                game.FireShot();
            }
            if (keysPressed.Contains(e.KeyCode))
            {
                keysPressed.Remove(e.KeyCode);
            }
            keysPressed.Add(e.KeyCode);
        }
Esempio n. 2
0
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Q)
            {
                Application.Exit();
            }
            if (e.KeyCode == Keys.S)
            {
                // code to reset the game
                gameOver       = false;
                game           = new Game(random, FormArea);
                game.GameOver += new EventHandler(game_GameOver);
                gameTimer.Start();
                return;
            }

            switch (e.KeyCode)
            {
            case Keys.R:
                game.FireShot(2);
                break;

            case Keys.T:
                game.FireShot(4);
                break;

            case Keys.Y:
                game.FireShot(6);
                break;
            }



            if (keysPressed.Contains(e.KeyCode))
            {
                keysPressed.Remove(e.KeyCode);
            }
            keysPressed.Add(e.KeyCode);
        }