コード例 #1
0
    public BlockData GetNextCombinableBlock(GamingLogic2048.EPushingDirection _direction) //獲得某個方位上的下一個可結合之格子,沒辦法的話就回傳null
    {
        BlockData nextCombinableBlock = null;
        BlockData nextBlock           = this.GetNeighbor(_direction);

        if (nextBlock != null)
        {
            if (nextBlock.Conbinable)
            {
                nextCombinableBlock = nextBlock;
            }
            else
            {
                switch (nextBlock.m_eBlockType)
                {
                case EBlockType.Obstruct:     //障礙格子什麼也不做,自然的讓函式回傳null
                    nextCombinableBlock = null;
                    break;

                case EBlockType.None:     //空洞格子會一路繼續找下去,直到找到底或著下個可判斷的格子為止
                    nextCombinableBlock = nextBlock.GetNextCombinableBlock(_direction);
                    break;
                }
            }
        }
        return(nextCombinableBlock);
    }
コード例 #2
0
    public void SetNeighbor(BlockData _anotherBlock, GamingLogic2048.EPushingDirection _eDirection)
    {
        int iThisToNeighbor = (int)_eDirection;                                       //自己看鄰居的方向
        int iNeighborToThis = (int)GamingLogic2048.GetOppositeDirection(_eDirection); //鄰居看自己的方向

        this.m_arrNeighbor[iThisToNeighbor]          = _anotherBlock;
        _anotherBlock.m_arrNeighbor[iNeighborToThis] = this;
    }
コード例 #3
0
    public bool TryToCombine(GamingLogic2048.EPushingDirection _direction)
    {
        bool      bCanCombine  = false;
        BlockData anotherBlock = this.GetNeighbor(_direction);

        if (anotherBlock != null)
        {
            switch (anotherBlock.m_eBlockType)
            {
            case EBlockType.Normal:
                bCanCombine = true;
                break;

            case EBlockType.Obstruct:
                bCanCombine = false;
                break;

            case EBlockType.None:
                bCanCombine = anotherBlock.TryToCombine(_direction);
                break;
            }
        }
        return(bCanCombine);
    }
コード例 #4
0
    public BlockData GetNeighbor(GamingLogic2048.EPushingDirection _direction)
    {
        int iThisToNeighbor = (int)_direction; //自己看鄰居的方向

        return(this.m_arrNeighbor[iThisToNeighbor]);
    }