/// <summary>
 /// ChessSquare Constructor
 /// </summary>
 public ChessSquare()
 {
     chessLocation = new Point(0, 0);
     startLocation = new Point(0, 0);
     chessPiece = null;
     isLastMove = false;
     squareID = EnumSquareID.A1;
 }
Ejemplo n.º 2
0
 //////////////////// 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);
 }
Ejemplo n.º 3
0
        /// <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;
        }
Ejemplo n.º 4
0
        /// <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;
        }
Ejemplo n.º 5
0
        /// <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;
        }
Ejemplo n.º 6
0
 /// <summary>
 /// DrawPiece method
 /// </summary>
 /// <param name="g"></param>
 /// <param name="aChessPiece"></param>
 public void DrawPiece(Graphics g, ChessPiece aChessPiece)
 {
     if (aChessPiece != null)
         aChessPiece.Draw(g, chessPieceFactory);
 }
 /// <summary>
 /// SetChessPiece Accessor
 /// </summary>
 /// <param name="aChessPiece"></param>
 public void SetChessPiece(ChessPiece aChessPiece)
 {
     chessPiece = aChessPiece;
 }