コード例 #1
0
        private void playCurrentPlayerTurn(Move i_CurrentMove, Player i_PlayerTurn, Player i_NotPlayerTurn)
        {
            bool isValid = isValidMove(i_CurrentMove, i_PlayerTurn);

            if (!isValid)
            {
                InvalidMove.Invoke(this, EventArgs.Empty);
            }
            else
            {
                MakeMove.Invoke(i_CurrentMove, EventArgs.Empty);
                i_CurrentMove.MoveOnBoard(m_BoardGame);

                if (i_PlayerTurn.IsJumpTurn)
                {
                    if (hasAnotherJump(i_CurrentMove, i_PlayerTurn))
                    {
                        m_LegalJumps = getListOfJumpsForPiece(i_PlayerTurn.GetShapeType(), i_CurrentMove.ToSquare);
                    }
                    else
                    {
                        v_Turn = !v_Turn;
                        i_PlayerTurn.IsJumpTurn = false;
                    }
                }
                else
                {
                    v_Turn = !v_Turn;
                }
            }
        }
コード例 #2
0
        /*
         * private void playFirstMoveOfGame()
         * {
         *  string currentMoveString = GameUI.GetFirstMoveFromUser(m_Player1, m_BoardGame);
         *
         *  if (GameUI.IsQuitInput(currentMoveString))
         *  {
         *      m_GameStatus = eGameStatus.Draw;
         *      GameUI.PrintGamePointStatus(this);
         *  }
         *
         *  else
         *  {
         *      Move currentMove = getMoveFromString(currentMoveString);
         *
         *      while (!currentMove.CheckIsValidMove(m_Player1.GetShapeType()))
         *      {
         *          GameUI.PrintErrorOfMove(Move.eTypeOfMove.Regular);
         *          currentMoveString = GameUI.GetFirstMoveFromUser(m_Player1, m_BoardGame);
         *          currentMove = getMoveFromString(currentMoveString);
         *      }
         *
         *      currentMove.MoveOnBoard(m_BoardGame);
         *      this.v_Turn = false;
         *  }
         *
         *
         * }
         *
         *
         *
         */

        public void playComputerTurn()
        {
            List <Move> computerJumpsMoves     = m_BoardGame.GetListOfPlayerJumps(Player.eShapeType.O);
            int         lengthOfJumpsList      = computerJumpsMoves.Count;
            Move        currentMoveForComputer = null;

            if (lengthOfJumpsList > 0)
            {
                while (lengthOfJumpsList > 0)
                {
                    int indexOfJumplMove = s_Random.Next(0, lengthOfJumpsList);
                    currentMoveForComputer          = computerJumpsMoves[indexOfJumplMove];
                    currentMoveForComputer.MoveType = Move.eTypeOfMove.Jump;


                    MakeMove.Invoke(currentMoveForComputer, EventArgs.Empty);
                    currentMoveForComputer.MoveOnBoard(m_BoardGame);

                    m_Player2.IsJumpTurn = true;

                    if (hasAnotherJump(currentMoveForComputer, m_Player2))
                    {
                        computerJumpsMoves = getListOfJumpsForPiece(m_Player2.GetShapeType(), currentMoveForComputer.ToSquare);
                        lengthOfJumpsList  = computerJumpsMoves.Count;
                    }
                    else
                    {
                        break;
                    }
                }
            }
            else
            {
                List <Move> computerDiagonalMoves = m_BoardGame.GetListOfPlayerDiagonalMoves(Player.eShapeType.O);
                int         lengthOfListDiagonal  = computerDiagonalMoves.Count;
                int         indexOfDiagonalMove   = s_Random.Next(0, lengthOfListDiagonal);
                currentMoveForComputer          = computerDiagonalMoves[indexOfDiagonalMove];
                currentMoveForComputer.MoveType = Move.eTypeOfMove.Regular;
                currentMoveForComputer.MoveOnBoard(m_BoardGame);
                MakeMove.Invoke(currentMoveForComputer, EventArgs.Empty);
            }
            v_Turn = !v_Turn;
        }