Example #1
0
 /// <summary>
 /// Creates a board of empty board squares and pieces to there rightful location and color.
 /// </summary>
 public void SetBoard()
 {
     //Sets Black & White Pieces
     Board[0, 4] = new King('d');//Kings
     Board[7, 4] = new King('l');//Kings
     Board[0, 3] = new Queen('d');//Queens
     Board[7, 3] = new Queen('l');//Queens
     for (int x = 2; x < 6; x+=3)
     {
         Board[0, x] = new Bishop('d');//Black Bishops
         Board[7, x] = new Bishop('l');//White Bishops
     }
     for (int x = 1; x < 7; x+=5)
     {
         Board[0, x] = new Knight('d');//Black Knight
         Board[7, x] = new Knight('l');//White Knight
     }
     for (int x = 0; x < 9; x+=7)
     {
         Board[0, x] = new Rook('d');//Black Rooks
         Board[7, x] = new Rook('l');//White Rooks
     }
     for (int x = 0; x < 8; x++)
     {
         Board[1, x] = new Pawn('d');//Black Pawns
         Board[6, x] = new Pawn('l');//White Pawns
     }
     //Empty squares
     for (int x = 0; x < 8; ++x)
     {
         for (int y = 0; y < 8; y++)
         {
             if (Board[x, y] == null)
             {
                 Board[x, y] = new Space();
             }
         }
     }
 }
Example #2
0
 /// <summary>
 /// Asks the user what piece they would like the pawn to be.
 /// It will then set a type chess piece to the desired piece.
 /// </summary>
 /// <param name="pawnColor">Color of the pawn being promoted.</param>
 /// <returns>returns a piece for the pawn.</returns>
 public ChessPiece Promotion(ChessColor pawnColor)
 {
     int promotion = 0;
     bool isValid = false;
     ChessPiece newPiece;
     while (isValid = false || (1 > promotion && promotion < 4))
     {
         Console.WriteLine(" 1) Queen\n 2) Bishop\n 3) Rook\n 4) knight");
         string choice = Console.ReadLine();
         isValid = int.TryParse(choice, out promotion);
     }
     if (promotion == 1)
     {
         newPiece = new Queen(pawnColor);
     }
     else if (promotion == 2)
     {
         newPiece = new Bishop(pawnColor);
     }
     else if(promotion == 3)
     {
         newPiece = new Rook(pawnColor);
     }
     else
     {
         newPiece = new Knight(pawnColor);
     }
     return newPiece;
 }