Beispiel #1
0
        private void SquareButton_MouseClick(object sender, MouseEventArgs e)
        {
            SquareButton squareButton = sender as SquareButton;

            if (m_SourceOfMove == null || squareButton.RegularSquare.SquareAlreadyChosen)
            {
                if (m_CountTurns % 2 == 0)
                {
                    m_CurrentPlayer = m_Player1;
                }
                else
                {
                    m_CurrentPlayer = m_Player2;
                }

                m_SourceOfMove = squareButton.SquareLocationInBoard;
                m_CurrentPlayer.PlayerChoseValidPiece(m_SourceOfMove);
                if (!squareButton.RegularSquare.SquareAlreadyChosen)
                {
                    m_SourceOfMove = null;
                }
            }
            else
            {
                bool succeed = getDestinatonAndMakeMove(sender as SquareButton, m_CurrentPlayer);
                if (succeed)
                {
                    if (m_SettingsForm.ComputerPlay && !m_CurrentPlayer.AnotherMoveToEat && !checkIfPlayersHaveNoMovesOrNoPieces())
                    {
                        makeComputerMove();
                    }
                    else if (!m_SettingsForm.ComputerPlay)
                    {
                        if (!m_CurrentPlayer.AnotherMoveToEat)
                        {
                            m_CountTurns++;
                        }
                    }

                    m_SourceOfMove  = null;
                    m_CurrentPlayer = null;
                }
                else
                {
                    DialogResult result;
                    result = MessageBox.Show(
                        @"This isn't a legal move
please make a legal move",
                        "ERROR",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
                }
            }
        }
Beispiel #2
0
        private void initialzieButtonsOnBoard()
        {
            m_BoardButtons = new SquareButton[m_BoardOfGame.SizeOfBoard, m_BoardOfGame.SizeOfBoard];
            System.Drawing.Point locationOfSquareButton = new System.Drawing.Point(50, 50);
            for (int indexOfRows = 0; indexOfRows < m_BoardOfGame.SizeOfBoard; indexOfRows++)
            {
                for (int indexOfCols = 0; indexOfCols < m_BoardOfGame.SizeOfBoard; indexOfCols++)
                {
                    m_BoardButtons[indexOfRows, indexOfCols] = new SquareButton(m_BoardOfGame.GetSquare(indexOfRows, indexOfCols), locationOfSquareButton);
                    this.Controls.Add(m_BoardButtons[indexOfRows, indexOfCols]);
                    m_BoardButtons[indexOfRows, indexOfCols].MouseClick += SquareButton_MouseClick;
                    m_BoardOfGame.GetSquare(indexOfRows, indexOfCols).OnSquareIsTakenByPiece();
                    locationOfSquareButton.X += 50;
                }

                locationOfSquareButton.X  = 50;
                locationOfSquareButton.Y += 50;
            }
        }
Beispiel #3
0
        private bool getDestinatonAndMakeMove(SquareButton i_Destination, Player i_CurrentPlayerTurn)
        {
            Point Destination = i_Destination.SquareLocationInBoard;
            Move  currentMove = new Move(m_SourceOfMove, Destination);
            bool  isMoveValid = i_CurrentPlayerTurn.CheckIfMoveIsLegal(currentMove);

            i_CurrentPlayerTurn.PlayerCurrentMove = currentMove;
            if (isMoveValid)
            {
                i_CurrentPlayerTurn.MakeMove();
            }

            if (checkIfPlayersHaveNoMovesOrNoPieces())
            {
                showMessageAfterRound();
            }

            return(isMoveValid);
        }