Ejemplo n.º 1
0
        public Point GetBaseCollectPoint()
        {
            CHelper = new CalcHelper(Engine.Map);
            List <Point> ar = new List <Point>();

            ar = CHelper.GetEmptyAround(BaseLoc);
            return(ar[Engine.rnd.Next(ar.Count)]);
        }
Ejemplo n.º 2
0
 public void GetShortestPath(Point TargetLocation)
 {
     Path        = new List <Point>();
     CHelper     = new CalcHelper(Engine.Map);
     bool[,] map = new bool[Engine.MapSize, Engine.MapSize];
     Target      = TargetLocation;
     Path        = CHelper.CalcShortestPath(Position, GetApprochablePoint(map, Target));
     //Target = GetOreArround(GetOreArround(Path[0]));
 }
Ejemplo n.º 3
0
        public static void tr()
        {
            CalcHelper   c = new CalcHelper(Map);
            List <Point> p = c.CalcShortestPath(new Point(1, 2), new Point(6, 5));

            for (int i = 0; i < p.Count; i++)
            {
                Map[p[i].X, p[i].Y].ContaintID = i + 1;
            }
            DrawMap();
        }
Ejemplo n.º 4
0
        private Point GetApprochablePoint(bool[,] map, Point t)
        {
            CHelper = new CalcHelper(Engine.Map);
            List <Point> ES = CHelper.GetEmptyAround(t);

            if (ES.Count != 0)
            {
                List <Point> Accesible = new List <Point>();
                for (int i = 0; i < ES.Count; i++)
                {
                    if (CHelper.CalcShortestPath(Position, ES[i]) != null)
                    {
                        Accesible.Add(ES[i]);
                    }
                }
                if (Accesible.Count != 0)
                {
                    return(Accesible[Engine.rnd.Next(Accesible.Count)]);
                }
            }
            else
            {
                map[t.X, t.Y] = true;
                if (t.X - 1 >= 0 && !map[t.X - 1, t.Y])
                {
                    GetApprochablePoint(map, new Point(t.X - 1, t.Y));
                }
                if (t.Y - 1 >= 0 && !map[t.X, t.Y - 1])
                {
                    GetApprochablePoint(map, new Point(t.X, t.Y - 1));
                }
                if (t.X + 1 < Engine.MapSize && !map[t.X + 1, t.Y])
                {
                    GetApprochablePoint(map, new Point(t.X + 1, t.Y));
                }
                if (t.Y + 1 < Engine.MapSize && !map[t.X, t.Y + 1])
                {
                    GetApprochablePoint(map, new Point(t.X, t.Y + 1));
                }
            }
            return(new Point(0, 0));
        }
Ejemplo n.º 5
0
 public override void Work()
 {
     if (Path.Count != 0)
     {
         Path.RemoveAt(Path.Count - 1);
         if (Path.Count - 1 >= 0)
         {
             this.Position = Path[Path.Count - 1];
         }
         if (!IsIdle)
         {
             Target = GetOreArround(this.Position);
         }
     }
     else if (IsIdle)
     {
         CalcHelper ch = new CalcHelper(Engine.Map);
         if (!ch.GetEmptyAround(BaseLoc).Contains(this.Position))
         {
             GetShortestPath(BaseLoc);
         }
     }
     else
     {
         if (Engine.Map[Target.X, Target.Y].ResourceAmmount >= CollectAmmount)
         {
             Engine.Map[Target.X, Target.Y].ResourceAmmount    -= CollectAmmount;
             Engine.Map[Target.X, Target.Y].AmmountOnTheGround += CollectAmmount;
         }
         else
         {
             Engine.Map[Target.X, Target.Y].AmmountOnTheGround += Engine.Map[Target.X, Target.Y].ResourceAmmount;
             Engine.Map[Target.X, Target.Y].ResourceAmmount     = 0;
             Engine.Map[Target.X, Target.Y].ContaintID          = 0;
             IsIdle = true;
         }
     }
 }
Ejemplo n.º 6
0
        public List <Point> GetReachebleNearNotVisible()
        {
            CHelper = new CalcHelper(Engine.Map);
            List <Point> TilesToGo = new List <Point>();

            for (int i = 0; i < Engine.MapSize; i++)
            {
                for (int j = 0; j < Engine.MapSize; j++)
                {
                    if (Engine.Visible[i, j] == false)
                    {
                        List <Point> aux = CHelper.GetEmptyAround(new Point(i, j));
                        for (int q = 0; q < aux.Count; q++)
                        {
                            if (!TilesToGo.Contains(aux[q]) && aux[q] != this.Position && CHelper.CalcShortestPath(this.Position, aux[q]) != null)
                            {
                                TilesToGo.Add(aux[q]);
                            }
                        }
                    }
                }
            }
            return(TilesToGo);
        }
Ejemplo n.º 7
0
 public void GetShortestPath(Point TargetLocation)
 {
     Path    = new List <Point>();
     CHelper = new CalcHelper(Engine.Map);
     Path    = CHelper.CalcShortestPath(this.Position, TargetLocation);
 }