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

        //  Reset the bagBall
        bBall = new bagBall(0.5, 1.7, 0.0, 0.0, 0.0);

        //  Update the display.
        UpdateDisplay();
    }
Exemplo n.º 2
0
    //  Event handling method for the "Fire" button
    public void FireButtonClicked(object source, EventArgs e)
    {
        //  Extract initial data from the textfields.
        double vx0 = Convert.ToDouble(vxTextBox.Text);
        double vz0 = Convert.ToDouble(vzTextBox.Text);

        bBall = new bagBall(0.5, 1.7, vx0, vz0, 0.0);

        //  Start the box sliding using a Timer object
        //  to slow down the action.
        gameTimer.Start();
    }
Exemplo n.º 3
0
    //  Event handling method for the "Reset" button
    public void ResetButtonClicked(object source, EventArgs evt)
    {
        //  stop the timer.
        gameTimer.Stop();
        perdut = false;

        //  Reset the ball location, velocity, and
        //  paddle location.
        pilota  = new bagBall(100, 100, 100, -71, 0);
        paddleZ = 100;

        //  Update the display.
        UpdateDisplay();
    }
Exemplo n.º 4
0
    //  Event handling method for the "Start" button
    public void StartButtonClicked(object source, EventArgs evt)
    {
        //  Extract initial data from the textfields.
        double ballVx = Convert.ToDouble(vxTextBox.Text);
        double ballVz = Convert.ToDouble(vzTextBox.Text);

        pilota = new bagBall(100, 100, ballVx, ballVz, 0);

        //  Update the display
        perdut = false;
        UpdateDisplay();

        //  Start the box sliding using a Timer object
        //  to slow down the action.
        gameTimer.Start();
    }
Exemplo n.º 5
0
    public PaddleGame()
    {
        //  Initialize ball location, velocity, and
        //  paddle location.
        pilota       = new bagBall(100, 100, 100, -71, 0);
        ballRadius   = 5.0;
        paddleZ      = 100;
        paddleHeight = 40;

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

        //  Create some Labels
        vxLabel       = new Label();
        vxLabel.Text  = "x-velocity, m/s";
        vxLabel.Font  = new Font(vxLabel.Font, FontStyle.Bold);
        vxLabel.Top   = 30;
        vxLabel.Left  = 10;
        vxLabel.Width = 100;

        vzLabel       = new Label();
        vzLabel.Text  = "z-velocity, m/s";
        vzLabel.Font  = new Font(vzLabel.Font, FontStyle.Bold);
        vzLabel.Top   = 60;
        vzLabel.Left  = 10;
        vzLabel.Width = 100;

        //  Create TextBox objects to display the outcome.
        vxTextBox          = new TextBox();
        vxTextBox.Width    = 60;
        vxTextBox.Text     = String.Format("{0}", 100.0m);
        vxTextBox.AutoSize = true;
        vxTextBox.Top      = vxLabel.Top;
        vxTextBox.Left     = 110;

        vzTextBox          = new TextBox();
        vzTextBox.Width    = 60;
        vzTextBox.Text     = String.Format("{0}", -80.0m);
        vzTextBox.AutoSize = true;
        vzTextBox.Top      = vzLabel.Top;
        vzTextBox.Left     = 110;

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

        startButton        = new Button();
        startButton.Text   = "Start";
        startButton.Height = buttonHeight;
        startButton.Width  = buttonWidth;
        startButton.Top    = 30;
        startButton.Left   = 200;
        startButton.Click += new EventHandler(StartButtonClicked);

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

        //  Create a drawing panel.
        drawingPanel             = new Panel();
        drawingPanel.Width       = 301;
        drawingPanel.Height      = 201;
        drawingPanel.Left        = 130;
        drawingPanel.Top         = 110;
        drawingPanel.BorderStyle = BorderStyle.FixedSingle;
        drawingPanel.MouseDown  += new MouseEventHandler(MovePaddle);

        //  Add the GUI components to the Form
        this.Controls.Add(vxLabel);
        this.Controls.Add(vzLabel);
        this.Controls.Add(vxTextBox);
        this.Controls.Add(vzTextBox);
        this.Controls.Add(startButton);
        this.Controls.Add(resetButton);
        this.Controls.Add(drawingPanel);

        // Set the size and title of the form
        this.Width  = 500;
        this.Height = 350;
        this.Text   = "PaddleGame";

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

        //  Update the GUI display
        UpdateDisplay();
    }
Exemplo n.º 6
0
    public BeanBag()
    {
        //  Initialize the beanbag parameters.
        bBall = new bagBall(0.5, 1.7, 0.0, 0.0, 0.0);

        //  Set up images
        playerIcon = Image.FromFile("tiuquetiraelsac.jpg");

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

        //  Create some Labels
        vxLabel       = new Label();
        vxLabel.Text  = "Initial horizontal velocity, m/s";
        vxLabel.Font  = new Font(vxLabel.Font, FontStyle.Bold);
        vxLabel.Top   = 30;
        vxLabel.Left  = 10;
        vxLabel.Width = 180;

        vzLabel       = new Label();
        vzLabel.Text  = "Initial vertical velocity, m/s";
        vzLabel.Font  = new Font(vzLabel.Font, FontStyle.Bold);
        vzLabel.Top   = 60;
        vzLabel.Left  = 10;
        vzLabel.Width = 180;

        //  Create TextBox objects to display the outcome.
        vxTextBox          = new TextBox();
        vxTextBox.Width    = 50;
        vxTextBox.Text     = String.Format("{0}", 2.5m);
        vxTextBox.AutoSize = true;
        vxTextBox.Top      = vxLabel.Top;
        vxTextBox.Left     = 200;

        vzTextBox          = new TextBox();
        vzTextBox.Width    = 50;
        vzTextBox.Text     = String.Format("{0}", 2.0m);
        vzTextBox.AutoSize = true;
        vzTextBox.Top      = vzLabel.Top;
        vzTextBox.Left     = 200;

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

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

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

        //  Create a drawing panel.
        drawingPanel             = new Panel();
        drawingPanel.Width       = 251;
        drawingPanel.Height      = 151;
        drawingPanel.Left        = 280;
        drawingPanel.Top         = 50;
        drawingPanel.BorderStyle = BorderStyle.FixedSingle;

        //  Add the GUI components to the Form
        this.Controls.Add(vxLabel);
        this.Controls.Add(vzLabel);
        this.Controls.Add(vxTextBox);
        this.Controls.Add(vzTextBox);
        this.Controls.Add(fireButton);
        this.Controls.Add(resetButton);
        this.Controls.Add(drawingPanel);

        // Set the size and title of the form
        this.Height = 300;
        this.Width  = 600;
        this.Text   = "Beanbag Game";

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

        //  Update the GUI display
        UpdateDisplay();
    }