コード例 #1
0
        private void newGame_Click(object sender, EventArgs e)
        {
            CityRush newForm = new CityRush();

            newForm.StartPosition = FormStartPosition.Manual;
            newForm.Location      = this.Location;
            newForm.Visible       = true;
            this.Dispose(false);
            newForm.startGame();
        }
コード例 #2
0
        private async void CityRush_KeyDown(object sender, KeyEventArgs e)
        {
            if (gameStarted)

            {
                if (e.KeyCode == Keys.Escape)
                {
                    if (!gameOver)
                    {
                        if (!gamePaused)
                        {
                            timer1.Stop();
                            countdownTimer.Stop();
                            gamePaused        = true;
                            lblStatus.Visible = true;
                            lblStatus.Text    = "    PAUSED";
                            //label4.Text = "pause!!!!";
                        }
                        else
                        {
                            timer1.Start();
                            countdownTimer.Start();
                            gamePaused     = false;
                            lblStatus.Text = "";
                            //label4.Text = "unpause";
                        }
                    }
                    else
                    {
                        CityRush newForm = new CityRush();
                        newForm.StartPosition = FormStartPosition.Manual;
                        newForm.Location      = this.Location;
                        newForm.Visible       = true;
                        this.Dispose(false);
                    }
                }

                if (e.KeyCode == Keys.Left && mainCar.Left == 522 && !gamePaused && !gameOver)
                {
                    mainCar.Left -= 320;
                }
                if (e.KeyCode == Keys.Right && mainCar.Left == 202 && !gamePaused && !gameOver)
                {
                    mainCar.Left += 320;
                }
                if (e.KeyCode == Keys.Up && speed < 25)
                {
                    speed++;
                }
                if (e.KeyCode == Keys.Down && speed > 8)
                {
                    speed--;
                }
                if (e.KeyCode == Keys.Space && mainCar.Top == 477)
                {
                    //space unpause disabled
                    if (gamePaused || gameOver)
                    {
                        e.SuppressKeyPress = true;
                    }
                    else
                    {
                        jumped = true;

                        for (int i = 0; i < 50; i++)
                        {
                            await Task.Delay(8000 / (speed * 100));//ne e najoptimalna formula

                            mainCar.Top -= 1;
                        }

                        for (int i = 0; i < 50; i++)
                        {
                            await Task.Delay(8000 / (speed * 100));

                            mainCar.Top += 1;
                        }

                        jumped = false;
                    }
                }
            }
        }