Exemplo n.º 1
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);
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            // Declare a new object
            var piece = new ChessPieces();

            // GetPiece 12 times
            var get1  = (Piece)piece.GetPiece();
            var get2  = (Piece)piece.GetPiece();
            var get3  = (Piece)piece.GetPiece();
            var get4  = (Piece)piece.GetPiece();
            var get5  = (Piece)piece.GetPiece();
            var get6  = (Piece)piece.GetPiece();
            var get7  = (Piece)piece.GetPiece();
            var get8  = (Piece)piece.GetPiece();
            var get9  = (Piece)piece.GetPiece();
            var get10 = (Piece)piece.GetPiece();
            var get11 = (Piece)piece.GetPiece();
            var get12 = (Piece)piece.GetPiece();

            // Output all 12 of the pieces using ToString method
            Console.WriteLine(get1.ToString());
            Console.WriteLine(get2.ToString());
            Console.WriteLine(get3.ToString());
            Console.WriteLine(get4.ToString());
            Console.WriteLine(get5.ToString());
            Console.WriteLine(get6.ToString());
            Console.WriteLine(get7.ToString());
            Console.WriteLine(get8.ToString());
            Console.WriteLine(get9.ToString());
            Console.WriteLine(get10.ToString());
            Console.WriteLine(get11.ToString());
            Console.WriteLine(get12.ToString());
        }