Пример #1
0
 /// <summary>
 /// Positions a minion (e.g. a ship) using any of the spawn areas in the arena.
 /// </summary>
 public static void PositionNewMinion(Gob minion, Arena arena)
 {
     Func<IGeomPrimitive, int, IEnumerable<Vector2>> getRandomPoses = (area, count) =>
         Enumerable.Range(0, count)
         .Select(x => arena.GetFreePosition(LARGE_GOB_PHYSICAL_RADIUS, area));
     var spawnPoses = arena.Gobs.All<SpawnPlayer>()
         .SelectMany(spawn => getRandomPoses(spawn._spawnArea, 5));
     var poses = spawnPoses.Any()
         ? spawnPoses
         : getRandomPoses(new Rectangle(Vector2.Zero, arena.Dimensions), 20);
     var posesWithThreats = poses
         .Select(pos => new { pos, mood = GetMood(minion, pos) })
         .ToList()
         .OrderByDescending(x => x.mood)
         .ToList();
     var bestMood = posesWithThreats[0].mood;
     var bestSpawns = posesWithThreats.TakeWhile(x => x.mood == bestMood).ToList();
     var bestPos = bestSpawns[RandomHelper.GetRandomInt(bestSpawns.Count)].pos;
     minion.ResetPos(bestPos, Vector2.Zero, Gob.DEFAULT_ROTATION);
 }