/// <summary>
        /// Method that generates the playfield
        /// </summary>
        /// <param name="rand">Parameter of type IRandomNumberGenerator</param>
        /// <returns>Returns the playfield as a two dimensional array</returns>
        public ICell[,] GeneratePlayField(IRandomNumberGenerator rand)
        {
            for (int row = 0; row < this.rows; row++)
            {
                for (int col = 0; col < this.cols; col++)
                {
                    int cellRandomValue = rand.GenerateNext(0, 1);

                    char charValue;
                    if (cellRandomValue == 0)
                    {
                        charValue = Constants.StandardGameCellEmptyValue;
                    }
                    else
                    {
                        charValue = Constants.StandardGameCellWallValue;
                    }

                    this.playField[row, col] = new Cell(new Position(row, col), charValue);
                }
            }

            this.playField[this.playerPosition.Row, this.playerPosition.Column].ValueChar = Constants.StandardGamePlayerChar;

            bool exitPathExists = this.ExitPathExists();
            if (!exitPathExists)
            {
                return this.GeneratePlayField(rand);
            }
            else
            {
                return this.playField;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Method that generates the playfield
        /// </summary>
        /// <param name="rand">Parameter of type IRandomNumberGenerator</param>
        /// <returns>Returns the playfield as a two dimensional array</returns>
        public ICell[,] GeneratePlayField(IRandomNumberGenerator rand)
        {
            for (int row = 0; row < this.rows; row++)
            {
                for (int col = 0; col < this.cols; col++)
                {
                    int cellRandomValue = rand.GenerateNext(0, 1);

                    char charValue;
                    if (cellRandomValue == 0)
                    {
                        charValue = Constants.StandardGameCellEmptyValue;
                    }
                    else
                    {
                        charValue = Constants.StandardGameCellWallValue;
                    }

                    this.playField[row, col] = new Cell(new Position(row, col), charValue);
                }
            }

            this.playField[this.playerPosition.Row, this.playerPosition.Column].ValueChar = Constants.StandardGamePlayerChar;

            bool exitPathExists = this.ExitPathExists();

            if (!exitPathExists)
            {
                return(this.GeneratePlayField(rand));
            }
            else
            {
                return(this.playField);
            }
        }
        public void TestRandNumberGeneratorShouldAlwaysReturnRandomNumbers()
        {
            var hashSet = new HashSet <int>();
            IRandomNumberGenerator numberGenerator = RandomNumberGenerator.Instance;

            for (int i = 0; i < 10000; i++)
            {
                hashSet.Add(numberGenerator.GenerateNext(1, 10));
            }

            Assert.AreEqual(10, hashSet.Count);
        }
        public void TestRandNumberGeneratorNotProduceNumberGreaterThanMaxValue()
        {
            IRandomNumberGenerator numberGenerator = RandomNumberGenerator.Instance;
            int max = 10;
            int generated;

            for (int i = 0; i < 10000; i++)
            {
                generated = numberGenerator.GenerateNext(1, 10);
                if (generated > max)
                {
                    max = generated;
                }
            }

            Assert.AreEqual(10, max);
        }
        public void TestGenerateNextShouldNoProduceNumberLessThanMinValue()
        {
            IRandomNumberGenerator numberGenerator = RandomNumberGenerator.Instance;
            int min = 1;
            int generatedNumber;

            for (int i = 0; i < 10000; i++)
            {
                generatedNumber = numberGenerator.GenerateNext(1, 10);
                if (generatedNumber < min)
                {
                    min = generatedNumber;
                }
            }

            Assert.AreEqual(1, min);
        }