Esempio n. 1
0
    private SequencePipe GetPipeFromPool()
    {
        SequencePipe res = null;

        // try take from pool
        for (int i = 0; i < _pipesPool.Count; ++i)
        {
            GameObject obj = _pipesPool[i].AGameObject;
            if (!obj.activeSelf)
            {
                res = _pipesPool[i];
                LeanTween.cancel(obj);
                res.ATransform.SetParent(Container, false);
                obj.SetActive(true);
                return(res);
            }
        }
        // create new
        GameObject pipeObj = (GameObject)GameObject.Instantiate(PipePrefab, Vector3.zero, Quaternion.identity);

        res = pipeObj.GetComponent <SequencePipe>();
        res.ATransform.SetParent(Container, false);
        _pipesPool.Add(res);
        return(res);
    }
Esempio n. 2
0
 public void LoadPanel(List <int> state)
 {
     for (int i = 0; i < _sequence.Count; ++i)
     {
         if (_sequence[i] != null)
         {
             _sequence[i].gameObject.SetActive(false);
             _sequence[i] = null;
         }
     }
     if (state.Count == 0)
     {
         for (int i = 0; i <= SIZE; ++i)
         {
             state.Add(GameManager.Instance.BoardData.GetRandomColor());
         }
     }
     //create full queue at start
     for (int i = 1; i <= SIZE; ++i)
     {
         EPipeType ptype  = EPipeType.Colored;
         int       param  = 0;
         int       acolor = state[i - 1];
         if (acolor == -1)
         {
             ptype  = EPipeType.Blocker;
             acolor = -1;
             param  = -1;
         }
         SequencePipe pipe = CreatePipe(ptype, acolor, param);
         pipe.ATransform.localPosition = _slotsPoses[i];
         _sequence[i] = pipe;
     }
 }
Esempio n. 3
0
    private SequencePipe CreatePipe(EPipeType pipeType, int acolor, int param)
    {
        SequencePipe pipe = GetPipeFromPool();

        pipe.InitPipe(pipeType, acolor, param);
        Transform pipeTransf = pipe.ATransform;

        pipeTransf.localScale = new Vector3(PIPES_SCALE, PIPES_SCALE, 1);
        return(pipe);
    }
Esempio n. 4
0
    void OnCombineWasMade(EventData e)
    {
        // add new pipe to last slot
        int acolor = (int)e.Data["acolor"];
        int param  = (int)e.Data["param"];
        //bool isdouble = (bool)e.Data["double"];
        SequencePipe pipe = GetPipeFromPool();

        pipe.InitPipe(EPipeType.Colored, acolor, param);
        Transform pipeTransf = pipe.ATransform;

        pipeTransf.localScale    = new Vector3(PIPES_SCALE, PIPES_SCALE, 1);
        pipeTransf.localPosition = _slotsPoses[_lastSlot];
        // move prev pipes to the left
        for (int i = 1; i <= SIZE; ++i)
        {
            if (_sequence[i] == null)
            {
                continue;
            }
            int          newi = i - 1;
            SequencePipe p    = _sequence[i];
            GameObject   pobj = p.AGameObject;
            LeanTween.cancel(p.gameObject);
            if (newi == 0)
            {
                // move to the left and remove
                LeanTween.moveLocalX(pobj, _slotsPoses[newi].x, MOVE_SPEED)
                .setOnComplete
                (
                    () =>
                {
                    pobj.SetActive(false);
                }
                );
            }
            else
            {
                // just move to the left
                _sequence[newi] = p;
                LeanTween.moveLocalX(pobj, _slotsPoses[newi].x, MOVE_SPEED);
            }
        }
        // move new pipe
        _sequence[SIZE] = pipe;
        LeanTween.moveLocalX(pipe.AGameObject, _slotsPoses[SIZE].x, MOVE_SPEED)
        .setOnComplete
        (
            () =>
        {
            CheckIfSomeSequenceCompleted();
        }
        );
        //
    }
Esempio n. 5
0
    public void MoveQueue(EPipeType pipeType, int acolor, int param)
    {
        // add new pipe to last slot
        SequencePipe pipe = CreatePipe(pipeType, acolor, param);

        pipe.ATransform.localPosition = _slotsPoses[_lastSlot];
        // move prev pipes to the left
        for (int i = 1; i <= SIZE; ++i)
        {
            if (_sequence[i] == null)
            {
                continue;
            }
            int          newi = i - 1;
            SequencePipe p    = _sequence[i];
            GameObject   pobj = p.AGameObject;
            LeanTween.cancel(p.gameObject);
            if (newi == 0)
            {
                // move to the left and remove
                LeanTween.moveLocalX(pobj, _slotsPoses[newi].x, MOVE_SPEED)
                .setOnComplete
                (
                    () =>
                {
                    pobj.SetActive(false);
                }
                );
            }
            else
            {
                // just move to the left
                _sequence[newi] = p;
                LeanTween.moveLocalX(pobj, _slotsPoses[newi].x, MOVE_SPEED);
            }
        }
        // move new pipe
        _sequence[SIZE] = pipe;
        LeanTween.moveLocalX(pipe.AGameObject, _slotsPoses[SIZE].x, MOVE_SPEED);
        //
    }
Esempio n. 6
0
    void ResetPanel()
    {
        for (int i = 0; i < _sequence.Count; ++i)
        {
            if (_sequence[i] != null)
            {
                _sequence[i].gameObject.SetActive(false);
                _sequence[i] = null;
            }
        }

        //create full queue at start
        for (int i = 1; i <= SIZE; ++i)
        {
            SequencePipe pipe = CreatePipe(EPipeType.Colored, GameManager.Instance.BoardData.GetRandomColor(), 0);
            {
                pipe.ATransform.localPosition = _slotsPoses[i];
                _sequence[i] = pipe;
            }
        }
    }
Esempio n. 7
0
    private void CheckIfSomeSequenceCompleted()
    {
        // check if all SIZE pipes
        for (int i = 1; i <= SIZE; ++i)
        {
            if (_sequence[i] == null)
            {
                return;
            }
        }
        //
        List <SequencePipe> orderedPipes = new List <SequencePipe>();

        for (int i = 1; i <= SIZE; ++i)
        {
            orderedPipes.Add(_sequence[i]);
        }
        for (int i = 0; i < orderedPipes.Count - 1; ++i)
        {
            for (int j = i + 1; j < orderedPipes.Count; ++j)
            {
                if (orderedPipes[j].Param < orderedPipes[j - 1].Param)
                {
                    SequencePipe temp = orderedPipes[j];
                    orderedPipes[j]     = orderedPipes[j - 1];
                    orderedPipes[j - 1] = temp;
                }
            }
        }

        //
        bool isSameColor = true;

        for (int i = 1; i < orderedPipes.Count; ++i)
        {
            if (orderedPipes[i].AColor != orderedPipes[0].AColor)
            {
                isSameColor = false;
                break;
            }
        }
        //
        bool isSameParam = true;

        for (int i = 1; i < orderedPipes.Count; ++i)
        {
            if (orderedPipes[i].Param != orderedPipes[0].Param)
            {
                isSameParam = false;
                break;
            }
        }
        //
        if (isSameColor)
        {
            if (isSameParam)
            {
                StartCoroutine(OnSequenceCompleted(orderedPipes, ESequenceType.Identical));
                return;
            }
        }
        else
        if (isSameParam)
        {
            StartCoroutine(OnSequenceCompleted(orderedPipes, ESequenceType.SameParam));
            return;
        }
        //
        bool isStraight = true;

        for (int i = 1; i < orderedPipes.Count; ++i)
        {
            if (orderedPipes[i].Param != (orderedPipes[i - 1].Param + 1))
            {
                isStraight = false;
                break;
            }
        }
        //
        if (isStraight)
        {
            if (isSameColor)
            {
                StartCoroutine(OnSequenceCompleted(orderedPipes, ESequenceType.SuperStraight));
                return;
            }
            else
            {
                StartCoroutine(OnSequenceCompleted(orderedPipes, ESequenceType.Straight));
                return;
            }
        }
        else
        if (isSameColor)
        {
            StartCoroutine(OnSequenceCompleted(orderedPipes, ESequenceType.SameColor));
            return;
        }
    }