Beispiel #1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="d"></param>
        /// <param name="cellList"></param>
        /// <param name="distance"></param>
        /// <param name="searchType">0= Projectiles only, 1= Units only, 2 =Both</param>
        /// <returns></returns>
        public static Entity FindFirstEntityInDistance(int x, int y, Directions d, Cell[,] cellList,int distance,int searchType)
        {
            Entity returnUnit = null;
            String tag = "FindFirstEntity";
            Globals.WriteDebug(tag, "Running FindFirstEntity", true);
            int searches = 0;
            while(searches< distance)
            {
                switch (d)
                {
                    case Directions.DOWN:
                        if (y < cellList.GetLength(1))
                        {
                            y++;
                        }
                        break;
                    case Directions.UP:
                        if (y > 0)
                        {
                            y--;
                        }
                        break;
                    case Directions.LEFT:
                        if (x > 0)
                        {
                            x--;
                        }
                        break;
                    case Directions.RIGHT:
                        if (x < cellList.GetLength(0))
                        {
                            x++;
                        }
                        break;
                }

                //Globals.WriteDebug(tag, "Checking xy"+x+" "+y , true);
                if (cellList[x, y].GetMat())
                {
                    return null;
                }
                if (searchType == 1 || searchType == 2)
                {
                    if (cellList[x, y].GetUnitOnCell() != null)
                    {
                        Globals.WriteDebug(tag, "Return Unit is " + cellList[x, y].GetUnitOnCell().GetUnitType(), true);
                        return cellList[x, y].GetUnitOnCell();
                    }
                }
                if (searchType == 0 || searchType == 2)
                {
                    if (cellList[x, y].GetProjectile() != null)
                    {
                        Globals.WriteDebug(tag, "Return Projectile is " + cellList[x, y].GetProjectile().ToString(), true);
                        return cellList[x, y].GetProjectile();
                    }
                }
                searches++;

            }
            Globals.WriteDebug(tag, "Returning Null", true);
            return returnUnit;

        }
Beispiel #2
0
        public static Unit FindFirstUnit(int x, int y, Directions d, Cell[,] cellList)
        {
            Unit returnUnit = null;
            String tag = "FindFirstUnit";
            Globals.WriteDebug(tag, "Running FindFirstUnit", true);

            switch (d)
            {
                case Directions.DOWN:
                    while (y < cellList.GetLength(1))
                    {

                        y++;
                        if (cellList[x, y].GetMat())
                        {
                            return null;
                        }
                        if (cellList[x, y].GetUnitOnCell() != null)
                        {
                            Globals.WriteDebug(tag, "Return Unit is " + cellList[x, y].GetUnitOnCell().GetUnitType(), true);
                            return cellList[x, y].GetUnitOnCell();
                        }
                    }
                    break;
                case Directions.UP:
                    while (y > 0)
                    {
                        y--;
                        if (cellList[x, y].GetMat())
                        {
                            return null;
                        }
                        if (cellList[x, y].GetUnitOnCell() != null)
                        {
                            Globals.WriteDebug(tag, "Return Unit is " + cellList[x, y].GetUnitOnCell().GetUnitType(), true);
                            return cellList[x, y].GetUnitOnCell();
                        }
                    }
                    break;
                case Directions.LEFT:
                    while (x > 0)
                    {
                        x--;
                        if (cellList[x, y].GetMat())
                        {
                            return null;
                        }
                        if (cellList[x, y].GetUnitOnCell() != null)
                        {
                            Globals.WriteDebug(tag, "Return Unit is " + cellList[x, y].GetUnitOnCell().GetUnitType(), true);
                            return cellList[x, y].GetUnitOnCell();
                        }
                    }
                    break;
                case Directions.RIGHT:
                    while (x < cellList.GetLength(0))
                    {

                        x++;
                        if (cellList[x, y].GetMat())
                        {
                            return null;
                        }
                        if (cellList[x, y].GetUnitOnCell() != null)
                        {
                            Globals.WriteDebug(tag, "Return Unit is " + cellList[x, y].GetUnitOnCell().GetUnitType(), true);
                            return cellList[x, y].GetUnitOnCell();
                        }
                    }
                    break;
            }
            Globals.WriteDebug(tag, "Returning Null", true);

            return returnUnit;

        }