示例#1
0
 private void StartTurn()
 {
     ChessPieces.CalculateAllMovementOptions();
     ChessPieces.GetAllMovementOptions();
     if (ChessPieces.MovementOptionsAreAvailable())
     {
         Debug.Log("Moves available");
     }
     else
     {
         string winner = ChessPieces.IsWhiteTurn() ? "Black" : "White";
         Debug.Log(winner + " wins!");
     }
 }
示例#2
0
 private void CheckMouseDown()
 {
     if (Input.GetMouseButtonDown(0))
     {
         if (selectionX >= 0 && selectionY >= 0)
         {
             //Check if a piece is currently selected
             if (selectedPiece == null)
             {
                 ChessPiece targetPiece = ChessPieces.GetPiece(selectionX, selectionY);
                 //Check for piece on selected tile, and if it belongs to the player
                 if (targetPiece != null && targetPiece.isWhite == ChessPieces.IsWhiteTurn() && CanMove(targetPiece))
                 {
                     //Display available movement options
                     DisplayMovementOptions(targetPiece);
                     HighlightPiece(targetPiece);
                     selectedPiece = targetPiece;
                 }
             }
             else
             {
                 //Check if valid movement option
                 if (MovementOptions[selectionX, selectionY])
                 {
                     MovePiece(selectedPiece, selectionX, selectionY);
                     //selectedPiece.SetHasMoved(true);
                     //If pawn reached other side, upgrade!!!
                     turnNumber += 1;
                     StartTurn();
                 }
                 //Deselect Piece
                 UnHighlightPiece(selectedPiece);
                 selectedPiece   = null;
                 MovementOptions = new bool[8, 8];
                 foreach (GameObject square in movementOptionTiles)
                 {
                     Destroy(square);
                 }
             }
         }
     }
 }