Beispiel #1
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.");
                }
            }
Beispiel #2
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());
            }
Beispiel #3
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());
            }
Beispiel #4
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());
            }
        /// <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>();
        }
        /// <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);
        }