예제 #1
0
    private void _suggestMove(cgSimpleMove move)
    {
        cgSquareScript departingSquare = _getSquare(cgGlobal.SquareNames[move.from]);
        cgSquareScript arrivalSquare   = _getSquare(cgGlobal.SquareNames[move.to]);

        departingSquare.highlightTemporarily(new Color(0, .5f, 0));
        arrivalSquare.highlightTemporarily(new Color(0, .5f, 0));
    }
예제 #2
0
 /// <summary>
 /// Start at provided square.
 /// </summary>
 /// <param name="startSquare">the starting square.</param>
 public void StartAtSquare(cgSquareScript startSquare)
 {
     square = startSquare;
     dead   = false;
     if (startSquare != null)
     {
         //piece.SetStartNode(startnode.node);
         transform.position = new Vector3(startSquare.transform.position.x, startSquare.transform.position.y, 0);
     }
 }
예제 #3
0
    /// <summary>
    /// The user has released a dragged piece. Verify that its a legal move, if so perform the move and perform the next move if appropriate mode.
    /// </summary>
    /// <param name="piece"></param>
    private void _pieceUp(cgChessPieceScript piece)
    {
        if (_downPiece != null)
        {
            if (playerCanMove || Mode == BoardMode.PlayerVsPlayer)
            {
                cgSimpleMove        legalMove     = null;
                cgSquareScript      closestSquare = _findSquareAt(_downPiece.transform.position);
                List <cgSimpleMove> legalMoves    = _abstractBoard.findLegalMoves(whiteTurnToMove);
                foreach (cgSimpleMove move in legalMoves)
                {
                    if (cgGlobal.SquareNames[move.from] == _downPiece.square.uniqueName && cgGlobal.SquareNames[move.to] == closestSquare.uniqueName)
                    {
                        legalMove = move;
                    }
                }
                //test legality of move here.

                if (legalMove != null && _abstractBoard.verifyLegality(legalMove))
                {
                    //piece.moveToSquare(closestSquare);
                    _makeMove(legalMove);
                    if (Mode == BoardMode.PlayerVsEngine)
                    {
                        _engine.MakeMove(_abstractBoard, false, _engineCallback);
                    }
                    else if (Mode == BoardMode.EngineVsPlayer)
                    {
                        _engine.MakeMove(_abstractBoard, true, _engineCallback);
                    }
                }
                else
                {
                    piece.moveToSquare(piece.square);
                }
            }
            else
            {
                piece.moveToSquare(piece.square);
            }
            _downPiece = null;
        }
        else
        {
            piece.moveToSquare(piece.square);
            _downPiece = null;
        }
        if (highlightLastMove)
        {//revert colors if highlighting is active
            foreach (cgSquareScript square in _squares)
            {
                square.changeColor(square.startColor);
            }
        }
    }
예제 #4
0
 /// <summary>
 /// Start at provided square.
 /// </summary>
 /// <param name="startSquare">the starting square.</param>
 public void StartAtSquare(cgSquareScript startSquare)
 {
     square = startSquare;
     dead   = false;
     if (startSquare != null)
     {
         //piece.SetStartNode(startnode.node);
         transform.position = new Vector3(startSquare.transform.position.x, startSquare.transform.position.y, startSquare.transform.position.z);
     }
     //UnityEngine.Debug.Log("Start square: " + startSquare);
 }
예제 #5
0
    /// <summary>
    /// Find the square location at the provided position, used to find the square where the user is dragging and dropping a piece.
    /// </summary>
    /// <param name="position"></param>
    /// <returns></returns>
    private cgSquareScript _findSquareAt(Vector3 position)
    {
        float          best   = Vector3.Distance(position, _squares[0].transform.position);
        cgSquareScript square = _squares[0];

        foreach (cgSquareScript candsquare in _squares)
        {
            if (Vector3.Distance(position, candsquare.transform.position) < best)
            {
                best   = Vector3.Distance(position, candsquare.transform.position);
                square = candsquare;
            }
        }
        return(square);
    }
예제 #6
0
    /// <summary>
    /// Move to a new square.
    /// </summary>
    /// <param name="newSquare">the new square to move to.</param>
    public void moveToSquare(cgSquareScript newSquare)
    {
        transform.position = new Vector3(newSquare.transform.position.x, newSquare.transform.position.y, newSquare.transform.position.z);

        square = newSquare;
    }