Ejemplo n.º 1
0
        private void checkBallCoord(object sender, ElapsedEventArgs eventArgs)
        {
            try
            {
                if (lastFirstCoord != 0 && lastSecondCoord != 0)
                {
                    if (Ball.CoordY >= PlayPictureBox.Height || Ball.CoordY <= 0)
                    {
                        Ball.SpeedY = -Ball.SpeedY;
                    }
                    if (Ball.CoordX < leftPlatform.Figure.X || Ball.CoordX > rightPlatform.Figure.X)
                    {
                        checkTimer.Stop();
                        speedUpTimer.Stop();
                        if (Ball.CoordX < leftPlatform.Figure.X)
                        {
                            rightWins += 1;
                        }
                        else
                        {
                            leftWins += 1;
                        }
                        LeftWinsLabel.Invoke(new Action(() => LeftWinsLabel.Text   = leftWins.ToString()));
                        RightWinsLabel.Invoke(new Action(() => RightWinsLabel.Text = rightWins.ToString()));
                    }

                    //check on ping leftPlatform
                    if (((Ball.CoordX - Ball.Size * 2) < (leftPlatform.Figure.X + Platform.Width) &&
                         (Ball.CoordY <= (leftPlatform.Figure.Y + Platform.Height + epsPlatform) && Ball.CoordY >= (leftPlatform.Figure.Y - epsPlatform))))
                    {
                        if ((Ball.CoordY > leftPlatform.Figure.Y + Platform.Height / 2 && Ball.SpeedY < 0) ||
                            Ball.CoordY <= leftPlatform.Figure.Y + Platform.Height / 2 && Ball.SpeedY > 0)
                        {
                            Ball.SpeedY = -Ball.SpeedY;
                        }
                        Ball.SpeedX = -Ball.SpeedX;
                    }

                    //check on ping rightPlatform
                    if (((Ball.CoordX + Ball.Size * 2) > (rightPlatform.Figure.X - Platform.Width) &&
                         (Ball.CoordY <= (rightPlatform.Figure.Y + Platform.Height + epsPlatform) && Ball.CoordY >= (rightPlatform.Figure.Y - epsPlatform))))   //check on ping rightPlatform
                    {
                        if ((Ball.CoordY > rightPlatform.Figure.Y + Platform.Height / 2 && Ball.SpeedY < 0) ||
                            Ball.CoordY <= rightPlatform.Figure.Y + Platform.Height / 2 && Ball.SpeedY > 0)
                        {
                            Ball.SpeedY = -Ball.SpeedY;
                        }

                        Ball.SpeedX = -Ball.SpeedX;
                    }
                    Ball.MoveByX();
                    Ball.MoveByY();
                }
            }
            catch
            {
                checkTimer.Stop();
                speedUpTimer.Stop();
            }
        }