Ejemplo n.º 1
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            score1.Text = $"{player1score}";
            score2.Text = $"{player2score}";

            ball.x += ball.speedX;
            ball.y += ball.speedY;
            gfx.Clear(Color.Black);

            gfx.FillRectangle(Brushes.White, ClientSize.Width / 2, 0, 5, 6000);

            paddle.Draw(gfx);

            paddle2.Draw(gfx);

            ball.Draw(gfx);


            if (ball.x <= 0 || ball.x >= ClientSize.Width)
            {
                if (ball.x <= 0)
                {
                    player2score++;
                }
                else
                {
                    player1score++;
                }
                ball.Reset(ClientSize.Width, ClientSize.Height);
            }
            else
            {
                ball.Move(ClientSize.Width, ClientSize.Height);
            }


            if (player1score > 6)
            {
                MessageBox.Show("Player 1 Won!");
                Close();
            }
            else if (player2score > 6)
            {
                MessageBox.Show("Player 2 Won!");
                Close();
            }


            ball.IntersectsPaddle(paddle, true);
            ball.IntersectsPaddle(paddle2, false);


            pictureBox1.Image = bitmap;
        }