public void GameLevelActionLimiter_TwoRequests_TimeNotStarted() { var time = new GameLevelTime(); var limiter = new GameLevelActionLimiter(time, TimeSpan.FromSeconds(1)); Assert.IsTrue(limiter.CanDoStuff()); limiter.DoingIt(); Assert.IsFalse(limiter.CanDoStuff()); limiter.DoingIt(); }
public async Task GameLevelActionLimiter_TwoRequests_TimeStarted() { var time = new GameLevelTime(); var limiter = new GameLevelActionLimiter(time, TimeSpan.FromMilliseconds(100)); time.Start(); Assert.IsTrue(limiter.CanDoStuff()); limiter.DoingIt(); await Task.Delay(TimeSpan.FromMilliseconds(200)); Assert.IsTrue(limiter.CanDoStuff()); limiter.DoingIt(); }
private void Shoot() { // Find the closest enemy. Enemy closestEnemy = GetClosestEnemy(); if (closestEnemy != null && IsInRange(closestEnemy)) { _shootLimiter.DoingIt(); closestEnemy.Shot(this); } }
private void Shoot() { // Find the closest enemy. EnemyBase closestEnemy = _gameLevel .CurrentMonsters .Where(m => m.IsAlive && m.IsVisible) .OrderBy(m => m.GetDistance(this)) .FirstOrDefault(); if (closestEnemy != null && closestEnemy.GetDistance(this) < Settings.RangePixels) { _shootLimiter.DoingIt(); closestEnemy.Shot(this); } }