/* * pieceSelection is a method that select the given piece (if it recive a valid piece). */ private void pieceSelection(object i_PieceSender) { PictureBoxCheckersPiece selectedPiece = i_PieceSender as PictureBoxCheckersPiece; if (IsAnyPieceSelected()) { m_CurrentSelectedPiece.BackColor = Color.White; // Return the color of previous selected piece to white. if (m_CurrentSelectedPiece != selectedPiece) { m_CurrentSelectedPiece = selectedPiece; // Now m_CurrentSelectedPiece is selectedPiece. m_CurrentSelectedPiece.BackColor = Color.DodgerBlue; } else { m_CurrentSelectedPiece = null; // If we select this piece before it means that now we cancel the select. } } else { if (selectedPiece != null) { m_CurrentSelectedPiece = selectedPiece; m_CurrentSelectedPiece.BackColor = Color.DodgerBlue; } } }
/* * initializePictureBoxCheckersPiece is a method that receive pictureBoxCheckersPiece component and initialize it. */ private void initializePictureBoxCheckersPiece(PictureBoxCheckersPiece i_PictureBoxCheckersPiece) { i_PictureBoxCheckersPiece.Size = new System.Drawing.Size(50, 50); i_PictureBoxCheckersPiece.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; i_PictureBoxCheckersPiece.BackColor = System.Drawing.Color.White; this.Controls.Add(i_PictureBoxCheckersPiece); i_PictureBoxCheckersPiece.Click += new EventHandler(this.piece_Clicked); }
/* * initializePiecesComponent is a method that initialize the pieces components. */ private void initializePiecesComponent() { for (int i = 0; i < r_NumberOfPiecesInOneSide; i++) { // Initialize white pieces pictureBoxCheckersPieceWhitePieces[i] = new PictureBoxCheckersPiece(eTeam.White); pictureBoxCheckersPieceWhitePieces[i].ImageLocation = @"..\..\..\Images\WhitePieace.gif"; initializePictureBoxCheckersPiece(pictureBoxCheckersPieceWhitePieces[i]); // Initialize black pieces pictureBoxCheckersPieceBlackPieces[i] = new PictureBoxCheckersPiece(eTeam.Black); pictureBoxCheckersPieceBlackPieces[i].ImageLocation = @"..\..\..\Images\BlackPieace.gif"; initializePictureBoxCheckersPiece(pictureBoxCheckersPieceBlackPieces[i]); } }
/// ----------------------------------Other Functions--------------------------------- /// /* * getPieceByCoordinates is a method that return the piece that is at the given coordinate. */ private PictureBoxCheckersPiece getPieceByCoordinates(int i_SquareBelowPieceRow, int i_SquareBelowPieceColmen, PictureBoxCheckersPiece[] i_Pieces) { ButtonSquare belowButtonSquare = buttonSquares[i_SquareBelowPieceRow, i_SquareBelowPieceColmen]; PictureBoxCheckersPiece pieceToSelect = null; foreach (PictureBoxCheckersPiece piece in i_Pieces) { if (piece != null) { if (piece.BelowSquare == belowButtonSquare) { pieceToSelect = piece; break; } } } return(pieceToSelect); }
/* * FormCheckersGame constructor for initilize the checker game form */ public FormCheckersGame(byte i_CheckersBoardSize) { r_BoardSize = i_CheckersBoardSize; r_NumberOfPiecesInOneSide = (byte)((r_BoardSize / 2) * ((r_BoardSize / 2) - 1)); buttonSquares = new ButtonSquare[r_BoardSize, r_BoardSize]; pictureBoxCheckersPieceWhitePieces = new PictureBoxCheckersPiece[r_NumberOfPiecesInOneSide]; pictureBoxCheckersPieceBlackPieces = new PictureBoxCheckersPiece[r_NumberOfPiecesInOneSide]; InitializeComponent(); initializePiecesComponent(); initializeButtonsComponent(); initializeLocationOfPieces(); resizeClient(); addControlsButtonSquareToForm(); ucPlayer1Information.IsMyTurn = true; EmphasizeCurrentPlayer(); addGroupPictureToUIPlayersInformation(); }