Esempio n. 1
0
    //  Event handling method for the "Reset" button
    public void ResetButtonClicked(object source, EventArgs e)
    {
        //  stop the timer.
        gameTimer.Stop();

        //  Reset the time, location, and velocity of ball;
        basketball.S = 0.0;       //  time
        basketball.SetQ(0.0, 0);  //  vx0
        basketball.SetQ(1.0, 1);  //  x0
        basketball.SetQ(0.0, 2);  //  vy0
        basketball.SetQ(0.0, 3);  //  y0
        basketball.SetQ(0.0, 4);  //  vz0
        basketball.SetQ(2.25, 5); //  z0
        shotMade = false;

        //  Update the display.
        UpdateDisplay();
    }
Esempio n. 2
0
    //  Event handling method for the "Reset" button
    public void ResetButtonClicked(object source, EventArgs e)
    {
        //  stop the timer.
        gameTimer.Stop();

        //  Reset the time, location, and velocity of ball;
        golfball.S = 0.0;      //  time
        golfball.SetQ(0.0, 0); //  vx0
        golfball.SetQ(0.0, 1); //  x0
        golfball.SetQ(0.0, 2); //  vy0
        golfball.SetQ(0.0, 3); //  y0
        golfball.SetQ(0.0, 4); //  vz0
        golfball.SetQ(0.0, 5); //  z0

        //  Reset the distance to hole.
        distanceToHole = Convert.ToDouble(distanceTextBox.Text);

        //  Update the display.
        UpdateDisplay();
    }
Esempio n. 3
0
    public FreeThrow()
    {
        //  Create a DragProjectile object to represent the soccer ball.
        basketball =
            new DragProjectile(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
                               0.62, 0.0452, 1.2, 0.5);
        basketball.SetQ(1.0, 1);  //  x0
        basketball.SetQ(2.25, 5); //  z0

        //  The shot is missed until it is made
        shotMade = false;

        //  Set up images
        playerIcon   = Image.FromFile("basketball_player.gif");
        playerWidth  = playerIcon.Width;
        playerHeight = playerIcon.Height;
        ballIcon     = Image.FromFile("Basketball.jpg");

        //  Create a Timer object that will be used
        //  to slow the action down.
        gameTimer          = new Timer();
        gameTimer.Interval = 20; //  delay in milliseconds.
        gameTimer.Tick    += new EventHandler(ActionPerformed);

        //  Create some Labels
        velocityLabel       = new Label();
        velocityLabel.Text  = "Initial velocity (m/s)";
        velocityLabel.Font  = new Font(velocityLabel.Font, FontStyle.Bold);
        velocityLabel.Top   = 20;
        velocityLabel.Left  = 10;
        velocityLabel.Width = 120;

        angleLabel       = new Label();
        angleLabel.Text  = "Shot angle (deg)";
        angleLabel.Font  = new Font(angleLabel.Font, FontStyle.Bold);
        angleLabel.Top   = 50;
        angleLabel.Left  = 10;
        angleLabel.Width = 120;

        //  Create TextBox objects to display the inputs.
        velocityTextBox          = new TextBox();
        velocityTextBox.Width    = 50;
        velocityTextBox.Text     = "7.5";
        velocityTextBox.AutoSize = true;
        velocityTextBox.Top      = velocityLabel.Top;
        velocityTextBox.Left     = 140;

        angleTextBox          = new TextBox();
        angleTextBox.Width    = 50;
        angleTextBox.Text     = "40.0";
        angleTextBox.AutoSize = true;
        angleTextBox.Top      = angleLabel.Top;
        angleTextBox.Left     = 140;

        //  Create Button objects
        int buttonHeight = 30;
        int buttonWidth  = 50;
        int buttonLeft   = 20;

        fireButton        = new Button();
        fireButton.Text   = "Fire";
        fireButton.Height = buttonHeight;
        fireButton.Width  = buttonWidth;
        fireButton.Top    = 80;
        fireButton.Left   = buttonLeft;
        fireButton.Click += new EventHandler(FireButtonClicked);

        resetButton        = new Button();
        resetButton.Text   = "Reset";
        resetButton.Height = buttonHeight;
        resetButton.Width  = buttonWidth;
        resetButton.Top    = 130;
        resetButton.Left   = buttonLeft;
        resetButton.Click += new EventHandler(ResetButtonClicked);

        //  Create a drawing panel.
        drawingPanel             = new Panel();
        drawingPanel.Width       = 301;
        drawingPanel.Height      = 251;
        drawingPanel.Left        = 300;
        drawingPanel.Top         = 20;
        drawingPanel.BorderStyle = BorderStyle.FixedSingle;

        //  Add the GUI components to the Form
        this.Controls.Add(velocityLabel);
        this.Controls.Add(angleLabel);
        this.Controls.Add(velocityTextBox);
        this.Controls.Add(angleTextBox);
        this.Controls.Add(fireButton);
        this.Controls.Add(resetButton);
        this.Controls.Add(drawingPanel);

        // Set the size and title of the form
        this.Width  = 650;
        this.Height = 400;
        this.Text   = "Free Throw";

        //  Center the form on the screen and make
        //  it visible.
        this.StartPosition = FormStartPosition.CenterScreen;
        this.Visible       = true;

        //  Update the GUI display
        UpdateDisplay();
    }