Esempio n. 1
0
    public BtnColor SetBtnInfo(int x1, int y1, string a)
    {
        GameObject go  = Resources.Load <GameObject>(@"Prefabs\BtnColor\" + a.ToString());
        Transform  go1 = transform.GetChild(x1).GetChild(y1);

        go1.GetComponent <SpriteRenderer>().DOFade(0, 0.01f);
        mapCtrl.GetMapOne(x1, y1).IsObstacle = true;
        GameObject go3 = Instantiate(go);

        SetParentInit(go1, go3.transform);
        BtnColor BtnCol1 = go3.transform.GetChild(0).GetComponent <BtnColor>();

        BtnCol1.AddBtnPath(mapCtrl.GetMapOne((int)go1.position.x, (int)go1.position.y));
        BtnCol1.mColor = BtnCol1.GetComponent <SpriteRenderer>().color;
        mapCtrl.AddColors(BtnCol1);
        return(BtnCol1);
    }
Esempio n. 2
0
    public void SetTipPaht()
    {
        if (GoldSystem.Instance.GetGoldMount(0) < 5)
        {
            return;
        }
        GoldSystem.Instance.GetGoldMount(-5);
        View.Instance.GameUI.SetGoldCount();
        View.Instance.PlayUI.SetGoldCount();
        int rodom = UnityEngine.Random.Range(0, ks.Count);

        if (ks.Count == 0)
        {
            return;
        }
        BtnColor btn = BtnColors[ks[rodom]];

        ks.Remove(ks[rodom]);
        MapOne mapOne2 = btn.HelpPos[1];

        btn.HelpPos.RemoveAt(1);
        btn.AddHelpPath(mapOne2);
        if (btn.IsFinished)
        {
            bool          b      = true;
            List <MapOne> isTrue = new List <MapOne>();
            isTrue.Add(GetMapOne((int)btn.mPosition.x, (int)btn.mPosition.y));
            for (int i = 0; i < btn.HelpPos.Count - 1; i++)
            {
                Vector2 Path = btn.HelpPos[i + 1].mPosition - btn.HelpPos[i].mPosition;
                MapOne  one  = new MapOne();
                one.XPosition = -1;
                one.YPosition = -1;
                if (Path.x != 0)
                {
                    int d = (int)btn.HelpPos[i].XPosition;
                    while (one.XPosition != btn.HelpPos[i + 1].XPosition)
                    {
                        d  += (int)(Path.x / Mathf.Abs(Path.x));
                        one = GetMapOne(d, (int)btn.HelpPos[i].YPosition);
                        isTrue.Add(one);
                    }
                }
                else
                {
                    int c = (int)btn.HelpPos[i].YPosition;
                    while (one.YPosition != btn.HelpPos[i + 1].YPosition)
                    {
                        c  += (int)(Path.y / Mathf.Abs(Path.y));
                        one = GetMapOne((int)btn.HelpPos[i].XPosition, c);
                        isTrue.Add(one);
                    }
                }
            }
            if (isTrue.Count == btn.BtnPath.Count || isTrue.Count == btn.mTargetBtnColor.BtnPath.Count)
            {
                if (isTrue.Count == btn.BtnPath.Count)
                {
                    for (int i = 0; i < isTrue.Count; i++)
                    {
                        b = b && btn.BtnPath.Contains(isTrue[i]);
                    }
                }
                else
                {
                    for (int i = 0; i < isTrue.Count; i++)
                    {
                        b = b && btn.mTargetBtnColor.BtnPath.Contains(isTrue[i]);
                    }
                }
            }
            else
            {
                b = false;
            }
            if (b)
            {
                isTrue.Clear();
                SetTipPaht();
                return;
            }
            b = true;
        }
        btn.PathActives.Clear();
        SetAllNOActives(btn);
        if (btn.BtnPath.Count != 1)
        {
            btn.BtnPath.RemoveRange(1, btn.BtnPath.Count - 1);
        }
        if (btn.mTargetBtnColor.BtnPath.Count != 1)
        {
            btn.mTargetBtnColor.BtnPath.RemoveRange(1, btn.mTargetBtnColor.BtnPath.Count - 1);
        }
        for (int i = 0; i < btn.HelpPos.Count - 1; i++)
        {
            Vector2 Path      = btn.HelpPos[i + 1].mPosition - btn.HelpPos[i].mPosition;
            float   XPosition = -1;
            float   YPosition = -1;
            if (Path.x != 0)
            {
                int d = (int)btn.HelpPos[i].XPosition;
                while (XPosition != btn.HelpPos[i + 1].XPosition)
                {
                    d        += (int)(Path.x / Mathf.Abs(Path.x));
                    XPosition = GetMapOne(d, (int)btn.HelpPos[i].YPosition).XPosition;
                    btn.AddBtnPath(GetMapOne(d, (int)btn.HelpPos[i].YPosition));
                }
            }
            else
            {
                int c = (int)btn.HelpPos[i].YPosition;
                while (YPosition != btn.HelpPos[i + 1].YPosition)
                {
                    c        += (int)(Path.y / Mathf.Abs(Path.y));
                    YPosition = GetMapOne((int)btn.HelpPos[i].XPosition, c).YPosition;
                    btn.AddBtnPath(GetMapOne((int)btn.HelpPos[i].XPosition, c));
                }
            }
        }
        btn.GetComponent <BoxCollider2D>().enabled = false;
        btn.mTargetBtnColor.GetComponent <BoxCollider2D>().enabled = false;
        GetHasPathToOther(btn);
        btn.IsFinished = true;
        btn.transform.Find("HelpUI").gameObject.SetActive(true);
        btn.mTargetBtnColor.IsFinished = true;
        btn.mTargetBtnColor.transform.Find("HelpUI").gameObject.SetActive(true);
        btn.maps = btn.BtnPath;
        foreach (MapOne one in btn.BtnPath)
        {
            one.GameOne.transform.Find("TrailDrag").GetComponent <BoxCollider2D>().enabled = false;
            one.IsObstacle = true;
            if (btn.BtnPath[btn.BtnPath.Count - 1] != one)
            {
                btn.AddPathActive(one);
            }
        }
        source.clip = AutoLine;
        source.Play();
        View.Instance.GameUI.SetFootCountTxt();
    }
Esempio n. 3
0
    private void Update()
    {
        int x  = (int)Math.Round(this.transform.position.x);
        int y  = (int)Math.Round(this.transform.position.y);
        int x1 = (int)Math.Round(this.transform.position.x) - (int)transform.parent.parent.position.x;
        int y1 = (int)Math.Round(this.transform.position.y) - (int)transform.parent.parent.position.y;

        if (Mathf.Abs(x1) >= 0 || Mathf.Abs(y1) >= 0)
        {
            MapOne   TargetOne  = mapCtrl.GetMapOne(x, y);
            BtnColor currentBtn = this.transform.parent.GetChild(0).GetComponent <BtnColor>();
            if (x >= LevelCreateSys.Col || y >= LevelCreateSys.Row || x < 0 || y < 0)
            {
                return;
            }
            if (TargetOne.IsObstacle == false || currentBtn.mTargetBtnColor.mPosition == new Vector2(x, y) || TargetOne.mPosition == currentBtn.mPosition)
            {
                if (TargetOne == currentBtn.BtnPath[currentBtn.BtnPath.Count - 1])
                {
                    return;
                }
                else
                {
                    if (!currentBtn.IsFinished && !(kk == x1 && xx == y1))
                    {
                        mapCtrl.source.clip = mapCtrl.mButton;
                        mapCtrl.source.Play();
                        kk = x1;
                        xx = y1;
                    }
                }

                BtnColor TragetBtn = mapCtrl.GetBtnForPath(TargetOne, currentBtn);
                if (TragetBtn != null)
                {
                    TragetBtn.IsFinished = false;
                    TragetBtn.mTargetBtnColor.IsFinished = false;
                    int remove = TragetBtn.BtnPath.IndexOf(TargetOne);
                    TragetBtn.BtnPath.RemoveRange(remove, TragetBtn.BtnPath.Count - remove);
                }
                else
                {
                    mapCtrl.GetHasPathToOther(currentBtn);
                }
                //判断是否可以继续运动,如果按钮的状态没有完成则无法运动
                if (currentBtn.IsFinished)
                {
                    if (!currentBtn.BtnPath.Contains(TargetOne))
                    {
                        return;
                    }
                    else
                    {
                        currentBtn.IsFinished = false;
                    }
                    currentBtn.mTargetBtnColor.IsFinished = false;
                }
                //判断 当前路线是否重合,重合整理路线
                if (currentBtn.BtnPath.Contains(TargetOne))
                {
                    if (currentBtn.BtnPath.Count != 1)
                    {
                        int remove = currentBtn.BtnPath.IndexOf(TargetOne);
                        currentBtn.BtnPath.RemoveRange(remove + 1, currentBtn.BtnPath.Count - remove - 1);
                    }
                }
                else
                {
                    currentBtn.AddBtnPath(TargetOne);
                    int   Count = currentBtn.BtnPath.Count;
                    float xoff  = Math.Abs(currentBtn.BtnPath[Count - 1].XPosition - currentBtn.BtnPath[Count - 2].XPosition);
                    float yoff  = Math.Abs(currentBtn.BtnPath[Count - 1].YPosition - currentBtn.BtnPath[Count - 2].YPosition);
                    //判断当前运动的位置是否发生大规模运动
                    if (xoff + yoff != 1)
                    {
                        //ToDo 高速度的响应解决方案  --->
                        currentBtn.BtnPath[currentBtn.BtnPath.Count - 2].GameOne.transform.GetChild(2).gameObject.SetActive(false);
                        List <MapOne> a1 = new List <MapOne>();
                        if (currentBtn.mTargetBtnColor.mPosition == TargetOne.mPosition)
                        {
                            TargetOne.IsObstacle = false;
                            mapCtrl.GetMapOne((int)currentBtn.mPosition.x, (int)currentBtn.mPosition.y).IsObstacle = false;
                            a1 = AStart.GetInstance.GetPath
                                     (mapCtrl.GetMapOne((int)currentBtn.BtnPath[Count - 2].XPosition, (int)currentBtn.BtnPath[Count - 2].YPosition),
                                     TargetOne);
                            TargetOne.IsObstacle = true;
                        }
                        else
                        {
                            mapCtrl.GetMapOne((int)currentBtn.mPosition.x, (int)currentBtn.mPosition.y).IsObstacle = false;
                            a1 = AStart.GetInstance.GetPath
                                     (mapCtrl.GetMapOne((int)currentBtn.BtnPath[Count - 2].XPosition, (int)currentBtn.BtnPath[Count - 2].YPosition),
                                     TargetOne);
                        }
                        mapCtrl.GetMapOne((int)currentBtn.mPosition.x, (int)currentBtn.mPosition.y).IsObstacle = true;
                        if (a1 == null || a1.Count == 0)
                        {
                            currentBtn.BtnPath.Remove(TargetOne); return;
                        }
                        else
                        {
                            if (isHas(a1, currentBtn))
                            {
                                int index = IndexMin(a1, currentBtn);
                                currentBtn.BtnPath.RemoveRange(index + 1, currentBtn.BtnPath.Count - index - 1);
                                foreach (MapOne cc in a1)
                                {
                                    int cx     = a1.IndexOf(cc);
                                    int insert = a1.IndexOf(currentBtn.BtnPath[index]);
                                    if (cx == 0 || cx == a1.Count - 1)
                                    {
                                        continue;
                                    }
                                    if (a1.IndexOf(cc) <= insert)
                                    {
                                        int Inde = insert - cx;
                                        currentBtn.BtnPath.Add(a1[Inde]);
                                    }
                                }
                            }
                            else
                            {
                                foreach (MapOne c in a1)
                                {
                                    if (c == a1[a1.Count - 1] || c == a1[0])
                                    {
                                        continue;
                                    }
                                    if (c == a1[a1.Count - 1] && c == a1[0])
                                    {
                                        continue;
                                    }
                                    int index = a1.Count - a1.IndexOf(c) - 1;
                                    currentBtn.BtnPath.Insert(currentBtn.BtnPath.Count - 1, a1[index]);
                                }
                            }
                        }
                        mapCtrl.GetHasPathToOther(currentBtn);
                    }
                }
                if (currentBtn.mTargetBtnColor.mPosition == new Vector2(x, y))
                {
                    View.Instance.GameUI.SetFootCountTxt();
                    currentBtn.IsFinished = true;
                    currentBtn.mTargetBtnColor.IsFinished = true;
                    if (currentBtn.mColorGame.transform.Find("HelpUI").gameObject.activeSelf == false)
                    {
                        mapCtrl.source.clip = mapCtrl.Winline;
                        mapCtrl.source.Play();
                    }
                }
                if (currentBtn.BtnPath.Count >= 2)
                {
                    MapOne one;
                    for (int i = 0; i < currentBtn.BtnPath.Count - 1; i++)
                    {
                        Vector2 ks = currentBtn.BtnPath[i + 1].mPosition - currentBtn.BtnPath[i].mPosition;
                        if (ks.x + ks.y > 1)
                        {
                            one = currentBtn.BtnPath[i + 1];
                            currentBtn.BtnPath.RemoveRange(i + 1, currentBtn.BtnPath.Count - i - 1);
                        }
                    }
                }
            }
        }
    }