Пример #1
0
    bool canMove(Piece src, Piece dst, Gesture.Direction dir)
    {
        int dis = dst.idx - src.idx;

        if (1 == dis && Gesture.Direction.Right == dir)
        {
            return(true);
        }
        else if (-1 == dis && Gesture.Direction.Left == dir)
        {
            return(true);
        }
        else if (3 == dis && Gesture.Direction.Up == dir)
        {
            return(true);
        }
        else if (-3 == dis && Gesture.Direction.Down == dir)
        {
            return(true);
        }
        else
        {
            return(false);
        }
    }
Пример #2
0
    private void setDestPosition(Gesture.Direction dir, bool reverse)
    {
        switch (dir)
        {
        case Gesture.Direction.Left:
        {
            destPos = new Vector3(-touchRect.size.x, 0, 0);
            break;
        }

        case Gesture.Direction.Right:
        {
            destPos = new Vector3(touchRect.size.x, 0, 0);
            break;
        }

        case Gesture.Direction.Up:
        {
            destPos = new Vector3(0, touchRect.size.y, 0);
            break;
        }

        case Gesture.Direction.Down:
        {
            destPos = new Vector3(0, -touchRect.size.y, 0);
            break;
        }
        }
        if (reverse)
        {
            destPos = -destPos;
        }
        destPos += gameObject.transform.position;
    }
Пример #3
0
 public void Move(Gesture.Direction dir, bool animation = true, bool reverse = false)
 {
     setDestPosition(dir, reverse);
     if (animation)
     {
         moving = true;
     }
     else
     {
         gameObject.transform.position = destPos;
         if (null != onMoveFinish)
         {
             onMoveFinish();
         }
     }
 }
Пример #4
0
    void OnMoveDirection(Gesture.Direction dir, Vector3 vec)
    {
        Piece p = null;

        foreach (GameObject obj in gameObjs)
        {
            p = obj.GetComponent <Piece> ();
            if (null != p && p.hit(vec))
            {
                break;
            }
            p = null;
        }

        if (null == p)
        {
            Debug.Log("Can't find touch piece");
        }
        else if (p.blank)
        {
            Debug.Log("This is blank, ignore");
        }
        else
        {
            GameObject blank      = getBlankPiece();
            Piece      blankPiece = blank.GetComponent <Piece> ();
            if (canMove(p, blankPiece, dir))
            {
                Debug.Log("Can Move");
                p.Move(dir);
                blankPiece.Move(dir, reverse: true);
                p.idx          = p.idx ^ blankPiece.idx;
                blankPiece.idx = p.idx ^ blankPiece.idx;
                p.idx          = p.idx ^ blankPiece.idx;
            }
            else
            {
                Debug.Log("Can't Move");
                //Debug.Log (string.Format ("Direction: {0}, Vec: {1}", dir, p.gameObject.name));
            }
        }
    }
Пример #5
0
 bool check_is_move(Gesture.Direction direction)
 {
     return(true);
 }
Пример #6
0
 void move(Gesture.Direction direction)
 {
 }