private void determineImageAccordingToPieceSign(CheckersButton i_SourcePBox, CheckersButton i_DestPBox)
        {
            Point     sourceDest        = m_Game.GetLastStep.GetDestination;
            string    sourceDestination = sourceDest.GetColCoord + sourceDest.GetRowCoord;
            BoardSlot sourceBoardSlot   = m_Game.GetGameBoard.GetBoardSlotFromIdentifierString(sourceDestination);

            if (m_Game.GetActivePlayer.GetPlayerSign == "X")
            {
                if (sourceBoardSlot.GetPieceRef().GetIsKingBoolean)
                {
                    i_DestPBox.Image = global::CheckersUI.Properties.Resources.WhiteKing;
                }
                else
                {
                    i_DestPBox.Image = global::CheckersUI.Properties.Resources.WhitePawn;
                }
            }
            else
            {
                if (sourceBoardSlot.GetPieceRef().GetIsKingBoolean)
                {
                    i_DestPBox.Image = global::CheckersUI.Properties.Resources.BlackKing;
                }
                else
                {
                    i_DestPBox.Image = global::CheckersUI.Properties.Resources.BlackPawn;
                }
            }

            i_SourcePBox.Image  = null;
            i_DestPBox.SizeMode = PictureBoxSizeMode.StretchImage;
            i_DestPBox.Update();
            i_SourcePBox.Update();
        }
示例#2
0
 public MoveEventArgs(CheckersButton i_Destination, CheckersButton i_Source)
 {
     m_Source         = i_Source.GetPositionIdentifier;
     m_Destination    = i_Destination.GetPositionIdentifier;
     m_SourceRowIndex = i_Source.GetRowCoord;
     m_SourceColIndex = i_Source.GetColCoord;
     m_DestRowIndex   = i_Destination.GetRowCoord;
     m_DestColIndex   = i_Destination.GetColCoord;
 }
        private void getPBoxByIdentifier(string i_Identifier, out CheckersButton i_PictureBox)
        {
            char xCoord, yCoord;

            xCoord       = i_Identifier[1];
            xCoord      -= 'a';
            yCoord       = i_Identifier[0];
            yCoord      -= 'A';
            i_PictureBox = m_FormBoard[xCoord, yCoord];
        }
        private void updateMoveInWindow(MoveEventArgs i_MoveArgsElement, bool i_DidJumpOverOccured)
        {
            CheckersButton sourcePBox = m_FormBoard[i_MoveArgsElement.GetSourceRowIndex, i_MoveArgsElement.GetSourceColIndex];
            CheckersButton destPBox   = m_FormBoard[i_MoveArgsElement.GetDestRowIndex, i_MoveArgsElement.GetDestColIndex];

            if (i_DidJumpOverOccured)
            {
                CheckersButton pictureBoxToRemovePiece;
                string         MoveExecuted = i_MoveArgsElement.GetSource + ">" + i_MoveArgsElement.GetDestination;
                Board          gameBoard    = m_Game.GetGameBoard;
                BoardSlot      slotToRemove = gameBoard.GetBoardSlotFromIdentifierString(gameBoard.GetJumpedOverPieceBoardSlotIdentifier(new Step(MoveExecuted)));
                getPBoxByIdentifier(slotToRemove.GetSlotIdentifier, out pictureBoxToRemovePiece);
                pictureBoxToRemovePiece.Image = null;
                pictureBoxToRemovePiece.Update();
            }

            determineImageAccordingToPieceSign(sourcePBox, destPBox);
        }
        private void OnClicked(object sender, EventArgs e)
        {
            MoveEventArgs moveWasSpotted;
            bool          isPieceClicked;

            if (m_LastButtonClicked == null)
            {
                m_LastButtonClicked = sender as CheckersButton;
                if (checkIfClickedPieceBelongsToOpponent(out isPieceClicked))
                {
                    MessageBox.Show("Selected piece belongs to opponent", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                    m_LastButtonClicked = null;
                }
                else if (!isPieceClicked)
                {
                    MessageBox.Show("Selected tile does not contain a piece", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                    m_LastButtonClicked = null;
                }
                else
                {
                    (sender as CheckersButton).BorderStyle = BorderStyle.FixedSingle;
                }
            }
            else
            {
                m_LastButtonClicked.BorderStyle = BorderStyle.Fixed3D;
                if (m_LastButtonClicked == sender)
                {
                    m_LastButtonClicked.BorderStyle = BorderStyle.Fixed3D;
                    m_LastButtonClicked             = null;
                }
                else
                {
                    moveWasSpotted      = new MoveEventArgs(sender as CheckersButton, m_LastButtonClicked);
                    m_LastButtonClicked = null;
                    OnMoveClicked(this, moveWasSpotted);
                }
            }
        }
        private void initializeGameWindow()
        {
            initializeGamePlayerAndStats();
            string currentSlotID = string.Empty;

            for (ushort rowIndex = 2; rowIndex < m_SelectedBoardSize + 2; rowIndex++)
            {
                for (ushort colIndex = 0; colIndex < m_SelectedBoardSize; colIndex++)
                {
                    currentSlotID = m_Game.GetGameBoard.GetBoardSlotIdentifier((ushort)(rowIndex - 2), (ushort)colIndex);
                    CheckersButton newPictureBox = new CheckersButton((ushort)(rowIndex - 2), (ushort)colIndex, currentSlotID)
                    {
                        Size     = new Size(k_TileSize, k_TileSize),
                        Location = new System.Drawing.Point(k_TileSize * colIndex, k_TileSize * rowIndex)
                    };
                    newPictureBox.Font   = new Font(newPictureBox.Font.FontFamily, 15);
                    newPictureBox.Click += new System.EventHandler(this.OnClicked);
                    Controls.Add(newPictureBox);
                    m_FormBoard[rowIndex - 2, colIndex] = newPictureBox;
                    newPictureBox.BorderStyle           = BorderStyle.Fixed3D;
                    if (rowIndex % 2 == 0)
                    {
                        newPictureBox.BackgroundImage = colIndex % 2 != 0 ? global::CheckersUI.Properties.Resources.BackColorBright : global::CheckersUI.Properties.Resources.BackColorDark;
                        newPictureBox.BackColor       = colIndex % 2 != 0 ? Color.White : Color.DarkGray;
                    }
                    else
                    {
                        newPictureBox.BackgroundImage = colIndex % 2 != 0 ? global::CheckersUI.Properties.Resources.BackColorDark : global::CheckersUI.Properties.Resources.BackColorBright;
                    }

                    if (newPictureBox.BackgroundImage == global::CheckersUI.Properties.Resources.BackColorDark)
                    {
                        newPictureBox.Enabled = false;
                    }
                }
            }
        }