/// <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);
            }
        }
Exemplo n.º 2
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);
            }
        }
Exemplo n.º 3
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");
            }
Exemplo n.º 4
0
            public void WHEN_GenerateARamInt_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
                    testIntValue = RamGenerator.GenerateARamInt(1, 100);

                    // Keep track of the occurrences of the number one
                    if (testIntValue < 1 || testIntValue > 100)
                    {
                        actualOutOfRangeCount += 1;
                    }
                }
                Assert.IsTrue(actualOutOfRangeCount == expectedOutOfRangeCount, "Invalid number generated from GenerateARamInt");
            }
Exemplo n.º 5
0
            public void WHEN_GenerateARamIntLowerEqualUpperBound_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
                    testIntValue = RamGenerator.GenerateARamInt(1, 1);

                    // Keep track of the occurrences of each number
                    if (testIntValue == 1)
                    {
                        actualOnesCount += 1;
                    }
                }
                Assert.IsTrue(actualOnesCount == expectedOnesCount, "Invalid number generated from GenerateARamInt");
            }
Exemplo n.º 6
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.");
                }
            }