Пример #1
0
 public void Select(out Block block)
 {
     if (mState == State.SELECT)
     {
         block = null;
         return;
     }
     block = this;
     mState = State.SELECT;
     StartCoroutine(scaleCoroutine(selectedScale, .1f));
 }
Пример #2
0
 public void DeSelect(out Block block)
 {
     block = null;
     mState = State.IDLE;
     StartCoroutine(scaleCoroutine(blockScale, .1f));
 }
Пример #3
0
        void swap(Block a, Block b)
        {
            blockList[a._X, a._Y] = b;
            blockList[b._X, b._Y] = a;

            a.SetData();
            b.SetData();
        }
Пример #4
0
 public void FinishedMoveEvent(Block block)
 {
     if (findMatchAtBlock(block))
     {
         matchProcess();
         //emptyDown();
     }
 }
Пример #5
0
        bool findMatchAtBlock(Block block)
        {
            if (block._State == Block.State.MATCH_END) return false;
            bool match = false;
            //Colors color = block.CurrentColor;

            bool hor, ver, left, top, right, bottom;

            hor = CompareColorInHorizontal(block);
            ver = CompareColorInVertical(block);
            left = CompareColorInPattern(MatchData.Direction.LEFT, block);
            top = CompareColorInPattern(MatchData.Direction.TOP, block);
            right = CompareColorInPattern(MatchData.Direction.RIGHT, block);
            bottom = CompareColorInPattern(MatchData.Direction.BOTTOM, block);

            match = hor || ver || left || top || right || bottom;

            if (match)
            {
                if (hor)
                {
                    if (left && right) matchList.Add(new MatchData(MatchData.Direction.RIGHT, 5, block._X - 2, block._Y));
                    else if (left) matchList.Add(new MatchData(MatchData.Direction.RIGHT, 4, block._X - 2, block._Y));
                    else if (right) matchList.Add(new MatchData(MatchData.Direction.RIGHT, 4, block._X - 1, block._Y));
                    else matchList.Add(new MatchData(MatchData.Direction.RIGHT, 3, block._X - 1, block._Y));
                }
                else
                {
                    if (left) matchList.Add(new MatchData(MatchData.Direction.LEFT, 3, block._X, block._Y));
                    if (right) matchList.Add(new MatchData(MatchData.Direction.RIGHT, 3, block._X, block._Y));
                }
                if (ver)
                {
                    if (top && bottom) matchList.Add(new MatchData(MatchData.Direction.TOP, 5, block._X, block._Y - 2));
                    else if (top) matchList.Add(new MatchData(MatchData.Direction.TOP, 4, block._X, block._Y - 1));
                    else if (bottom) matchList.Add(new MatchData(MatchData.Direction.TOP, 4, block._X, block._Y - 2));
                    else matchList.Add(new MatchData(MatchData.Direction.TOP, 3, block._X, block._Y - 1));
                }
                else
                {
                    if (top) matchList.Add(new MatchData(MatchData.Direction.TOP, 3, block._X, block._Y));
                    if (bottom) matchList.Add(new MatchData(MatchData.Direction.BOTTOM, 3, block._X, block._Y));
                }
            }

            return match;
        }
Пример #6
0
 void setHintBlock()
 {
     foreach (Block block in blockList)
     {
         if (checkMatchAtBlock(block))
         {
             hintBlock = block;
         }
     }
 }
Пример #7
0
        /// <summary>
        /// Call at Blocks swap Horizontal
        /// </summary>
        /// 
        bool CompareColorInVertical(Block block)
        {
            int x = block._X;
            int y = block._Y;
            Colors color = block.CurrentColor;

            return (CompareColor(color, x, y - 1) && CompareColor(color, x, y + 1));
        }
Пример #8
0
 void completeSelect()
 {
     StartCoroutine(swapCoroutine());
     firBlock = null;
     secBlock = null;
 }
Пример #9
0
        bool CompareColorInHorizontal(Block block)
        {
            int x = block._X;
            int y = block._Y;
            Colors color = block.CurrentColor;

            return (CompareColor(color, x - 1, y) && CompareColor(color, x + 1, y));
        }
Пример #10
0
        bool CompareColorInPattern(MatchData.Direction dir, Block block)
        {
            int x = block._X;
            int y = block._Y;
            Colors color = block.CurrentColor;

            switch (dir)
            {
                case MatchData.Direction.LEFT:
                    return (CompareColor(color, x - 2, y) && CompareColor(color, x - 1, y));
                case MatchData.Direction.RIGHT:
                    return (CompareColor(color, x + 2, y) && CompareColor(color, x + 1, y));
                case MatchData.Direction.TOP:
                    return (CompareColor(color, x, y + 2) && CompareColor(color, x, y + 1));
                case MatchData.Direction.BOTTOM:
                    return (CompareColor(color, x, y - 2) && CompareColor(color, x, y - 1));
            }

            return false;
        }
Пример #11
0
 bool CompareColor(Colors a, Block b)
 {
     return a == b.CurrentColor;
 }
Пример #12
0
        bool CompareColor(Block block, int fx, int fy, int sx, int sy)
        {
            Colors color = block.CurrentColor;
            int x = block._X;
            int y = block._Y;

            int x1 = x + fx;
            int y1 = y + fy;
            int x2 = x + sx;
            int y2 = y + sy;

            if (x1 < 0 || x1 > width - 1 || x2 < 0 || x2 > width - 1 || y1 < 0 || y1 > height - 1 || y2 < 0 || y2 > height - 1) return false;

            return color == blockList[x1, y1].CurrentColor && color == blockList[x2, y2].CurrentColor;
        }
Пример #13
0
        //check order : left -> right -> top -> bottom
        bool checkMatchAtBlock(Block block)
        {
            /*
            //left
            if (x > 0 && y < height - 2 && CompareColor(block, -1, 1, -1, 2)) return true;
            if (x > 0 && y > 1 && CompareColor(block, -1, -1, -1, -2)) return true;
            if (x > 2 && CompareColor(block, -2, 0, -3, 0)) return true;
            //right
            if (x < width - 1 && y < height - 2 && CompareColor(block, 1, 1, 1, 2)) return true;
            if (x < width - 1 && y > 1 && CompareColor(block, 1, -1, 1, -2)) return true;
            if (x < width - 3 && CompareColor(block, 2, 0, 3, 0)) return true;
            //top
            if (x < width - 2 && y < height - 1 && CompareColor(block, 1, 1, 2, 1)) return true;
            if (x > 1 && y < height - 1 && CompareColor(block, -1, 1, -2, 1)) return true;
            if (y < height - 3 && CompareColor(block, 0, 2, 0, 3)) return true;
            //bottom
            if (x < width - 2 && y > 0 && CompareColor(block, 1, -1, 2, -1)) return true;
            if (x > 1 && y > 0 && CompareColor(block, -1, -1, -2, -1)) return true;
            if (y > 2 && CompareColor(block, 0, -2, 0, -3)) return true;
             * */

            //left
            if (CompareColor(block, -1, 1, -1, 2)) return true;
            if (CompareColor(block, -1, -1, -1, -2)) return true;
            if (CompareColor(block, -2, 0, -3, 0)) return true;
            //right
            if (CompareColor(block, 1, 1, 1, 2)) return true;
            if (CompareColor(block, 1, -1, 1, -2)) return true;
            if (CompareColor(block, 2, 0, 3, 0)) return true;
            //top
            if (CompareColor(block, 1, 1, 2, 1)) return true;
            if (CompareColor(block, -1, 1, -2, 1)) return true;
            if (CompareColor(block, 0, 2, 0, 3)) return true;
            //bottom
            if (CompareColor(block, 1, -1, 2, -1)) return true;
            if (CompareColor(block, -1, -1, -2, -1)) return true;
            if (CompareColor(block, 0, -2, 0, -3)) return true;

            return false;
        }
Пример #14
0
        bool checkMatch(Block block)
        {
            Colors pColor = block.CurrentColor;
            int x = block._X;
            int y = block._Y;

            //left
            if (x > 1 && pColor == blockList[x - 1, y].CurrentColor && pColor == blockList[x - 2, y].CurrentColor) return true;
            //right
            else if (x < width - 2 && pColor == blockList[x + 1, y].CurrentColor && pColor == blockList[x + 2, y].CurrentColor) return true;
            //top
            else if (y < height - 2 && pColor == blockList[x, y + 1].CurrentColor && pColor == blockList[x, y + 2].CurrentColor) return true;
            //bottom
            else if (y > 1 && pColor == blockList[x, y - 1].CurrentColor && pColor == blockList[x, y - 2].CurrentColor) return true;

            return false;
        }
Пример #15
0
        IEnumerator checkCanMatchCoroutine()
        {
            while (isMoving()) yield return null;

            foreach (Block block in blockList)
            {
                if (checkMatchAtBlock(block))
                {
                    if (hintBlock && hintBlock._State != Block.State.HINT)
                        hintBlock = block;
                    yield break;
                }
            }

            AllBlockColorSet();
        }