Example #1
0
    public virtual bool Draw(TileDef def)
    {
        Debug.Log(gameObject.name + " draw -> " + def.ToString());

        _drawTile = MahjongTile.Create(def);

        _drawTile.transform.parent = null;

        _drawTile.Direction = MahjongTile.Face.STAND_POSITIVE;
        _angle = Vector3.Angle(Vector3.right, _direction);
        //Debug.Log (angle + "    " + Vector3.right + "," + _direction);
        // unity3d bug from vector3.right to vector3.forward == 90 ?
        if (_direction == Vector3.forward)
        {
            _angle = 270f;
        }

        _drawTile.transform.Rotate(Vector3.forward, _angle, Space.Self);
        _drawTile.transform.parent = PocketLocator;
        Vector3 newPos = (PocketLocator.childCount - 1 + 0.2f) * _direction * MahjongTile.Width;

        _drawTile.Draw(newPos);

        _sortPocketList.Add(_drawTile);
        _proxy.Draw(def);

        return(true);
    }
Example #2
0
    public void ResetPocketList(bool lastGap = false)
    {
        TileDef     def  = null;
        MahjongTile tile = null;

        destroyChildren(PocketLocator);

        if (_direction == Vector3.right)
        {
            //self
            _angle = 0f;
        }
        else if (_direction == Vector3.forward)
        {
            //right
            _angle = -270f;
        }
        else if (_direction == Vector3.left)
        {
            //front
            _angle = -180;
        }
        else if (_direction == -Vector3.forward)
        {
            //left
            _angle = -90f;
        }

        if (_sortPocketList == null)
        {
            _sortPocketList = new List <MahjongTile> ();
        }
        else
        {
            _sortPocketList.Clear();
        }

        Proxy.PocketList.Sort(TileDef.Comparison);
        for (int i = 0; i < Proxy.PocketList.Count; ++i)
        {
            def            = _proxy.PocketList [i];
            tile           = MahjongTile.Create(def);
            tile.Direction = MahjongTile.Face.PLANE_POSITIVE;
            tile.transform.Rotate(Vector3.right, -90f, Space.Self);
            tile.transform.Rotate(-Vector3.forward, _angle, Space.Self);             //local space forward
            tile.transform.parent        = PocketLocator;
            tile.transform.localPosition = i * _direction * MahjongTile.Width;
            _sortPocketList.Add(tile);
        }

        if (lastGap)
        {
            tile.transform.localPosition = (Proxy.PocketList.Count - 0.8f) * _direction * MahjongTile.Width;
        }
    }
Example #3
0
    public void RebuildStack(int a, int b, int count, int drawFront, int drawBehind)
    {
        _wall.Clear();
        MahjongTile    tile = null;
        List <TileDef> list = _proxy.RebuildStack(a, b, count, drawFront, drawBehind);

        for (int i = 0; i < list.Count; ++i)
        {
            tile = MahjongTile.Create(list [i]);
            _wall.Add(tile);
        }
    }
Example #4
0
    public void ResetPlayList()
    {
        TileDef     def  = null;
        MahjongTile tile = null;

        destroyChildren(PlayLocator);

        for (int i = 0; i < Proxy.PlayList.Count; ++i)
        {
            def = Proxy.PlayList [i];
            if (TileDef.IsValid(def.Value))
            {
                tile = MahjongTile.Create(def);
                if (tile != null)
                {
                    placePlayed(tile, false);
                }
            }
        }
    }
Example #5
0
    //random play one tile from network command
    public virtual bool Play(TileDef def)
    {
        MahjongTile tile = null;

        if (((Player)_proxy).Play(def))
        {
            for (int i = 0; i < _sortPocketList.Count; ++i)
            {
                if (_sortPocketList [i].Def.Value == def.Value)
                {
                    _playIndex = i;
                    tile       = _sortPocketList [_playIndex];
                    _sortPocketList.Remove(tile);
                    placePlayed(tile);
                    return(true);
                }
            }
            Debug.Log(_sortPocketList.Count);
            Debug.Log(Proxy.Index + " Play(TileDef def)####################" + _playIndex);
            tile = MahjongTile.Create(def);
            placePlayed(tile);
            _playIndex = Random.Range(0, _sortPocketList.Count);
            tile       = _sortPocketList [_playIndex];
            _sortPocketList.Remove(tile);
            tile.Despawn();
        }
        else
        {
            _proxy.RemovePocketList(1);
            tile = MahjongTile.Create(def);
            placePlayed(tile);
            _playIndex = Random.Range(0, _sortPocketList.Count);
            tile       = _sortPocketList [_playIndex];
            _sortPocketList.Remove(tile);
            tile.Despawn();
        }

        return(false);
    }
Example #6
0
    // param id is a combo list
    public void Combo(TileDef def, int num, int flipNum = 0, bool withAnimation = true)
    {
        MahjongTile tile     = null;
        Vector3     localPos = Vector3.zero;

        if (ComboLocator.childCount > 0)
        {
            localPos = Vector3.zero - MahjongTile.Width * _direction * ComboLocator.childCount - MahjongTile.Width * _direction * 0.2f;
        }
        else
        {
            localPos = Vector3.zero;
        }

        for (int i = 0; i < num; ++i)
        {
            tile = MahjongTile.Create(def);
            tile.Reset();

            if (i < flipNum)
            {
                tile.Direction = MahjongTile.Face.PLANE_NEGTIVE;

                _angle = Vector3.Angle(Vector3.right, _direction);
                //Debug.Log (_angle + "    " + Vector3.right + "," + _direction);
                // unity3d bug from vector3.right to vector3.forward == 90 ?
                if (_direction == Vector3.forward)
                {
                    _angle = 270f;
                }
                tile.transform.Rotate(Vector3.up, _angle, Space.Self);
            }
            else
            {
                _angle = Vector3.Angle(Vector3.right, _direction);
                //Debug.Log (_angle + "    " + Vector3.right + "," + _direction);
                // unity3d bug from vector3.right to vector3.forward == 90 ?
                if (_direction == Vector3.forward)
                {
                    _angle = 270f;
                }
                tile.transform.Rotate(Vector3.up, _angle, Space.Self);
            }

            //往左偏移的起始位置
            tile.transform.parent        = ComboLocator;
            tile.transform.localPosition = localPos - i * MahjongTile.Width * _direction;

            if (withAnimation)
            {
                //再往左偏移一段位置从起始位置起 然后播放动画
                Vector3 localDstPosition = tile.transform.localPosition;
                tile.transform.localPosition = tile.transform.localPosition - _direction * MahjongTile.Width * 3f;

                ActionBase act = MoveTo.Create(0.2f, localDstPosition, true);
                ActionManager.Instance.RunAction(tile.gameObject, act);
            }
        }

        //Debug.Log (_comboLocator.transform.childCount);
    }
Example #7
0
    private IEnumerator initDraw(bool banker)
    {
        _initDrawFinished = false;

        float angle = 0f;

        if (_direction == Vector3.right)
        {
            //self
            angle = 0f;
        }
        else if (_direction == Vector3.forward)
        {
            //right
            angle = -270f;
        }
        else if (_direction == Vector3.left)
        {
            //front
            angle = -180;
        }
        else if (_direction == -Vector3.forward)
        {
            //left
            angle = -90f;
        }

        RotateBy    rb      = null;
        TileDef     def     = null;
        MahjongTile tile    = null;
        Transform   locator = PocketLocator;

        float duration     = 0.1f;
        float waitDuration = 0.3f;

        int index            = 0;
        int drawCountPerTime = 4;

        for (int i = 0; i < 4; ++i)
        {
            if (i == 3)
            {
                drawCountPerTime = 1;
            }

            for (int j = 0; j < drawCountPerTime; ++j)
            {
                //_pile.PopOneTile ();
                def            = _proxy.PocketList [index];
                tile           = MahjongTile.Create(def);
                tile.Direction = MahjongTile.Face.PLANE_NEGTIVE;
                tile.transform.Rotate(Vector3.up, angle, Space.Self);
                tile.transform.parent = locator.transform;

                tile.transform.localPosition = index * _direction * MahjongTile.Width;

                rb = RotateBy.Create(duration, Vector3.right, 90f, Space.Self);
                ActionManager.Instance.RunAction(tile.gameObject, rb);

                //yield return new WaitForSeconds (duration);

                ++index;
            }

            yield return(new WaitForSeconds(waitDuration));
        }

        for (int i = 0; i < locator.childCount; ++i)
        {
            tile = locator.GetChild(i).GetComponent <MahjongTile> ();
            rb   = RotateBy.Create(duration, Vector3.right, -90f, Space.Self);
            ActionManager.Instance.RunAction(tile.gameObject, rb);
        }

        yield return(new WaitForSeconds(waitDuration));

        //_proxy.SortPocketList (TileDef.Comparison);
        _sortPocketList = SortMahjongTile(locator);
        for (int i = 0; i < _sortPocketList.Count; ++i)
        {
            tile = _sortPocketList [i];
            tile.transform.localPosition = i * _direction * MahjongTile.Width;
            rb = RotateBy.Create(duration, Vector3.right, 90f, Space.Self);
            ActionManager.Instance.RunAction(tile.gameObject, rb);
        }

        yield return(new WaitForSeconds(waitDuration));

        if (banker)
        {
            if (_proxy.PocketList.Count == 14)
            {
                def = _proxy.PocketList [13];
                _proxy.RemovePocketList(def, 1);
                Draw(def);
                _drawTile = null;
            }
            else
            {
                def = TileDef.Create();
                Draw(def);
                _drawTile = null;
            }
        }

        _initDrawFinished = true;
    }