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);
        }
 /// <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));
 }
        /// <summary>
        /// Calculates the number of thieves and people images that will appear in the round. The imageOrder
        /// list will be updated accordingly.
        /// </summary>
        private void FillImageList()
        {
            // Randomly determine whether thief or person images should appear
            // And make sure at least one of thief and person appears
            thiefAppearInRound = RamGenerator.GenerateARandomBool();
            if (thiefAppearInRound)
            {
                // personAppearInRound could be either true or false
                personAppearInRound = RamGenerator.GenerateARandomBool();
                // Add thief image type to the list of images that will appear
                imageOrder.Add(Images.THIEF);
            }
            else
            {
                // personAppearInRound should be true
                personAppearInRound = true;
            }

            if (personAppearInRound)
            {
                // Determine the number of people that will appear this round
                numberOfPeople = RamGenerator.GenerateARamInt(MIN_PEOPLE, MAX_PEOPLE);
                // Add one person image type to the list for each person that will appear this round
                for (int count = 0; count < numberOfPeople; count += 1)
                {
                    imageOrder.Add(Images.PERSON);
                }
            }

            // For all the remaining square game objects, they will be left blank
            while (imageOrder.Count < 9)
            {
                imageOrder.Add(Images.BLANK);
            }
        }
Ejemplo n.º 4
0
            public void WHEN_PickNRandomElems_THEN_ValuesGeneratedEqually()
            {
                testIntList = new List <int>()
                {
                    0, 1, 2, 3, 4
                };
                resultIntList = new List <int>()
                {
                    0, 0, 0, 0, 0
                };

                // Run the random boolean generator 1000 times
                for (int i = 0; i < 1000; i++)
                {
                    List <int> ramGeneratorList = RamGenerator.PickNRandomElems(testIntList, 2);

                    // Record the values generated in the list
                    resultIntList[ramGeneratorList[0]] += 1;
                    resultIntList[ramGeneratorList[1]] += 1;
                }

                // Ensure that all numbers were generated at least 15% of the time out of 1000 calls to the generator
                for (int index = 0; index < 4; index++)
                {
                    Assert.IsTrue(resultIntList[index] > 150, "GenerateARamInt: Out of 1000 calls, " + index + " was generated " + resultIntList[index] + " times.");
                }
            }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
            public void WHEN_Pick0RandomElemsFromEmptyList_THEN_EmptyListReturned()
            {
                // Predetermined test list
                testIntList = new List <int>()
                {
                };

                // Random items picked out by the PickNRandomElems function
                List <int> ramGeneratorList = RamGenerator.PickNRandomElems(testIntList, 0);

                Assert.AreEqual(0, ramGeneratorList.Count());
            }
Ejemplo n.º 7
0
            public void WHEN_Pick3RandomElemsFromListWith2Elems_THEN_ListWith2ElemsReturned()
            {
                // Predetermined test list
                testIntList = new List <int>()
                {
                    1, 2
                };

                // Random items picked out by the PickNRandomElems function
                List <int> ramGeneratorList = RamGenerator.PickNRandomElems(testIntList, 3);

                Assert.AreEqual(2, ramGeneratorList.Count());
            }
Ejemplo n.º 8
0
            public void WHEN_GenerateARandomBool_THEN_TrueAndFalseAppearEqually()
            {
                int trueCountTotal = 0;

                // Run the random boolean generator 1000 times
                for (int i = 0; i < 1000; i++)
                {
                    testBoolValue = RamGenerator.GenerateARandomBool();
                    if (testBoolValue)
                    {
                        trueCountTotal += 1;
                    }
                }

                Assert.IsTrue(trueCountTotal < 600, "GenerateARandomBool: Out of 1000 calls, number of times true appeared " + trueCountTotal);
            }
Ejemplo n.º 9
0
            public IEnumerator WHEN_ClickCatchTheThief_THEN_CatchTheThiefImageCheck()
            {
                Grid = GameObject.Find("SquareGridArea");
                yield return(null);

                // Boolean to determine if the thief appears in this round
                bool thiefAppearInRound;
                // Boolean to determine if the person appears in this round
                bool          personAppearInRound;
                List <Images> imageOrder = new List <Images>();
                int           numberOfPeople;

                // Randomly determine whether thief or person images should appear
                // And make sure at least one of thief and person appears
                thiefAppearInRound = RamGenerator.GenerateARandomBool();
                if (thiefAppearInRound)
                {
                    // personAppearInRound could be either true or false
                    personAppearInRound = RamGenerator.GenerateARandomBool();
                    // Add thief image type to the list of images that will appear
                    imageOrder.Add(Images.THIEF);
                }
                else
                {
                    // personAppearInRound should be true
                    personAppearInRound = true;
                }

                if (personAppearInRound)
                {
                    // Determine the number of people that will appear this round
                    numberOfPeople = RamGenerator.GenerateARamInt(1, 3);
                    // Add one person image type to the list for each person that will appear this round
                    for (int count = 0; count < numberOfPeople; count += 1)
                    {
                        imageOrder.Add(Images.PERSON);
                    }
                }

                // For all the remaining square game objects, they will be left blank
                while (imageOrder.Count < 9)
                {
                    imageOrder.Add(Images.BLANK);
                }

                Assert.IsTrue(imageOrder.Count == 9, " message: no Error TestFCS1");
            }
Ejemplo n.º 10
0
        /// <summary>
        /// To start the Image hit game
        /// The game should be started at once after calling this method
        /// </summary>
        public void StartGame()
        {
            UnityEngine.Random.InitState(DateTime.Now.Second);

            //To get a random theme used for this round of game
            currentThemeId = GetRandTheme("");
            if (currentThemeId != -1)
            {
                themes[currentThemeId].specifiedTheme = themes[currentThemeId].specifiedTheme.Trim();
                specifiedTheme = themes[currentThemeId].specifiedTheme;

                // To get images of current themes of the number MIN_NumOfImagesOfTheme to MAX_NumOfImagesOfTheme
                int randThemeCount = RamGenerator.GenerateARamInt(MIN_NumOfImagesOfTheme, MAX_NumOfImagesOfTheme);
                currentRoundTestImages = themes[currentThemeId].getrandimages(randThemeCount);

                randThemeCount = 10 - randThemeCount;

                List <TImage> tmp = GetRandImage(randThemeCount);
                currentRoundTestImages.AddRange(tmp);
            }

            images = new List <string>();

            foreach (var item in currentRoundTestImages)
            {
                images.Add(item.sprite.name);
            }


            // Before the game start, the imagelist must have 10 images
            // All variables should be initialized
            serialNumber = 0;
            if (currentRoundTestImages.Count == 10)
            {
                currentRoundTestData.Clear();

                initialTestImages  = currentRoundTestImages;
                gameInfo.text      = "";
                prepareTime        = 1;
                imageDisplayedTime = 0;
                canShowNextImage   = true;
                gameState          = 0;
                RandSortImages(initialTestImages);
                imageDisplay.gameObject.SetActive(true);
                mRoundStart(0);
            }
        }
Ejemplo n.º 11
0
            public void WHEN_PickNRandomElems_THEN_NoDuplicatedElements()
            {
                // Predetermined test list
                testIntList = new List <int>()
                {
                    1, 2, 3, 4, 5
                };

                // Random items picked out by the PickNRandomElems function
                List <int> ramGeneratorList = RamGenerator.PickNRandomElems(testIntList, 3);

                // Check for duplicates
                IEnumerable <int> duplicatesList = ramGeneratorList.GroupBy(x => x)
                                                   .Where(g => g.Count() > 1)
                                                   .Select(x => x.Key);

                Assert.AreEqual(0, duplicatesList.Count());
            }
Ejemplo n.º 12
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");
            }
Ejemplo n.º 13
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");
            }
        /// <summary>
        /// Function for displaying the highlight sequence
        /// </summary>
        private IEnumerator HighlightSequenceStage()
        {
            roundNumber += 1;

            // Initialize round gameplay data variables
            round = new SquaresRound();
            round.HighlightedSquares      = new List <IndexAndPosition>();
            round.RecalledSquares         = new List <IndexAndPosition>();
            round.SquareHighlightInterval = squareHighlightInterval; // float value
            round.SquareHighlightDuration = squareHighlightDuration; // float value

            // Randomly select a new square highlight sequence for the new round,
            // by using the existing list of square game objects
            squaresToHighlight = RamGenerator.PickNRandomElems(displayedSquares, numberOfHighlightedSquares);

            // Display the square highlight sequence
            yield return(StartCoroutine(HighlightSquareSequence(squaresToHighlight, squareHighlightInterval)));

            // Clear the list of squares recalled by the player
            recalledSquares = new List <IndexAndPosition>();
        }
Ejemplo n.º 15
0
            public void WHEN_GenerateARamInt_THEN_ValuesGeneratedEqually()
            {
                resultIntList = new List <int>()
                {
                    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
                    testIntValue = RamGenerator.GenerateARamInt(0, 4);
                    // Keep track of the occurrences of each number
                    resultIntList[testIntValue] += 1;
                }

                // Ensure that all numbers were generated at least 15% of the time out of 1000 calls to the generator
                for (int index = 0; index < 4; index++)
                {
                    Assert.IsTrue(resultIntList[index] > 150, "GenerateARamInt: Out of 1000 calls, " + index + " was generated " + resultIntList[index] + " times.");
                }
            }
        /// <summary>
        /// Reset or Calculate the level variables for the next round.
        /// </summary>
        private IEnumerator PrepareRound()
        {
            // Initialize round gameplay data variables
            roundNumber           += 1;
            identifiedKeyPressTime = 0;
            isRoundOver            = false;
            isIdentifiedKeyPressed = false;
            // In each round there is a new image order
            imageOrder = new List <Images>();

            // Decrease round duration as the number of rounds increase, until it reaches the minimum
            // round duration time
            if (roundDuration > MIN_ROUND_TIME)
            {
                roundDuration -= ROUND_TIME_DECREMENT;
            }

            // Calculate whether thief or person images will appear in this round
            FillImageList();

            // Set the round variables in the game storage
            round = new CatchTheThiefRound();
            round.UnidentifiedKeysPressed = new List <TimeAndKey>();
            round.ThiefAppearInRound      = thiefAppearInRound;
            round.PersonAppearInRound     = personAppearInRound;

            // Randomize the list of images that will appear in this round
            imageOrder = RamGenerator.PickNRandomElems(imageOrder, numberOfSquaresInGrid);
            // If the thief has been randomized to appear on the same square as in the last round
            while (imageOrder[indexThiefAppearedLastRound] == Images.THIEF)
            {
                // Randomize the list of images again
                imageOrder = RamGenerator.PickNRandomElems(imageOrder, numberOfSquaresInGrid);
            }

            yield return(null);
        }
Ejemplo n.º 17
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));
 }