/// <summary> /// 尝试射击目标 /// </summary> /// <param name="targetName">目标名</param> /// <param name="bulletName">子弹名称</param> /// <returns>是否命中目标</returns> public bool Shoot(string targetName, string bulletName) { if (_targetList.ContainsKey(targetName) == false) { throw new ArgumentOutOfRangeException("没指定的靶。"); } LimitedRequestTarget target = _targetList[targetName]; return(target.Shoot(bulletName)); }
/// <summary> /// 增加一个目标 /// </summary> /// <param name="targetName">目标名</param> /// <param name="intervalMinute">单位时间</param> /// <param name="shootingTimes">单位内允许的命中次数</param> public void AddTarget(string targetName, int intervalMinute, int shootingTimes) { if (_targetList.ContainsKey(targetName) == false) { lock (_lockObj) { if (_targetList.ContainsKey(targetName) == false) { LimitedRequestTarget target = new LimitedRequestTarget(targetName, intervalMinute, shootingTimes); _targetList.Add(targetName, target); } } } }
public LimitedRequestBullet(string name, LimitedRequestTarget target) { Name = name; Target = target; }