Exemplo n.º 1
0
        private void check(path pd)
        {
            switch (pd.dir) //0 none, 1 up, 2 down, 3 left, 4 right
            {
            case direction.up:
            {
                if (pd.id - width > 0)
                {
                    if (!p[pd.id - width].selected)
                    {
                        addtoPath(direction.up, pd.id - width);         //up
                    }
                }
                if (pd.id % width != 0)
                {
                    if (!p[pd.id - 1].selected)
                    {
                        addtoPath(direction.left, pd.id - 1);           //left
                    }
                }
                if ((pd.id + 1) % width != 0)
                {
                    if (!p[pd.id + 1].selected)
                    {
                        addtoPath(direction.right, pd.id + 1);          //right
                    }
                }
                break;
            }

            case direction.down:
            {
                if (pd.id + width < total)
                {
                    if (!p[pd.id + width].selected)
                    {
                        addtoPath(direction.down, pd.id + width);           //down
                    }
                }
                if (pd.id % width != 0)
                {
                    if (!p[pd.id - 1].selected)
                    {
                        addtoPath(direction.left, pd.id - 1);           //left
                    }
                }
                if ((pd.id + 1) % width != 0)
                {
                    if (!p[pd.id + 1].selected)
                    {
                        addtoPath(direction.right, pd.id + 1);          //right
                    }
                }
                break;
            }

            case direction.left:
            {
                if (pd.id - width > 0)
                {
                    if (!p[pd.id - width].selected)
                    {
                        addtoPath(direction.up, pd.id - width);         //up
                    }
                }
                if (pd.id + width < total)
                {
                    if (!p[pd.id + width].selected)
                    {
                        addtoPath(direction.down, pd.id + width);           //down
                    }
                }
                if (pd.id % width != 0)
                {
                    if (!p[pd.id - 1].selected)
                    {
                        addtoPath(direction.left, pd.id - 1);           //left
                    }
                }
                break;
            }

            case direction.right:
            {
                if (pd.id - width > 0)
                {
                    if (!p[pd.id - width].selected)
                    {
                        addtoPath(direction.up, pd.id - width);         //up
                    }
                }
                if (pd.id + width < total)
                {
                    if (!p[pd.id + width].selected)
                    {
                        addtoPath(direction.down, pd.id + width);           //down
                    }
                }
                if ((pd.id + 1) % width != 0)
                {
                    if (!p[pd.id + 1].selected)
                    {
                        addtoPath(direction.right, pd.id + 1);          //right
                    }
                }
                break;
            }

            case direction.none:
            {
                if (pd.id - width > 0)
                {
                    if (!p[pd.id - width].selected)
                    {
                        addtoPath(direction.up, pd.id - width);         //up
                    }
                }
                if (pd.id + width < total)
                {
                    if (!p[pd.id + width].selected)
                    {
                        addtoPath(direction.down, pd.id + width);           //down
                    }
                }
                if (pd.id % width != 0)
                {
                    if (!p[pd.id - 1].selected)
                    {
                        addtoPath(direction.left, pd.id - 1);           //left
                    }
                }
                if ((pd.id + 1) % width != 0)
                {
                    if (!p[pd.id + 1].selected)
                    {
                        addtoPath(direction.right, pd.id + 1);          //right
                    }
                }
                break;
            }
            }
        }