Beispiel #1
0
    /// <summary>
    /// 逻辑:场上移动麻将到指定层位置
    /// </summary>
    /// <param name="index">Index.-1视为可撤销位置</param>
    /// <param name="layer">Layer.-1视为可撤销位置</param>
    private void MoveCardsLogicalTo(BaseCard baseCards, int index, int layer, bool needRemoveDict = true)
    {
        //目前只记录到可撤销位置时的移动记录
        if (index < 0 || layer < 0)
        {
            CardsEvent cardsEvent = new CardsEvent();
            cardsEvent.targetsCardsList.Add(baseCards);
            cardsEvent.originLayerList.Add(baseCards.Layer);
            cardsEvent.originIndexCardsList.Add(baseCards.Index);
            _cardMoveHistory.Enqueue(cardsEvent);
            Debug.Log("记录撤销位置" + _cardMoveHistory.Count);
        }

        //当洗牌时,不需要移动前清楚原位置记录,因可能清掉新的已经移动到原位置上的牌组
        //update bound index recording
        for (int w = 0; w < baseCards.leftIndexs.Length; w++)
        {
            RemoveOccupyIndex(baseCards.leftIndexs[w], baseCards.Layer);
            RemoveOccupyIndex(baseCards.rightIndexs[w], baseCards.Layer);
        }
        RemoveOccupyIndex(baseCards.Index, baseCards.Layer);
        RemoveOccupyIndex(baseCards.leftIndexs[0] + 1, baseCards.Layer);
        RemoveOccupyIndex(baseCards.leftIndexs[2] + 1, baseCards.Layer);

        if (needRemoveDict)
        {
            RemoveFromDict(baseCards.Layer, baseCards, false);
        }

        //定义:大于0的位置为棋盘位置,否则视为可撤销位置
        if (index > -1)
        {
            //init all params
            baseCards.Layer = layer;
            baseCards.Index = index;
            baseCards.UpdateBounds(_colPointsNum, _rowPointsNum);
            baseCards.cardObj.transform.name = string.Format("{0}_{1}", baseCards.Layer.ToString(), baseCards.Index.ToString());

            //update bound index recording
            for (int w = 0; w < baseCards.leftIndexs.Length; w++)
            {
                AddOccupyIndex(baseCards.leftIndexs[w], baseCards.Layer);
                AddOccupyIndex(baseCards.rightIndexs[w], baseCards.Layer);
            }
            AddOccupyIndex(baseCards.Index, baseCards.Layer);
            AddOccupyIndex(baseCards.leftIndexs[0] + 1, baseCards.Layer);
            AddOccupyIndex(baseCards.leftIndexs[2] + 1, baseCards.Layer);

            AddToDict(layer, baseCards);
        }
    }