Пример #1
0
        private void CheckerBtn_Click(object sender, EventArgs e)
        {
            CheckerButton checkerBtn   = sender as CheckerButton;
            bool          clickedState = checkerBtn.Clicked,
                          playerIsClickingOnASquareThatHasHisSoldier = checkerBtn.Square.Color == GameManager.ActivePlayer.Color,
                          playerIsclickingAnAvailableMoveSquare      = checkerBtn.IsAnAvailableMove;

            // First, make sure you are able to click that button
            if (!playerIsClickingOnASquareThatHasHisSoldier && !playerIsclickingAnAvailableMoveSquare)
            {
                return;
            }

            if (playerIsClickingOnASquareThatHasHisSoldier)
            {
                // Unclick all the other buttons.
                m_Board.UnclickallButtons();
                clickedState = !clickedState; // We have to toggle the state now.

                // This line also triggeres the Available Moves part. Please take a look at the CheckerCheckerButton Setter for more information
                CheckedCheckerButton = clickedState ? checkerBtn : null;
            }
            else
            {
                // Player has clicked on an available move square
                Move move = AvailableMoves.First(m => m.Destination == checkerBtn.LocationOnMatrix);
                CheckedCheckerButton = null;
                GameManager.HandleMove(move);
            }
        }
Пример #2
0
        private CheckerButton[] getCheckerButtonsByCoordinates(CheckersLogic.Point[] availableMovesDestinationPoints)
        {
            CheckerButton[] destinationButtons = new CheckerButton[availableMovesDestinationPoints.Length];
            byte            counter            = 0;

            foreach (CheckerButton currentCheckerButton in this.Controls)
            {
                foreach (CheckersLogic.Point destinationPoint in availableMovesDestinationPoints)
                {
                    if (currentCheckerButton.LocationOnMatrix == destinationPoint)
                    {
                        destinationButtons[counter] = currentCheckerButton;
                        counter++;
                    }
                }
            }

            return(destinationButtons);
        }
Пример #3
0
        /// <summary>
        /// Initialize all the checker buttons. This is done only once when we start playing
        /// </summary>
        /// <param name="i_CellWidthAndHeight">The Height and Width of every cell</param>
        /// <param name="i_CheckerBtn_Click">A pointer to a method that will be called once a checker button is clicked</param>
        private void setupButtonBoard(int i_CellWidthAndHeight, EventHandler i_CheckerBtn_Click)
        {
            byte boardSize = m_GameBoard.BoardSize;

            m_CheckerButtons = new CheckerButton[boardSize, boardSize];

            for (byte i = 0; i < boardSize; i++)
            {
                for (byte j = 0; j < boardSize; j++)
                {
                    bool          buttonIsEnabled = (i + j) % 2 != 0;
                    CheckerButton checkerBtn      = new CheckerButton(i_CellWidthAndHeight, buttonIsEnabled);
                    checkerBtn.Location         = new System.Drawing.Point(i_CellWidthAndHeight * i, i_CellWidthAndHeight * j);
                    checkerBtn.Square           = m_GameBoard.Matrix[j, i];
                    checkerBtn.LocationOnMatrix = new Ex05.CheckersLogic.Point(i, j);

                    checkerBtn.Click += i_CheckerBtn_Click;

                    m_CheckerButtons[i, j] = checkerBtn;
                    this.Controls.Add(checkerBtn);
                }
            }
        }
Пример #4
0
        private void Damka_GameEnded(Player i_WinningPlayer)
        {
            // Game is done so we can remove all markers on the board.
            CheckedCheckerButton = null;

            StringBuilder messageBoxContent = new StringBuilder();

            messageBoxContent.AppendLine(GameManager.State == GameState.Tie ? "Tie!" : string.Format("{0} Won and received {1} points!", i_WinningPlayer.Name, GameManager.CalculatePlayerWinningPoints(i_WinningPlayer)));

            messageBoxContent.AppendLine("Another round?");

            DialogResult dialogResult = MessageBox.Show(messageBoxContent.ToString(), "Game Ended", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk);

            if (dialogResult == DialogResult.Yes)
            {
                updatePlayerScoresLabels();
                GameManager.Reset();
            }
            else if (dialogResult == DialogResult.No)
            {
                Application.Exit();
            }
        }