Esempio n. 1
0
    private bool Trymove2(int x1, int y1, int x2, int y2, Pices select, Pices[,] pices)
    {
        bool rightmove = false, Killed = false;

        select = pices[x1, y1];
        List <Pices> forcedPieces = ScanforPossibleMove(x1, y1, pices);
        //multiplayer support
        Vector2 startDrag = new Vector2(x1, y1);
        Vector2 endDrag   = new Vector2(x2, y2);


        //out of bounds
        if (x2 < 0 || x2 >= 8 || y2 < 0 || y2 >= 8)
        {
            return(false);
            // if (select != null)
            //    rightmove = false;

            //let the piece be at the same position
        }
        //if the start drag and the stop drag is same
        if (select != null)
        {
            if (endDrag == startDrag)
            {
                rightmove = false;
            }
        }
        //check if its vaild move
        if (select.ValidMove(pices, x1, y1, x2, y2))
        {
            if (Mathf.Abs(x2 - x1) == 2)
            {
                Pices p = pices[(x1 + x2) / 2, (y1 + y2) / 2];
                if (p != null)
                {
                    Killed = true;
                }
            }

            if (forcedPieces.Count != 0 && !Killed)
            {
                rightmove = false;
            }

            rightmove = true;
        }
        else
        {
            rightmove = false;
        }
        return(rightmove);
    }
Esempio n. 2
0
    private void Trymove(int x1, int y1, int x2, int y2)
    {
        forcedPieces = ScanforPossibleMove();
        //multiplayer support
        startDrag     = new Vector2(x1, y1);
        endDrag       = new Vector2(x2, y2);
        selectedPiece = pices[x1, y1];

        //out of bounds
        if (x2 < 0 || x2 >= 8 || y2 < 0 || y2 >= 8)
        {
            if (selectedPiece != null)
            {
                MovePiece(selectedPiece, x1, y1);
            }


            selectedPiece = null;
            startDrag     = Vector2.zero;
            return;
        }

        if (selectedPiece != null)
        {
            if (endDrag == startDrag)
            {
                MovePiece(selectedPiece, x1, y1);
                selectedPiece = null;
                startDrag     = Vector2.zero;
                return;
            }
        }
        //check if its vaild move
        if (selectedPiece.ValidMove(pices, x1, y1, x2, y2))
        {
            if (Mathf.Abs(x2 - x1) == 2)
            {
                Pices p = pices[(x1 + x2) / 2, (y1 + y2) / 2];
                if (p != null)
                {
                    pices[(x1 + x2) / 2, (y1 + y2) / 2] = null;
                    Destroy(p.gameObject);
                    hasKilled = true;
                }
            }

            if (forcedPieces.Count != 0 && !hasKilled)
            {
                MovePiece(selectedPiece, x1, y1);
                selectedPiece = null;
                startDrag     = Vector2.zero;
                return;
            }

            pices[x2, y2] = selectedPiece;
            pices[x1, y1] = null;
            MovePiece(selectedPiece, x2, y2);

            EndTurn();
        }
        else
        {
            MovePiece(selectedPiece, x1, y1);
            selectedPiece = null;
            startDrag     = Vector2.zero;
            return;
        }

        //  MovePiece(selectedPiece, x2, y2);
    }