Beispiel #1
0
        //初始化地图
        void Init()
        {
            List <List <bool> > mark = new List <List <bool> >();

            //建立结点
            for (int i = 0; i < layerCount; i++)
            {
                List <MapNode> floor     = new List <MapNode>();
                List <bool>    floorMark = new List <bool>();
                int            num       = Random.Range(2, 5);
                for (int j = 0; j < num; j++)
                {
                    MapNode node = new MapNode();
                    node.layer = i;
                    //node属性设置TODO
                    NodeType nodeType;
                    if (i == 1 || i == 5)
                    {
                        //nodeType = (NodeType)Random.Range(0, (int)NodeType.count);
                        nodeType = NodeType.shop;
                    }
                    else if (i == 3)
                    {
                        nodeType = NodeType.thing;
                    }
                    else
                    {
                        nodeType = NodeType.fight;
                    }

                    node.nodeType = nodeType;

                    floor.Add(node);
                    floorMark.Add(false);
                }
                map.Add(floor);
                mark.Add(floorMark);
            }

            //填充结点的子节点
            for (int i = 0; i < layerCount - 1; i++)
            {
                List <MapNode> floor     = map[i];
                int            childNum  = map[i + 1].Count;
                List <bool>    floorMark = mark[i + 1];
                float          stand     = childNum / (floor.Count + 0.0f);
                for (int j = 0; j < floor.Count; j++)
                {
                    MapNode node = new MapNode();
                    if (j == 0)
                    {
                        floor[j].child.Add(0);
                        floorMark[0] = true;
                        if (Random.Range(0.0f, 1.0f) >= 0.5)
                        {
                            floor[j].child.Add(1);
                            floorMark[1] = true;
                        }
                    }
                    else
                    {
                        if (j < childNum - 1)
                        {
                            if (Random.Range(0.0f, 1.0f) >= 0.5)
                            {
                                floor[j].child.Add(j);
                                floorMark[j] = true;
                            }
                            if (Random.Range(0.0f, 1.0f) >= 0.5 && j < childNum - 2)
                            {
                                floor[j].child.Add(j + 1);
                                floorMark[j + 1] = true;
                            }
                            if (!floorMark[j])
                            {
                                if (floor[j].child.Count == 0)
                                {
                                    floor[j].child.Add(j);
                                    floorMark[j] = true;
                                }
                                else if (Random.Range(0.0f, 1.0f) >= 0.5)
                                {
                                    floor[j].child.Add(j - 1);
                                    floorMark[j - 1] = true;
                                }
                            }
                            else
                            {
                                if (floor[j].child.Count == 0)
                                {
                                    floor[j].child.Add(j);
                                    floorMark[j] = true;
                                }
                            }
                        }
                        else if (floorMark[childNum - 1])
                        {
                            floor[j].child.Add(childNum - 1);
                            floorMark[childNum - 1] = true;
                        }
                        else
                        {
                            if (Random.Range(0.0f, 1.0f) >= 0.5)
                            {
                                floor[j].child.Add(childNum - 2);
                                floorMark[childNum - 2] = true;
                                if (Random.Range(0.0f, 1.0f) >= 0.5)
                                {
                                    floor[j].child.Add(childNum - 1);
                                    floorMark[childNum - 1] = true;
                                }
                            }
                            else
                            {
                                floor[j].child.Add(childNum - 1);
                                floorMark[childNum - 1] = true;
                            }
                            if (j == floor.Count - 1)
                            {
                                floor[floor.Count - 1].child.Add(childNum - 1);
                                floorMark[childNum - 1] = true;
                            }
                        }
                        for (int m = 0; m < childNum; m++)
                        {
                            if (!floorMark[m])
                            {
                                if (m >= floor.Count)
                                {
                                    floor[floor.Count - 1].child.Add(m);
                                }
                                else
                                {
                                    floor[m].child.Add(m);
                                }
                            }
                        }
                    }
                }
            }
            //指向BOSS
            List <MapNode> floorTop = map[layerCount - 1];

            for (int i = 0; i < floorTop.Count; i++)
            {
                floorTop[i].child.Add(0);
            }
            List <MapNode> bossFloor = new List <MapNode>();
            MapNode        bossNode  = new MapNode();

            bossNode.layer    = layerCount;
            bossNode.nodeType = NodeType.fight;
            bossFloor.Add(bossNode);
            map.Add(bossFloor);
            ///绘制
            float length = mapHight / layerCount;

            for (int i = 0; i < map.Count; i++)
            {
                for (int j = 0; j < map[i].Count; j++)
                {
                    float layerXNum = map[i].Count * -(width / 2) + (width / 2);
                    float layerYNum = 0;
                    if (i == map.Count - 1)
                    {
                        layerYNum = 0;
                    }
                    else
                    {
                        layerYNum = map[i + 1].Count * -(width / 2) + (width / 2);
                    }
                    MapNode mapNode = map[i][j];
                    Color   color;
                    Sprite  nowSprite;
                    if (mapNode.nodeType == NodeType.fight)
                    {
                        color     = Color.green;
                        nowSprite = LoadResources.Instance.fight.disable;
                    }
                    else if (mapNode.nodeType == NodeType.shop)
                    {
                        color     = Color.blue;
                        nowSprite = LoadResources.Instance.shop.disable;
                    }
                    else
                    {
                        color     = Color.red;
                        nowSprite = LoadResources.Instance.random.disable;
                    }
                    //color = Color.red;
                    ButtonEx button;
                    if (i == layerCount)
                    {
                        button = CreatButton(new Vector2(layerXNum + width * j, -(mapHight - buttonWidth) / 2 + length * i + buttonWidth / 2), new Vector2(buttonWidth * 2f, buttonWidth * 2f), nowSprite, Color.red);
                    }
                    else
                    {
                        button = CreatButton(new Vector2(layerXNum + width * j, -(mapHight - buttonWidth) / 2 + length * i), new Vector2(buttonWidth, buttonWidth), nowSprite, Color.white);
                    }
                    map[i][j].button = button;

                    button.onClick.AddListener(delegate()
                    {
                        button.Exit();
                        this.buttonResponse(mapNode);
                    });
                    if (i == 0)
                    {
                        mapNode.FatherIsPass = true;
                    }
                    //Button btn = new Button();
                    for (int m = 0; m < map[i][j].child.Count; m++)
                    {
                        int     num = map[i][j].child[m];
                        mapLine li  = new mapLine();

                        li.x = new Vector2(layerXNum + width * j, -(mapHight / 2 - buttonWidth) + length * i);
                        //if(i==map.Count-1)
                        //li.y = new Vector2(0, -260 + length * (i+1));
                        //else
                        li.y = new Vector2(layerYNum + width * num, -(mapHight / 2) + length * (i + 1));
                        if (i == map.Count - 2)
                        {
                            li.color = Color.red;
                        }
                        else
                        {
                            li.color = Color.white;
                        }
                        render.addLine(li);
                    }
                }
            }
        }
Beispiel #2
0
 /// <summary>
 /// 增加绘制的线
 /// </summary>
 /// <param name="line">line结构体,线的两端,注意位置是像素位置</param>
 public void addLine(mapLine line)
 {
     this.line.Add(line);
 }
Beispiel #3
0
        //初始化地图
        void Init()
        {
            List <List <bool> > mark = new List <List <bool> >();

            //建立结点
            for (int i = 0; i < layerCount; i++)
            {
                List <MapNode> floor     = new List <MapNode>();
                List <bool>    floorMark = new List <bool>();
                int            num       = Random.Range(2, 5);
                for (int j = 0; j < num; j++)
                {
                    MapNode node = new MapNode();
                    node.layer = i;
                    //node属性设置TODO
                    NodeType nodeType = (NodeType)Random.Range(0, (int)NodeType.count);
                    node.nodeType = nodeType;
                    floor.Add(node);
                    floorMark.Add(false);
                }
                map.Add(floor);
                mark.Add(floorMark);
            }
            //填充结点的子节点
            for (int i = 0; i < layerCount - 1; i++)
            {
                List <MapNode> floor     = map[i];
                int            childNum  = map[i + 1].Count;
                List <bool>    floorMark = mark[i + 1];
                float          stand     = childNum / (floor.Count + 0.0f);
                for (int j = 0; j < floor.Count; j++)
                {
                    MapNode node = new MapNode();
                    if (j == 0)
                    {
                        floor[j].child.Add(0);
                        floorMark[0] = true;
                        if (Random.Range(0.0f, 1.0f) >= 0.5)
                        {
                            floor[j].child.Add(1);
                            floorMark[1] = true;
                        }
                    }
                    else
                    {
                        if (j < childNum - 1)
                        {
                            if (Random.Range(0.0f, 1.0f) >= 0.5)
                            {
                                floor[j].child.Add(j);
                                floorMark[j] = true;
                            }
                            if (Random.Range(0.0f, 1.0f) >= 0.5 && j < childNum - 2)
                            {
                                floor[j].child.Add(j + 1);
                                floorMark[j + 1] = true;
                            }
                            if (!floorMark[j])
                            {
                                if (floor[j].child.Count == 0)
                                {
                                    floor[j].child.Add(j);
                                    floorMark[j] = true;
                                }
                                else if (Random.Range(0.0f, 1.0f) >= 0.5)
                                {
                                    floor[j].child.Add(j - 1);
                                    floorMark[j - 1] = true;
                                }
                            }
                            else
                            {
                                if (floor[j].child.Count == 0)
                                {
                                    floor[j].child.Add(j);
                                    floorMark[j] = true;
                                }
                            }
                        }
                        else if (floorMark[childNum - 1])
                        {
                            floor[j].child.Add(childNum - 1);
                            floorMark[childNum - 1] = true;
                        }
                        else
                        {
                            if (Random.Range(0.0f, 1.0f) >= 0.5)
                            {
                                floor[j].child.Add(childNum - 2);
                                floorMark[childNum - 2] = true;
                                if (Random.Range(0.0f, 1.0f) >= 0.5)
                                {
                                    floor[j].child.Add(childNum - 1);
                                    floorMark[childNum - 1] = true;
                                }
                            }
                            else
                            {
                                floor[j].child.Add(childNum - 1);
                                floorMark[childNum - 1] = true;
                            }
                            if (j == floor.Count - 1)
                            {
                                floor[floor.Count - 1].child.Add(childNum - 1);
                                floorMark[childNum - 1] = true;
                            }
                        }
                        for (int m = 0; m < childNum; m++)
                        {
                            if (!floorMark[m])
                            {
                                if (m >= floor.Count)
                                {
                                    floor[floor.Count - 1].child.Add(m);
                                }
                                else
                                {
                                    floor[m].child.Add(m);
                                }
                            }
                        }
                    }
                }
            }
            //指向BOSS
            List <MapNode> floorTop = map[layerCount - 1];

            for (int i = 0; i < floorTop.Count; i++)
            {
                floorTop[i].child.Add(0);
            }

            ///绘制
            int length = 500 / layerCount;

            for (int i = 0; i < map.Count; i++)
            {
                Debug.Log("层");
                for (int j = 0; j < map[i].Count; j++)
                {
                    Debug.Log("节点");
                    int layerXNum = map[i].Count * -50 + 50;
                    int layerYNum = 0;
                    if (i == map.Count - 1)
                    {
                        layerYNum = 0;
                    }
                    else
                    {
                        layerYNum = map[i + 1].Count * -50 + 50;
                    }
                    MapNode mapNode = map[i][j];
                    Color   color;
                    if (mapNode.nodeType == NodeType.fight)
                    {
                        color = Color.green;
                    }
                    else if (mapNode.nodeType == NodeType.shop)
                    {
                        color = Color.blue;
                    }
                    else
                    {
                        color = Color.red;
                    }


                    ButtonEx button = CreatButton(new Vector2(layerXNum + 100 * j, -250 + length * i), new Vector2(20, 20), sprite, color);
                    map[i][j].button = button;

                    button.onClick.AddListener(delegate()
                    {
                        button.Exit();
                        this.buttonResponse(mapNode);
                    });
                    if (i == 0)
                    {
                        mapNode.FatherIsPass = true;
                    }
                    //Button btn = new Button();
                    for (int m = 0; m < map[i][j].child.Count; m++)
                    {
                        Debug.Log(map[i][j].child[m]);
                        int     num = map[i][j].child[m];
                        mapLine li  = new mapLine();

                        li.x = new Vector2(layerXNum + 100 * j, -250 + length * i);
                        //if(i==map.Count-1)
                        //li.y = new Vector2(0, -260 + length * (i+1));
                        //else
                        li.y = new Vector2(layerYNum + 100 * num, -260 + length * (i + 1));
                        render.addLine(li);
                    }
                }
            }
        }