Ejemplo n.º 1
0
        protected List <TTargetToSearch> LocateTarget <TTargetToSearch>()
        {
            int[] wayX   = { -1, 0, 1, 0 };
            int[] wayY   = { 0, 1, 0, -1 };
            int   radius = 8;

            int[] anotherWay = { -1, 1 };

            List <TTargetToSearch> list = new List <TTargetToSearch>();

            for (int i = 0; i < wayX.Length * radius; i++)
            {
                int k           = i / wayX.Length + 1;
                int moveRight   = wayY[i % 4] * k;
                int moveForward = wayX[i % 4] * k;


                if (i % 2 == 1)
                {
                    for (int j = 0; j < anotherWay.Length * radius; j++)
                    {
                        int c = j / anotherWay.Length + 1;

                        moveForward = anotherWay[j % 2] * c;

                        if (GlobalMap.CheckBorder(X + moveForward, Y + moveRight))
                        {
                            if (GlobalMap.Field[X + moveForward, Y + moveRight].Entity.OfType <TTargetToSearch>().FirstOrDefault() != null)
                            {
                                foreach (var target in GlobalMap.Field[X + moveForward, Y + moveRight].Entity.OfType <TTargetToSearch>())
                                {
                                    list.Add(target);
                                }
                            }
                        }
                    }
                }
                else if (GlobalMap.CheckBorder(X + moveForward, Y + moveRight))
                {
                    if (GlobalMap.Field[X + moveForward, Y + moveRight].Entity.OfType <TTargetToSearch>().FirstOrDefault() != null)
                    {
                        foreach (var target in GlobalMap.Field[X + moveForward, Y + moveRight].Entity.OfType <TTargetToSearch>())
                        {
                            list.Add(target);
                        }
                    }
                }
            }


            return(list);
        }
Ejemplo n.º 2
0
        protected void RandomMove()
        {
            Satiety -= SatPerTurn;
            Stress  += StressPerTurn;

            int[] wayX = { -1, 0, 1, 0 };
            int[] wayY = { 0, 1, 0, -1 };

            var value = Map.Rand.Next(wayX.Length);

            if (GlobalMap.CheckBorder(X + wayX[value], Y + wayY[value]))
            {
                X += wayX[value];
                Y += wayY[value];

                GlobalMap.Field[X - wayX[value], Y - wayY[value]].Entity.Remove(this);
                GlobalMap.Field[X, Y].Entity.Add(this);

                GlobalMap.ChangedCell.Add(GlobalMap.Field[X - wayX[value], Y - wayY[value]]);
                GlobalMap.ChangedCell.Add(GlobalMap.Field[X, Y]);
            }
        }