/// <summary>
 /// Generates an initial ball radius from the target ring radius.
 /// </summary>
 /// <param name="targetRingRadius">The radius of the target ring.</param>
 /// <returns>The initial ball radius.</returns>
 public float GenerateInitialBallRadius(float targetRingRadius)
 {
     // The initial ball radius is currently between 1% and 30% of that of
     // the target ring's.
     return(targetRingRadius * RamGenerator.GenerateARamNum(MIN_BALL_RADIUS_AS_PERCENTAGE_OF_TARGET_RING_RADIUS,
                                                            MAX_BALL_RADIUS_AS_PERCENTAGE_OF_TARGET_RING_RADIUS));
 }
示例#2
0
        /// <summary>
        /// PrepareDestinationBalloons is called when the player is going to click on the balloon
        /// that would appears on a random position.
        /// It will set up the game state for the current round.
        /// </summary>
        private void PrepareDestinationBalloon()
        {
            // Save the previous balloon info before it's been updated
            previousBalloonPos  = balloon.transform.localPosition;
            previousBalloonSize = balloon.image.rectTransform.sizeDelta;

            // Generate random x and y values for the random balloon position (local position)
            // Make sure the random position is different from center point (0,0)
            float localX = RamGenerator.GenerateARamNum(MINX, MAXX);
            float localY = RamGenerator.GenerateARamNum(MINY, MAXY);

            while (localX == 0 && localY == 0)
            {
                localX = RamGenerator.GenerateARamNum(MINX, MAXX);
                localY = RamGenerator.GenerateARamNum(MINY, MAXY);
            }


            // Display balloon at the random position (local position)
            balloon.transform.localPosition = new Vector3(localX, localY, 0);

            // Reset destinationClickTime when the balloon appears in ramdom position
            destinationClickTime = 0;

            // Reset the click time timer for the time between clicks
            initClickTime = 0;

            // Toggle the isBalloonInCenter value because The next balloon should appear at the center
            isBalloonInCenter = true;

            // Set the local state variables:
            balloonSize      = balloon.image.rectTransform.sizeDelta.x;
            destinationPoint = new Position2D(localX, localY);
        }
        public override BallRound GenerateDataForRound(float targetRingRadius)
        {
            float initialFastBallRadius   = GenerateInitialBallRadius(targetRingRadius);
            float initialPlayerBallRadius = initialFastBallRadius * RamGenerator.GenerateARamNum(MIN_PLAYER_BALL_RADIUS_AS_PERCENTAGE_OF_FAST_BALL_RADIUS,
                                                                                                 MAX_PLAYER_BALL_RADIUS_AS_PERCENTAGE_OF_FAST_BALL_RADIUS);
            float initialSlowBallRadius = initialPlayerBallRadius * RamGenerator.GenerateARamNum(MIN_SLOW_BALL_RADIUS_AS_PERCENTAGE_OF_FAST_BALL_RADIUS,
                                                                                                 MAX_SLOW_BALL_RADIUS_AS_PERCENTAGE_OF_FAST_BALL_RADIUS);

            float fastBallActualTimeToContact   = GenerateActualTimeToContact();
            float playerBallActualTimeToContact = fastBallActualTimeToContact + RamGenerator.GenerateARamNum(MIN_ADDITIONAL_SECONDS_IN_TIME_TO_CONTACT,
                                                                                                             MAX_ADDITIONAL_SECONDS_IN_TIME_TO_CONTACT);
            float slowBallActualTimeToContact = playerBallActualTimeToContact + RamGenerator.GenerateARamNum(MIN_ADDITIONAL_SECONDS_IN_TIME_TO_CONTACT,
                                                                                                             MAX_ADDITIONAL_SECONDS_IN_TIME_TO_CONTACT);

            BallRound ballRound = new BallRound
            {
                InitialSlowBallRadius   = initialSlowBallRadius,
                InitialPlayerBallRadius = initialPlayerBallRadius,
                InitialFastBallRadius   = initialFastBallRadius,

                SlowBallActualTimeToContact   = slowBallActualTimeToContact,
                PlayerBallActualTimeToContact = playerBallActualTimeToContact,
                FastBallActualTimeToContact   = fastBallActualTimeToContact
            };

            // The ball disappearance time is calculated by taking the
            // fastest time-to-contact ball time, and then
            // subtracting a random value from this.
            ballRound.TimeBeforeDisappearence = Math.Min(ballRound.SlowBallActualTimeToContact,
                                                         ballRound.FastBallActualTimeToContact)
                                                - RamGenerator.GenerateARamNum(MIN_SECONDS_BEFORE_BALL_DISAPPEARANCE,
                                                                               MAX_SECONDS_BEFORE_BALL_DISAPPEARANCE);

            return(ballRound);
        }
示例#4
0
            public void WHEN_GenerateARamNum_THEN_ValuesGeneratedAreWithinRange()
            {
                int actualOutOfRangeCount   = 0;
                int expectedOutOfRangeCount = 0;

                // Run the random boolean generator 1000 times
                for (int i = 0; i < 1000; i++)
                {
                    // Generate a random number between 0 and 0
                    testFloatValue = RamGenerator.GenerateARamNum(1.0f, 100.0f);

                    // Keep track of the occurrences of the number one
                    if (testFloatValue < 1.0 || testFloatValue > 100.0)
                    {
                        actualOutOfRangeCount += 1;
                    }
                }
                Assert.IsTrue(actualOutOfRangeCount == expectedOutOfRangeCount, "Invalid number generated from GenerateARamNum");
            }
示例#5
0
            public void WHEN_GenerateARamNumLowerEqualUpperBound_THEN_Only1NumGenerated()
            {
                int actualOnesCount   = 0;
                int expectedOnesCount = 1000;

                // Run the random boolean generator 1000 times
                for (int i = 0; i < 1000; i++)
                {
                    // Generate a random number between 0 and 0
                    testFloatValue = RamGenerator.GenerateARamNum(1.0f, 1.0f);

                    // Keep track of the occurrences of the number one
                    if (testFloatValue == 1.0)
                    {
                        actualOnesCount += 1;
                    }
                }
                Assert.IsTrue(actualOnesCount == expectedOnesCount, "Invalid number generated from GenerateARamNum");
            }
示例#6
0
            public void WHEN_GenerateARamNum_THEN_ValuesGeneratedEqually()
            {
                resultIntList = new List <int>()
                {
                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0
                };

                // Run the random boolean generator 1000 times
                for (int i = 0; i < 1000; i++)
                {
                    // Generate a random number between 0 and 10
                    testFloatValue = RamGenerator.GenerateARamNum(1, 11);
                    // Keep track of the occurrences of each number
                    if (testFloatValue < 2)
                    {
                        resultIntList[0] += 1;
                    }
                    else if (testFloatValue < 3)
                    {
                        resultIntList[1] += 1;
                    }
                    else if (testFloatValue < 4)
                    {
                        resultIntList[2] += 1;
                    }
                    else if (testFloatValue < 5)
                    {
                        resultIntList[3] += 1;
                    }
                    else if (testFloatValue < 6)
                    {
                        resultIntList[4] += 1;
                    }
                    else if (testFloatValue < 7)
                    {
                        resultIntList[5] += 1;
                    }
                    else if (testFloatValue < 8)
                    {
                        resultIntList[6] += 1;
                    }
                    else if (testFloatValue < 9)
                    {
                        resultIntList[7] += 1;
                    }
                    else if (testFloatValue < 10)
                    {
                        resultIntList[8] += 1;
                    }
                    else if (testFloatValue <= 11)
                    {
                        resultIntList[9] += 1;
                    }
                }

                // Ensure that all numbers were generated at least 80% of the time out of 1000 calls to the generator
                for (int index = 0; index < 9; index++)
                {
                    Assert.IsTrue(resultIntList[index] > 70, "GenerateARamInt: Out of 1000 calls, " + index + " was generated " + resultIntList[index] + " times.");
                }
            }
 /// <summary>
 /// Generates an actual time to contact.
 /// </summary>
 /// <returns>The generated actual time to contact.</returns>
 public float GenerateActualTimeToContact()
 {
     return(RamGenerator.GenerateARamNum(MIN_TIME_TO_CONTACT_IN_SECONDS,
                                         MAX_TIME_TO_CONTACT_IN_SECONDS));
 }