本文整理汇总了C#中Map.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# Map.Contains方法的具体用法?C# Map.Contains怎么用?C# Map.Contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Map
的用法示例。
在下文中一共展示了Map.Contains方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildingInfluence
public BuildingInfluence(World world)
{
map = world.Map;
influence = new CellLayer<Actor>(map);
world.ActorAdded += a =>
{
var b = a.TraitOrDefault<Building>();
if (b == null)
return;
foreach (var u in FootprintUtils.Tiles(map.Rules, a.Info.Name, b.Info, a.Location))
if (map.Contains(u) && influence[u] == null)
influence[u] = a;
};
world.ActorRemoved += a =>
{
var b = a.TraitOrDefault<Building>();
if (b == null)
return;
foreach (var u in FootprintUtils.Tiles(map.Rules, a.Info.Name, b.Info, a.Location))
if (map.Contains(u) && influence[u] == a)
influence[u] = null;
};
}
示例2: Run
public void Run(ModData modData, string[] args)
{
Game.ModData = modData;
map = new Map(modData, modData.ModFiles.OpenPackage(args[1]));
Console.WriteLine("Resizing map {0} from {1} to {2},{3}", map.Title, map.MapSize, width, height);
map.Resize(width, height);
var forRemoval = new List<MiniYamlNode>();
foreach (var kv in map.ActorDefinitions)
{
var actor = new ActorReference(kv.Value.Value, kv.Value.ToDictionary());
var location = actor.InitDict.Get<LocationInit>().Value(null);
if (!map.Contains(location))
{
Console.WriteLine("Removing actor {0} located at {1} due being outside of the new map boundaries.".F(actor.Type, location));
forRemoval.Add(kv);
}
}
foreach (var kv in forRemoval)
map.ActorDefinitions.Remove(kv);
map.Save((IReadWritePackage)map.Package);
}
示例3: GetTargetablePoints
public static IEnumerable<Vector2i> GetTargetablePoints(
Map map,
Actor attacker,
int minRange,
int maxRange,
bool targetsEnemies,
bool targetsAllies)
{
var visible = new HashSet<Vector2i>();
var start = attacker.GridPosition;
ShadowCaster.ComputeFieldOfViewWithShadowCasting(start.X, start.Y, maxRange,
(x, y) =>
map.Contains(x,y) &&
!(x == start.X && y == start.Y) &&
(map.ContainsActorAtLocation(x,y) ||
map[x,y].Properties.BlocksVision),
(x, y) => visible.Add(new Vector2i(x, y)),
(x, y, z) => x + y <= z);
for (int ii = minRange; ii <= maxRange; ii++)
{
foreach (var point in GetPointsAtDistance(start, ii))
{
if (map.Contains(point) && visible.Contains(point))
{
Actor inhabitant;
if (map.TryGetActor(point, out inhabitant) && (inhabitant.Team == attacker.Team))
{
bool isAlly = inhabitant.Team == attacker.Team;
if (isAlly && targetsAllies || !isAlly && targetsEnemies)
{
yield return point;
}
}
else
{
yield return point;
}
}
}
}
}
示例4: Shroud
public Shroud(Actor self)
{
this.self = self;
map = self.World.Map;
visibleCount = new CellLayer<short>(map);
generatedShroudCount = new CellLayer<short>(map);
explored = new CellLayer<bool>(map);
self.World.ActorAdded += AddVisibility;
self.World.ActorRemoved += RemoveVisibility;
self.World.ActorAdded += AddShroudGeneration;
self.World.ActorRemoved += RemoveShroudGeneration;
fogVisibilities = Exts.Lazy(() => self.TraitsImplementing<IFogVisibilityModifier>().ToArray());
shroudEdgeTest = cell => map.Contains(cell);
fastExploredTest = IsExploredCore;
slowExploredTest = IsExplored;
fastVisibleTest = IsVisibleCore;
slowVisibleTest = IsVisible;
}
示例5: applyAssemblyText
private List<SpectrumSourceGroup> applyAssemblyText(ISession session, string filepath)
{
var spectrumSources = session.Query<SpectrumSource>().ToList();
var sourcesByGroup = new Map<string, List<SpectrumSource>>();
var alreadyGroupedSources = new Set<string>();
var sourceGroups = new List<SpectrumSourceGroup>();
// open the assembly.txt file
using (var assembleTxtFile = File.OpenText(filepath))
{
string line;
while ((line = assembleTxtFile.ReadLine()) != null)
{
if (line.Length == 0)
continue;
try
{
Regex groupFilemaskPair = new Regex("((\"(.+)\")|(\\S+))\\s+((\"(.+)\")|(\\S+))");
Match lineMatch = groupFilemaskPair.Match(line);
string group = lineMatch.Groups[3].ToString() + lineMatch.Groups[4].ToString();
string filemask = lineMatch.Groups[7].ToString() + lineMatch.Groups[8].ToString();
// for wildcards, use old style behavior
if (filemask.IndexOfAny("*?".ToCharArray()) > -1)
{
if (!Path.IsPathRooted(filemask))
filemask = Path.Combine(Path.GetDirectoryName(filepath), filemask);
if (!sourcesByGroup.Contains(group))
sourcesByGroup[group] = new List<SpectrumSource>();
if (!Directory.Exists(Path.GetDirectoryName(filemask)))
continue;
var files = Directory.GetFiles(Path.GetDirectoryName(filemask), Path.GetFileName(filemask));
var sourceNames = files.Select(o => Path.GetFileNameWithoutExtension(o));
foreach (string sourceName in sourceNames)
{
var spectrumSource = spectrumSources.SingleOrDefault(o => o.Name == sourceName);
if (spectrumSource == null)
continue;
var insertResult = alreadyGroupedSources.Insert(sourceName);
if (insertResult.WasInserted)
sourcesByGroup[group].Add(spectrumSource);
}
}
else
{
// otherwise, match directly to source names
string sourceName = Path.GetFileNameWithoutExtension(filemask);
var spectrumSource = spectrumSources.SingleOrDefault(o => o.Name == sourceName);
if (spectrumSource == null)
continue;
var insertResult = alreadyGroupedSources.Insert(sourceName);
if (insertResult.WasInserted)
sourcesByGroup[group].Add(spectrumSource);
}
}
catch (Exception ex)
{
Program.HandleException(new Exception("Error reading assembly text from \"" + filepath + "\": " + ex.Message, ex));
}
}
}
// remove existing groups
RemoveGroupNode(_rootNode, false);
sourceGroups.Add(new SpectrumSourceGroup { Name = "/" });
// build new group hierarchy
foreach (var itr in sourcesByGroup)
{
if (itr.Value.IsNullOrEmpty())
continue;
var ssg = new SpectrumSourceGroup { Name = itr.Key };
if (!alreadyGroupedSources.Contains(ssg.Name))
sourceGroups.Add(ssg);
// decompose group path into segments, e.g. /foo/bar/ -> {foo, bar}
IEnumerable<string> segments = ssg.Name.Split("/".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
segments = segments.Take(segments.Count() - 1); // ignore the last segment
var parentNode = _rootNode;
foreach(string segment in segments)
{
var segmentNode = parentNode.Children.FirstOrDefault(o => o.Text == segment);
if (segmentNode == null)
{
var segmentGroup = new SpectrumSourceGroup { Name = (parentNode.Text + "/").Replace("//", "/") + segment };
if (!alreadyGroupedSources.Contains(segmentGroup.Name))
sourceGroups.Add(segmentGroup);
segmentNode = new tlvBranch
{
Text = segment,
//.........这里部分代码省略.........