示例#1
0
        private void GameScreen_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
        {
            if (e.KeyCode == Keys.Escape && gameTimer.Enabled)
            {
                gameTimer.Enabled = false;

                DialogResult result = PauseScreen.Show();

                if (result == DialogResult.Cancel)
                {
                    gameTimer.Enabled = true;
                }
                else if (result == DialogResult.Abort)
                {
                    MenuScreen.ChangeScreen(this, "MenuScreen");
                }
            }

            //player 1 button presses
            switch (e.KeyCode)
            {
            case Keys.Left:
                leftArrowDown = true;
                direction     = "left";
                break;

            case Keys.Right:
                rightArrowDown = true;
                direction      = "right";
                break;

            case Keys.Space:
                start = true;
                break;

            case Keys.Escape:
                break;

            default:
                break;
            }

            if (!start)
            {
                switch (e.KeyCode)
                {
                case Keys.A:
                    // move left
                    if (angleposition >= 1 && angleposition < 6)
                    {
                        angleposition++;
                    }
                    break;

                case Keys.D:
                    // move right
                    if (angleposition <= 6 && angleposition > 1)
                    {
                        angleposition--;
                    }
                    break;
                }
            }
        }
示例#2
0
        private void LoseScreenMulti_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
        {
            lastIndex = index;

            if (e.KeyCode == Keys.Escape)
            {
                MenuScreen ms   = new MenuScreen();
                Form       form = this.FindForm();

                form.Controls.Add(ms);
                form.Controls.Remove(this);

                ms.Location = new Point((form.Width - ms.Width) / 2, (form.Height - ms.Height) / 2);
            }

            switch (e.KeyCode)
            {
            case Keys.Right:
                if (index != 0)
                {
                    index--;
                }
                else
                {
                    index = 1;
                }
                break;

            case Keys.Left:
                if (index != 1)
                {
                    index++;
                }
                else
                {
                    index = 0;
                }
                break;

            case Keys.Space:
                switch (index)
                {
                case 0:
                    Form       f  = this.FindForm();
                    MenuScreen ms = new MenuScreen();

                    ms.Location = new Point((f.Width - ms.Width) / 2, (f.Height - ms.Height) / 2);

                    f.Controls.Add(ms);
                    f.Controls.Remove(this);

                    break;

                case 1:
                    Form            form = this.FindForm();
                    GameScreenMulti gsm  = new GameScreenMulti();

                    gsm.Location = new Point((form.Width - gsm.Width) / 2, (form.Height - gsm.Height) / 2);

                    form.Controls.Add(gsm);
                    form.Controls.Remove(this);

                    break;
                }
                break;
            }


            switch (lastIndex)
            {
            case 0:
                returnToMenuLabel.ForeColor = Color.White;
                break;

            case 1:
                playAgainLabel.ForeColor = Color.White;
                break;
            }

            switch (index)
            {
            case 0:
                returnToMenuLabel.ForeColor = Color.Red;
                break;

            case 1:
                playAgainLabel.ForeColor = Color.Red;
                break;
            }
        }