Beispiel #1
2
        /// <summary>
        /// Take a swing on the course, with the specified angle and velocity.
        ///		Exceptions:
        ///			AngleInvalidException
        /// </summary>
        /// <param name="angle">angle of the launch</param>
        /// <param name="velocity">speed of the ball</param>
        public void Swing(double angle, double velocity)
        {
            // Create the swing object, with the angle and velocity provided
            Swing swing = new Swing(angle, velocity, this);

            // Add the swing to the list
            Swings.Add(swing);

            // Increment the Swing Counter
            this.SwingCounter++;

            // If the distance to the hole is less than the tolerance,
            // the player has won, so end the course.
            if (this.DistanceFromHole            // distance
                <= Course.Tolerance /* tolerance */)
            {
                this.HasEnded = true;
                this.HasWon   = true;

                // If the distance is greater than the total distance plus the rough,
                // the player is out of bounds, so end the course in failure
            }
            else if (this.DistanceFromHole > (CourseLength + CourseRough))
            {
                this.IsOutOfBounds = true;
                this.HasEnded      = true;
                this.HasLost       = true;
            }
        }
Beispiel #2
0
        public void Swing(double angle, double velocity)
        {
            // Skapa svingen med hjälp av vinkeln och styrkan
            Swing swing = new Swing(angle, velocity, this);

            // Lägger till svingen till listan
            Swings.Add(swing);

            // Ökar slagräknaren
            this.SwingCounter++;

            // Ifall vi är inom tolleransen av vad som är att bollen är i hålet
            if (this.DistanceFromHole
                <= Course.Tolerance)
            {
                this.HasEnded = true;
                this.HasWon   = true;

                // Ifall bollen har flugit utanför gränsen
            }
            else if (this.DistanceFromHole > (CourseLength + CourseRough))
            {
                this.IsOutOfBounds = true;
                this.HasEnded      = true;
                this.HasLost       = true;
            }
        }
Beispiel #3
0
        public void SimulateSwing()
        {
            double distance       = 0;
            double angleInRadians = (Math.PI / 180) * Angle;


            distance = Convert.ToDouble(Math.Pow(Velocity, 2) / _gravity * Math.Sin(2 * angleInRadians));
            Swing swing = new Swing(Angle, Velocity, distance);

            Swings.Add(swing);
            TotalDistanceTravelled = TotalDistanceTravelled + distance;
            StopCondition          = DistanceToCup - TotalDistanceTravelled;
            NoOfSwings++;
            SendSwingInfoToUser(distance);
        }
Beispiel #4
0
        public void Swing(double angle, double velocity)
        {
            Swing swing = new Swing(angle, velocity, this);

            Swings.Add(swing);
            this.SwingCounter++;
            if (this.DistanceFromHole <= Ball.Tolerance)
            {
                this.Ended = true;
                this.Won   = true;
            }
            else if (this.DistanceFromHole > Rough)
            {
                this.IsOutOfBounds = true;
                this.Ended         = true;
                this.Lost          = true;
            }
        }