private void IncrementGameClock(GameClock gameClock, TimeSpan elapsed)
        {
            // Rather than have every game increment time in the same sequence - add some variability
            var variableTime = TimeSpan.FromMilliseconds(_random.Any(-(int)elapsed.TotalMilliseconds, (int)elapsed.TotalMilliseconds));

            // Add more variable time, if it is above 0
            var gameElapsed = elapsed + (variableTime > TimeSpan.Zero ? variableTime : TimeSpan.Zero);

            //
            var newClockTime = gameClock.Time - gameElapsed;

            // Ensure the clock is rounded to the nearest tenth of a second
            newClockTime = newClockTime.RoundToNearest(TimeSpan.FromMilliseconds(100));

            // Check if time has expired for the current quarter
            if (newClockTime > TimeSpan.Zero)
            {
                gameClock.Time = newClockTime;
            }
            else
            {
                //
                if (gameClock.Quarter >= GameClock.NumberOfQuarters)
                {
                    // Game is over
                    gameClock.Time = TimeSpan.Zero;
                    return;
                }

                gameClock.Quarter++;
                gameClock.Time = GameClock.TimeEachQuarter + newClockTime; // In this case, new time is negative
            }
        }
        public void Any()
        {
            var listR = new List <int>();

            for (int i = 0; i < 500; i++)
            {
                listR.Add(_random.Any());
            }

            foreach (var i in listR)
            {
                Assert.Greater(i, 0);
            }
        }
        public void JsonCloneAnyObject()
        {
            var myObject = new MyPlainObject
            {
                Id        = Guid.NewGuid(),
                Name      = _random.AnyString(8),
                Timestamp = DateTime.UtcNow,
                Value     = _random.Any(),
                DataBlock = _random.AnyBytes(128),
            };

            var clonedObject = myObject.JsonClone();

            Assert.IsFalse(ReferenceEquals(myObject, clonedObject));

            Assert.AreEqual(myObject.Id, clonedObject.Id);
            Assert.AreEqual(myObject.Name, clonedObject.Name);
            Assert.AreEqual(myObject.Timestamp, clonedObject.Timestamp);
            Assert.AreEqual(myObject.Value, clonedObject.Value);
            Assert.AreEqual(myObject.DataBlock, clonedObject.DataBlock);
        }
Esempio n. 4
0
        public void Test()
        {
            var testObject = new SimpleJsonObject
            {
                Name   = _random.AnyString(6),
                Number = _random.Any(),
            };

            for (int i = 0; i < _random.Any(2, 7); i++)
            {
                var childObject = new SimpleChildJsonObject
                {
                    Name   = _random.AnyString(6),
                    Number = _random.Any(),
                };

                testObject.Children.Add(childObject);
            }


            var memoryStream = new MemoryStream();

            // Serialize the object
            using (var writer = JSON.GetWriter(memoryStream))
            {
                testObject.ToJson(writer);
            }

            Assert.Greater(memoryStream.Position, 0);

            memoryStream.Position = 0;


            // Deserialize back into the original object

            var simpleJsonObjectResponse = new SimpleJsonObject();

            using (var reader = JSON.GetReader(memoryStream))
            {
                reader.Read();

                simpleJsonObjectResponse.FromJson(reader);
            }
        }
        public T GetRandom <T>() where T : class
        {
            var allItems = GetAll <T>().ToList().AsReadOnly();

            return(_random.Any(allItems));
        }