Ejemplo n.º 1
0
        public void MoveRotateOrAttack(Creature aggressor, Creature prey, ISimulationWorld isw)
        {
            int distance = DistanceMeasurer.Taxi(aggressor.Position, prey.Position);

            if (distance == 0)
            {
                isw.Attack(aggressor, prey);
            }
            if (distance == 1)
            {
                if (aggressor.Position.X == prey.Position.X)
                {
                    if (aggressor.Position.Y == prey.Position.Y + 1) //ant 1 tile above
                    {
                        if (aggressor.Direction == Dir.N)
                        {
                            isw.Attack(aggressor, prey);
                            return;
                        }
                        else
                        {
                            aggressor.Direction = Dir.N;
                        }
                    }
                    else
                    {
                        if (aggressor.Direction == Dir.S)
                        {
                            isw.Attack(aggressor, prey);
                            return;
                        }
                        else
                        {
                            aggressor.Direction = Dir.S;
                        }
                    }
                }
                else
                {
                    if (aggressor.Position.X == prey.Position.X + 1) //ant 1 tile left
                    {
                        if (aggressor.Direction == Dir.W)
                        {
                            isw.Attack(aggressor, prey);
                            return;
                        }
                        else
                        {
                            aggressor.Direction = Dir.W;
                        }
                    }
                    else
                    {
                        if (aggressor.Direction == Dir.E)
                        {
                            isw.Attack(aggressor, prey);
                            return;
                        }
                        else
                        {
                            aggressor.Direction = Dir.E;
                        }
                    }
                }
                return;
            }
            if (distance > 1)
            {
                List <KeyValuePair <int, int> > trail = Astar.Search(new KeyValuePair <int, int>(aggressor.Position.X, aggressor.Position.Y), new KeyValuePair <int, int>(prey.Position.X, prey.Position.Y), new AstarOtherObject());
                if (trail == null)
                {
                    return;
                }
                if (trail.Count <= 1)
                {
                    return;
                }
                MoveOrRotate(trail[1]);
            }
        }