/// <summary> /// CalculateLocations /// </summary> /// <param name="aSquare"></param> /// <param name="isSupportPosition"></param> /// <returns>ArrayList</returns> internal virtual ArrayList CalculateLocations(ChessSquare aSquare, bool isSupportPosition) { ClearValidSquaresList(); originalSquare = aSquare; // Preserve original square return null; }
/// <summary> /// CalculateLocations /// </summary> /// <param name="aSquare"></param> /// <param name="isSupportLocation"></param> /// <returns>ArrayList</returns> internal override ArrayList CalculateLocations(ChessSquare aSquare, bool isSupportLocation) { base.CalculateLocations(aSquare, isSupportLocation); if (isSupportLocation) return this.CalculateCaptureLocations(aSquare, isSupportLocation); else { if (chessPlayer.GetPlayerType() == EnumPlayerType.WhitePlayer) { if (originalSquare.GetChessLocation().Y == 1) GoDown( aSquare.GetChessLocation(), 2); else GoDown( aSquare.GetChessLocation(), 1 ); GoLeftDown(aSquare.GetChessLocation(), false); GoRightDown(aSquare.GetChessLocation(), false); } else if (chessPlayer.GetPlayerType() == EnumPlayerType.BlackPlayer) { if (originalSquare.GetChessLocation().Y == 6) GoUp( aSquare.GetChessLocation(), 2 ); else GoUp( aSquare.GetChessLocation(), 1 ); GoLeftUp(aSquare.GetChessLocation(), false); GoRightUp(aSquare.GetChessLocation(), false); } return validSquaresList; } }
/// <summary> /// CalculateLocations /// </summary> /// <param name="aSquare"></param> /// <param name="isSupportPosition"></param> /// <returns>ArrayList</returns> internal override ArrayList CalculateLocations(ChessSquare aSquare, bool isSupportPosition) { base.CalculateLocations(aSquare, isSupportPosition); GoUp ( new Point(aSquare.GetChessLocation().X, aSquare.GetChessLocation().Y), isSupportPosition ); GoDown ( new Point(aSquare.GetChessLocation().X, aSquare.GetChessLocation().Y), isSupportPosition ); GoRight( new Point(aSquare.GetChessLocation().X, aSquare.GetChessLocation().Y), isSupportPosition ); GoLeft ( new Point(aSquare.GetChessLocation().X, aSquare.GetChessLocation().Y), isSupportPosition ); return validSquaresList; }
/// <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; isCastlingPossible = ((chessPieceType == EnumPieceType.King) || ((chessPieceType == EnumPieceType.Rook))); isEnabled = false; }
//////////////////// MOVE //////////////////////////// /// <summary> /// RealMove method /// </summary> /// <param name="aMovingPiece"></param> /// <param name="aNewSquare"></param> /// <param name="aOriginalSquare"></param> private void RealMove(ChessPiece aMovingPiece, ChessSquare aNewSquare, ChessSquare aOriginalSquare) { aOriginalSquare.SetChessPiece(null); aMovingPiece.SetChessSquare(aNewSquare); aNewSquare.SetChessPiece(aMovingPiece); }
/// <summary> /// GetChessPieceAtSquare method /// </summary> /// <param name="square"></param> /// <returns>ChessPiece</returns> private ChessPiece GetChessPieceAtSquare(ChessSquare square) { if (square != null) { ChessPiece chessPiece = (ChessPiece)square.GetChessPiece(); if (chessPiece != null) return chessPiece; else return null; } else return null; }
////////////////////// DRAWING //////////////////// /// <summary> /// DrawSquare method /// </summary> /// <param name="g"></param> /// <param name="aChessSquare"></param> /// <param name="aIsHighlight"></param> /// <param name="aIsLastMove"></param> private void DrawSquare(Graphics g, ChessSquare aChessSquare, bool aIsHighlight, bool aIsLastMove) { if (aChessSquare != null) { aChessSquare.Draw(g, squareFactory, aIsHighlight, aIsLastMove); ChessPiece chessPiece = (ChessPiece)aChessSquare.GetChessPiece(); DrawPiece(g, chessPiece); } }
/// <summary> /// CreateChessPiece by square piece type and piece color /// </summary> /// <param name="aChessSquare"></param> /// <param name="aChessPieceType"></param> /// <param name="aChessPieceColor"></param> /// <returns>ChessPiece</returns> private ChessPiece CreateChessPiece(ChessSquare aChessSquare, EnumPieceType aChessPieceType, EnumPieceColor aChessPieceColor) { ChessPiece chessPiece = new ChessPiece(aChessPieceColor, aChessPieceType, 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 (aChessPieceColor == EnumPieceColor.White) { whitePieceList.Add(chessPiece); } else { blackPieceList.Add(chessPiece); } return chessPiece; }
/// <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) { EnumPieceColor chessPieceColor = EnumPieceColor.White; EnumPieceType chessPieceType = EnumPieceType.None; int pieceNumber = (int)aPieceID; if( pieceNumber >= 11 && pieceNumber <= 16) { pieceNumber -= 10; chessPieceColor = EnumPieceColor.White; } else if (pieceNumber >= 21 && pieceNumber <= 26) { pieceNumber -= 20; 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; }
/// <summary> /// MovePiece method /// </summary> /// <param name="aMovingPiece"></param> /// <param name="aSquare"></param> /// <param name="aoriginalSquare"></param> /// <returns>bool</returns> public bool MovePiece(ChessPiece aMovingPiece, ChessSquare aSquare, ChessSquare aoriginalSquare) { // if new square contains a piece, make that piece's square to null ChessPiece aCapturedPiece = aSquare.GetChessPiece(); // Move the Piece RealMove(aMovingPiece, aSquare, aoriginalSquare); // Set Piece's Start Position aMovingPiece.SetStartLocation(new Point(aSquare.GetStartLocation().X + ChessImageConstants.ChessPieceLeft, aSquare.GetStartLocation().Y + ChessImageConstants.ChessPieceTop)); return true; }
/// <summary> /// CreateBoardSquares method /// </summary> private void CreateBoardSquares() { EnumSquareColor squareColor = EnumSquareColor.Black; ChessSquare chessSquare; int line = -1; int column = 0; squareLocator.Reset(); for (int counter = 0; counter < ChessImageConstants.SquareCount; counter++) { chessSquare = new ChessSquare(); chessSquare.SetColor(GetSquareColor(squareColor)); chessSquare.SetStartLocation(squareLocator.GetLocation()); if (squareLocator.IsNewLine()) { line++; column = 0; } else { column++; } chessSquare.SetChessLocation(new Point(column, line)); EnumSquareID sid = chessSquare.GetSquareID(); squareList.Add(chessSquare); squareColor = chessSquare.GetColor(); squareLocator.Increment(); } }
/// <summary> /// CalculateCaptureLocations /// </summary> /// <param name="square"></param> /// <param name="isSupportLocation"></param> /// <returns>ArrayList</returns> private ArrayList CalculateCaptureLocations(ChessSquare square, Boolean isSupportLocation) { if (chessPlayer.GetPlayerType() == EnumPlayerType.WhitePlayer) { GoLeftDown(square.GetChessLocation(), isSupportLocation); GoRightDown(square.GetChessLocation(), isSupportLocation); } else if (chessPlayer.GetPlayerType() == EnumPlayerType.BlackPlayer) { GoLeftUp(square.GetChessLocation(), isSupportLocation); GoRightUp(square.GetChessLocation(), isSupportLocation); } return validSquaresList; }
/// <summary> /// SetChessSquare /// </summary> /// <param name="aChessSquare"></param> internal void SetChessSquare(ChessSquare aChessSquare) { chessSquare = aChessSquare; }