/// <summary> /// ChessPiece Constructor /// </summary> /// <param name="aPieceColor"></param> /// <param name="aPieceType"></param> /// <param name="aChessSquare"></param> internal ChessPiece(EnumPieceColor aPieceColor, EnumPieceType aPieceType, ChessSquare aChessSquare) { chessPieceColor = aPieceColor; chessPieceType = aPieceType; chessPieceID = (EnumPieceID)((int)chessPieceColor + (int)chessPieceType); chessSquare = aChessSquare; EnumSquareID sid = chessSquare.GetSquareID(); ChessImageConstants.parserChessBoardSquares[sid] = chessPieceID; isEnabled = true; }
/// <summary> /// ChessPiece Constructor /// </summary> /// <param name="aPieceColor"></param> /// <param name="aPieceType"></param> /// <param name="aChessSquare"></param> internal ChessPiece(EnumPieceColor aPieceColor, EnumPieceType aPieceType, ChessSquare aChessSquare) { chessPieceColor = aPieceColor; chessPieceType = aPieceType; chessPieceID = (EnumPieceID)((int)chessPieceColor + (int)chessPieceType); chessSquare = aChessSquare; EnumSquareID sid = chessSquare.GetSquareID(); ChessImageConstants.parserChessBoardSquares[sid] = chessPieceID; isCastlingPossible = ((aPieceType == EnumPieceType.King) || ((aPieceType == EnumPieceType.Rook))); isEnabled = true; // TODO was false }
/// <summary> /// ChessPiece Constructor /// </summary> /// <param name="aChessPieceID"></param> internal ChessPiece(EnumPieceID aChessPieceID, ChessSquare aChessSquare) { chessSquare = aChessSquare; if (aChessPieceID == EnumPieceID.BlackKing) { chessPieceType = EnumPieceType.King; chessPieceColor = EnumPieceColor.Black; } else if (aChessPieceID == EnumPieceID.WhiteKing) { chessPieceType = EnumPieceType.King; chessPieceColor = EnumPieceColor.White; } chessPieceID = aChessPieceID; isEnabled = false; }
/// <summary> /// ChessPiece Constructor /// </summary> /// <param name="aChessPieceID"></param> internal ChessPiece(EnumPieceID aChessPieceID, ChessSquare aChessSquare) { chessSquare = aChessSquare; if (aChessPieceID == EnumPieceID.BlackKing) { chessPieceType = EnumPieceType.King; chessPieceColor = EnumPieceColor.Black; } else if (aChessPieceID == EnumPieceID.WhiteKing) { chessPieceType = EnumPieceType.King; chessPieceColor = EnumPieceColor.White; } chessPieceID = aChessPieceID; isCastlingPossible = ((chessPieceType == EnumPieceType.King) || ((chessPieceType == EnumPieceType.Rook))); isEnabled = false; }
/// <summary> /// CreateChessPiece by square and piece ID /// </summary> /// <param name="aChessSquare"></param> /// <param name="aChessPieceType"></param> /// <param name="aChessPieceColor"></param> /// <returns>ChessPiece</returns> private ChessPiece CreateChessPiece(ChessSquare aChessSquare, EnumPieceID aPieceID) { int whitePieceOffset = (int)EnumPieceColor.White; int blackPieceOffset = (int)EnumPieceColor.Black; EnumPieceColor chessPieceColor = EnumPieceColor.None; EnumPieceType chessPieceType = EnumPieceType.None; int pieceNumber = (int)aPieceID; if (pieceNumber >= whitePieceOffset + 1 && pieceNumber <= whitePieceOffset + 6) { pieceNumber -= (int)EnumPieceColor.White; chessPieceColor = EnumPieceColor.White; } else if (pieceNumber >= blackPieceOffset + 1 && pieceNumber <= blackPieceOffset + 6) { pieceNumber -= (int)EnumPieceColor.Black; chessPieceColor = EnumPieceColor.Black; } else { chessPieceColor = EnumPieceColor.None; chessPieceType = EnumPieceType.None; } // King, Queen, Rook, Bishop, Knight, Pawn switch (pieceNumber) { case 1: chessPieceType = EnumPieceType.King; break; case 2: chessPieceType = EnumPieceType.Queen; break; case 3: chessPieceType = EnumPieceType.Rook; break; case 4: chessPieceType = EnumPieceType.Bishop; break; case 5: chessPieceType = EnumPieceType.Knight; break; case 6: chessPieceType = EnumPieceType.Pawn; break; default: chessPieceType = EnumPieceType.None; break; } ChessPiece chessPiece = new ChessPiece(chessPieceColor, chessPieceType, aChessSquare); EnumSquareID squareID = aChessSquare.GetSquareID(); Point aLocation = new Point(aChessSquare.GetStartLocation().X + ChessImageConstants.ChessPieceLeft, aChessSquare.GetStartLocation().Y + ChessImageConstants.ChessPieceTop); chessPiece.SetStartLocation(aLocation); chessPiece.SetChessSquare(aChessSquare); aChessSquare.SetChessPiece(chessPiece); if (chessPieceColor == EnumPieceColor.White) { whitePieceList.Add(chessPiece); } else if (chessPieceColor == EnumPieceColor.Black) { blackPieceList.Add(chessPiece); } return chessPiece; }