本文整理汇总了C#中IStore.Where方法的典型用法代码示例。如果您正苦于以下问题:C# IStore.Where方法的具体用法?C# IStore.Where怎么用?C# IStore.Where使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IStore
的用法示例。
在下文中一共展示了IStore.Where方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Check
public void Check(IEnumerable<IComponent> components, IStore<string, IArtificialIntelligence> aiStore)
{
var groupedByOwener = components.GroupBy(x => x.OwnerId);
foreach (var group in groupedByOwener) {
var enemies = components.Except(group).OfType<IFieldOfVision>();
foreach (var component in group) {
foreach (var enemy in enemies) {
var isInFieldOfVision = enemy.IsInFieldOfVision(component.Position);
if (isInFieldOfVision) {
var artificialIntelligence = aiStore.Get(enemy.OwnerId);
artificialIntelligence.Fire(new ComponentSpottedEvent(enemy.OwnerId, enemy.Id, component.Id, component.OwnerId, component.Position.X, component.Position.Y, component.GetType()));
SpottedUnitsStore.Store(component.Id, enemy.OwnerId);
}
}
}
}
//foreach (var group in groupedByOwener) {
// var others = components.Except(group).OfType<IFieldOfVision>();
// foreach (var component in group) {
// var spottingUnits = others.Where(x => x.IsInFieldOfVision(component.Position));
// foreach (var fieldOfVision in spottingUnits) {
// var artificialIntelligence = aiStore.Get(fieldOfVision.OwnerId);
// artificialIntelligence.Fire(new ComponentSpottedEvent(fieldOfVision.OwnerId,fieldOfVision.Id,component.Id,component.OwnerId,component.Position.X,component.Position.Y, component.GetType()));
// SpottedUnitsStore.Store(component.Id,fieldOfVision.OwnerId);
// }
// }
//}
var spottedUnits = SpottedUnitsStore.GetKeys();
Parallel.ForEach(spottedUnits, (suid,loopState) =>
{
var spottedComponent = components.SingleOrDefault(x => x.Id.Equals(suid));
if(spottedComponent == null)
{
SpottedUnitsStore.Remove(suid);
}
else
{
var enemyOwnerId = SpottedUnitsStore.Get(suid);
if(enemyOwnerId == null)
return;
var enemyUnits =
components.Where(x => x.OwnerId.Equals(enemyOwnerId)).OfType<IFieldOfVision>();
if(enemyUnits.All(x => !x.IsInFieldOfVision(spottedComponent.Position)))
{
SpottedUnitsStore.Remove(spottedComponent.Id);
var artificialIntelligence = aiStore.Where(x => x.Id.Equals(enemyOwnerId)).First();
artificialIntelligence.Fire(new ComponentLeftFieldOfVisionEvent(artificialIntelligence.Id,spottedComponent.Id,spottedComponent.OwnerId,spottedComponent.Position.X,spottedComponent.Position.Y,spottedComponent.GetType()));
}
}
});
}