Пример #1
0
    public void setWalkRangeGrid()
    {
        walkGraph = new LocGraph(mvt, row, column);
        walkGraph.setDrawX(transform.position.x);
        walkGraph.setDrawY(transform.position.y);
        Queue <LocNode> queue = new Queue <LocNode>();

        walkGraph.addNode(row, column, column, (GameMapping.map.unitMap.GetLength(0) - 1) - row, 0);
        queue.Enqueue(walkGraph.getNode(row, column));
        int count = queue.Count;
        int idx   = 0;

        while (idx < mvt)
        {
            while (count > 0)
            {
                LocNode node = queue.Dequeue();
                count--;
                if (node.row - 1 >= 0 &&
                    !GameMapping.map.occupied[node.row - 1, node.column] &&
                    !walkGraph.nodeExists(node.row - 1, node.column))
                {
                    walkGraph.addNode(node.row - 1, node.column, node.x, node.y + 1, idx);
                    queue.Enqueue(walkGraph.getNode(node.row - 1, node.column));
                }
                if (node.column + 1 < GameMapping.map.occupied.GetLength(1) &&
                    !GameMapping.map.occupied[node.row, node.column + 1] &&
                    !walkGraph.nodeExists(node.row, node.column + 1))
                {
                    walkGraph.addNode(node.row, node.column + 1, node.x + 1, node.y, idx);
                    queue.Enqueue(walkGraph.getNode(node.row, node.column + 1));
                }
                if (node.row + 1 < GameMapping.map.occupied.GetLength(0) &&
                    !GameMapping.map.occupied[node.row + 1, node.column] &&
                    !walkGraph.nodeExists(node.row + 1, node.column))
                {
                    walkGraph.addNode(node.row + 1, node.column, node.x, node.y - 1, idx);
                    queue.Enqueue(walkGraph.getNode(node.row + 1, node.column));
                }
                if (node.column - 1 >= 0 &&
                    !GameMapping.map.occupied[node.row, node.column - 1] &&
                    !walkGraph.nodeExists(node.row, node.column - 1))
                {
                    walkGraph.addNode(node.row, node.column - 1, node.x - 1, node.y, idx);
                    queue.Enqueue(walkGraph.getNode(node.row, node.column - 1));
                }
            }
            count = queue.Count;
            idx++;
        }
    }
Пример #2
0
 public void setActionRangeGrid(int minR, int maxR, int _row, int _column, int val)
 {
     actionGraph = new LocGraph(maxR, _row, _column);
     actionGraph.setDrawX(transform.position.x);
     actionGraph.setDrawY(transform.position.y);
     while (minR <= maxR)
     {
         for (int i = -1; i <= 1; i += 2)
         {
             if (_row + (minR * i) < GameMapping.map.occupied.GetLength(0) && _row + (minR * i) >= 0 &&
                 ((minR * i) + maxR) < actionGraph.getHeight() && ((minR * i) + maxR) >= 0)
             {
                 actionGraph.addNode(_row + (minR * i), _column, (minR * i), 0, val);
             }
             if (_column + (minR * i) < GameMapping.map.occupied.GetLength(1) && _column + (minR * i) >= 0 &&
                 ((minR * i) + maxR) < actionGraph.getWidth() && ((minR * i) + maxR) >= 0)
             {
                 actionGraph.addNode(_row, _column + (minR * i), 0, (minR * i), val);
             }
         }
         for (int j = 0; j < minR - 1; j++)
         {
             if ((_row - minR) + j < GameMapping.map.occupied.GetLength(0) && (_row - minR) + j >= 0 &&
                 _column + j < GameMapping.map.occupied.GetLength(1) && _column + j >= 0)
             {
                 actionGraph.addNode((_row - minR) + j, _column + j, _column + j, ((GameMapping.map.unitMap.GetLength(0) - 1) - _row - minR) + j, val);
             }
             if (_row - j < GameMapping.map.occupied.GetLength(0) && _row - j >= 0 &&
                 (_column - minR) + j < GameMapping.map.occupied.GetLength(1) && (_column - minR) + j >= 0)
             {
                 actionGraph.addNode(_row - j, (_column - minR) + j, (_column - minR) + j, ((GameMapping.map.unitMap.GetLength(0) - 1) - _row) - j, val);
             }
             if ((_row + minR) - j < GameMapping.map.occupied.GetLength(0) && (_row + minR) - j >= 0 &&
                 _column - j < GameMapping.map.occupied.GetLength(1) && _column - j >= 0)
             {
                 actionGraph.addNode((_row + minR) - j, _column - j, _column - j, ((GameMapping.map.unitMap.GetLength(0) - 1) - (_row + minR)) - j, val);
             }
             if (_row + j < GameMapping.map.occupied.GetLength(0) && _row + j >= 0 &&
                 (_column + minR) - j < GameMapping.map.occupied.GetLength(1) && (_column + minR) - j >= 0)
             {
                 actionGraph.addNode(_row + j, (_column + minR) - j, (_column + minR) - j, ((GameMapping.map.unitMap.GetLength(0) - 1) - _row) + j, val);
             }
         }
         minR++;
     }
 }