コード例 #1
0
        public void ButtonClicked(Point i_Location, EventArgs i_Event)
        {
            // if m_Move.IsEmpty -> We are in the first click
            if (m_Move.IsEmpty())
            {
                m_Move.Source = i_Location;
            }
            else
            {
                m_Move.Destination = i_Location;
                if (m_Player1.Turn)
                {
                    if (isLegalMove(m_Player1, m_Move))
                    {
                        giveTurnTo(ref m_Player1, ref m_Player2, m_Move);

                        if (m_Player2.Name == "PC" && !m_Player1.CanEatMore(m_GameBoard, m_Move.Source))
                        {
                            m_Move = choosePcMove(m_Player2);
                            if (!m_Move.IsEmpty())
                            {
                                ButtonClicked(m_Move.Destination, i_Event);
                            }
                        }
                    }
                }
                else
                {
                    if (isLegalMove(m_Player2, m_Move))
                    {
                        giveTurnTo(ref m_Player2, ref m_Player1, m_Move);
                    }
                }

                Player currentPlayer = m_Player1.Turn ? m_Player1 : m_Player2;

                if (isGameOver(currentPlayer))
                {
                    m_MyChecker.UpdateBoard();
                    GameOver(determineGameResult());
                }

                m_Move.MakeEmpty();
                m_MyChecker.UpdateBoard();
            }
        }
コード例 #2
0
        private void giveTurnTo(ref Player io_Player, ref Player io_Opponent, Move i_Move)
        {
            m_GameBoard.MovePawn(i_Move, io_Player);

            if (io_Player.AteOpponent(i_Move))
            {
                int colIndexToRemove = m_GameBoard.CalculateColIndexOfCellToRemove(i_Move);
                int rowIndexToRemove = m_GameBoard.CalculateRowIndexOfCellToRemove(i_Move);

                if (m_GameBoard.m_Grid[rowIndexToRemove, colIndexToRemove].Sign == io_Opponent.PawnSign)
                {
                    io_Opponent.NumOfPawns--;
                }
                else
                {
                    io_Opponent.NumOfKings--;
                }

                m_GameBoard.m_Grid[rowIndexToRemove, colIndexToRemove].PawnInCell = false;

                if (!io_Player.CanEatMore(m_GameBoard, m_Move.Destination))
                {
                    io_Opponent.Turn = true;
                    io_Player.Turn   = false;
                }
                else
                {
                    m_Move.Source      = m_Move.Destination;
                    m_Move.Destination = destinationInEatingSerie(io_Player, m_Move.Source);

                    if (io_Player.Name == "PC")
                    {
                        ButtonClicked(m_Move.Destination, EventArgs.Empty);
                    }
                }
            }
            else
            {
                io_Opponent.Turn = true;
                io_Player.Turn   = false;
            }
        }