コード例 #1
0
        List <bbPos> SetNeighborsSquare(bbPos p, Dictionary <string, bbPos> map, int _dim, bool _wrapEastWest = false, bool _wrapNorthSouth = false)
        {
            float        x         = p.gridLoc.x();
            float        y         = p.gridLoc.y();
            List <bbPos> neighbors = new List <bbPos>();

            for (int i = -1; i <= 1; i++)
            {
                for (int j = -1; j <= 1; j++)
                {
                    if (i != 0 || j != 0)
                    {
                        float X = _wrapEastWest ? (_dim + x + i) % _dim : x + i;
                        float Y = _wrapNorthSouth ? (_dim + y + j) % _dim : y + j;

                        bbLoc l2 = new bbLoc(X, Y);
                        if (map.ContainsKey(l2.key()))
                        {
                            neighbors.Add(map[l2.key()]);
                        }
                        else
                        {
                            Debug.Log("Map doesn't contain " + l2.x() + "," + l2.y());
                        }
                    }
                }
            }
            return(neighbors);
        }
コード例 #2
0
        List <bbPos> SetNeighborsHex(bbPos p, Dictionary <string, bbPos> map, int _dim, bool _wrapEastWest = false, bool _wrapNorthSouth = false)
        {
            List <bbPos> neighbors = new List <bbPos>();

            List <int[]> hexNeighbors = new List <int[]>();

            if (p.gridLoc.y() % 2 == 0)
            {
                hexNeighbors.Add(new int[] { 1, 0 });
                hexNeighbors.Add(new int[] { 1, -1 });
                hexNeighbors.Add(new int[] { 0, -1 });
                hexNeighbors.Add(new int[] { -1, 0 });
                hexNeighbors.Add(new int[] { 0, 1 });
                hexNeighbors.Add(new int[] { 1, 1 });
            }
            else
            {
                hexNeighbors.Add(new int[] { 1, 0 });
                hexNeighbors.Add(new int[] { -1, -1 });
                hexNeighbors.Add(new int[] { 0, -1 });
                hexNeighbors.Add(new int[] { -1, 0 });
                hexNeighbors.Add(new int[] { 0, 1 });
                hexNeighbors.Add(new int[] { -1, 1 });
            }


            float x = p.gridLoc.x();
            float y = p.gridLoc.y();

            for (int k = 0; k < hexNeighbors.Count; k++)
            {
                int   i = hexNeighbors[k][0];
                int   j = hexNeighbors[k][1];
                float X = _wrapEastWest ? (_dim + x + i) % _dim : x + i;
                float Y = _wrapNorthSouth ? (_dim + y + j) % _dim : y + j;

                bbLoc l2 = new bbLoc(X, Y);
                if (map.ContainsKey(l2.key()))
                {
                    neighbors.Add(map[l2.key()]);
                }
                else
                {
                    Debug.Log("Map doesn't contain " + l2.x() + "," + l2.y());
                }
            }

            return(neighbors);
        }
コード例 #3
0
        public void AddStructure(bbStructureType t, float x, float y, ClickType _clickType)
        {
            bbLoc       l = new bbLoc(x, y);
            bbStructure s = bbStructureFactory.GenerateStructure(t, pathMap[l.key()], _clickType);

            structures[s.getPos()] = s;
            //Debug.Log("Added Structure at " + s.getPos().getName());
        }