Exemplo n.º 1
0
        private bool TryToFight(Goblin goblin)
        {
            var root      = new Coordinate(goblin.X, goblin.Y);
            var neighbors = GetNeighbors(root);

            var elves = new List <Elf>();

            foreach (var neighbor in neighbors)
            {
                var elf = Elves.Find(g => !g.IsDead && g.X == neighbor.X && g.Y == neighbor.Y);
                if (elf != null)
                {
                    elves.Add(elf);
                }
            }

            var toAttack = elves.OrderBy(g => g.HP).ThenBy(g => g.Y).ThenBy(g => g.X).FirstOrDefault();

            if (toAttack != null)
            {
                toAttack.HP -= goblin.AP;

                if (toAttack.IsDead)
                {
                    Map[toAttack.X, toAttack.Y] = '.';
                }

                return(true);
            }

            return(false);
        }
Exemplo n.º 2
0
        public Elf FindClosestEnemyTo(Goblin source)
        {
            var sourceX = source.X;
            var sourceY = source.Y;

            var target = SearchFor('E', sourceX, sourceY);

            return(Elves.Find(e => e.X == target.X && e.Y == target.Y));
        }