示例#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 playCurrentPlayerTurn(Move i_CurrentMove, Player i_PlayerTurn, Player i_NotPlayerTurn)
        {
            bool isLegal = isLegalMove(i_CurrentMove, i_PlayerTurn);

            if (!isLegal)
            {
                InvalidMove.Invoke(this, EventArgs.Empty);
            }
            else
            {
                MakeMove.Invoke(i_CurrentMove, EventArgs.Empty);
                i_CurrentMove.MoveOnTable(r_GameTable);

                if (i_PlayerTurn.IsJumpTurn)
                {
                    if (hasAnotherJump(i_CurrentMove, i_PlayerTurn))
                    {
                        m_LegalJumps = getListOfJumpsForPiece(i_PlayerTurn.GetShapeType(), i_CurrentMove.TargetPiece);
                    }
                    else
                    {
                        v_TurnPlayer1           = !v_TurnPlayer1;
                        i_PlayerTurn.IsJumpTurn = false;
                    }
                }
                else
                {
                    v_TurnPlayer1 = !v_TurnPlayer1;
                }
            }
        }
示例#3
0
        private void OnPawnMakeMove(object sender, EventArgs e)
        {
            var pawnControl        = gameBoardTableLayoutPanel.Controls.OfType <CellControl>().Single(x => x.CapturedMouse);
            var placeholderControl = (CellControl)sender;
            var position           = gameBoardTableLayoutPanel.GetPositionFromControl(placeholderControl);

            var move = pawnControl.Pawn.AvailableMoves.Single(x => x.DestinatedPosition.Row == position.Row && x.DestinatedPosition.Column == position.Column);

            if (MakeMove != null)
            {
                MakeMove.Invoke(this, move);
            }
        }
示例#4
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;
        }
示例#5
0
        internal void PlayComputerTurn()
        {
            List <Move> computerJumpsMoves     = r_GameTable.GetPlayerJumpsList(eShapeType.O);
            int         lengthOfJumpsList      = computerJumpsMoves.Count;
            Move        currentMoveForComputer = null;

            if (lengthOfJumpsList > 0)
            {
                while (lengthOfJumpsList > 0)
                {
                    int indexOfJumplMove = r_Random.Next(0, lengthOfJumpsList);
                    currentMoveForComputer          = computerJumpsMoves[indexOfJumplMove];
                    currentMoveForComputer.MoveType = eMoveType.Jump;
                    MakeMove.Invoke(currentMoveForComputer, EventArgs.Empty);
                    currentMoveForComputer.MoveOnTable(r_GameTable);
                    r_Player2.IsJumpTurn = true;

                    if (hasAnotherJump(currentMoveForComputer, r_Player2))
                    {
                        computerJumpsMoves = getListOfJumpsForPiece(r_Player2.GetShapeType(), currentMoveForComputer.TargetPiece);
                        lengthOfJumpsList  = computerJumpsMoves.Count;
                    }
                    else
                    {
                        break;
                    }
                }
            }
            else
            {
                List <Move> computerDiagonalMoves = r_GameTable.GetListOfPlayerDiagonalMoves(eShapeType.O);
                int         lengthOfListDiagonal  = computerDiagonalMoves.Count;
                int         indexOfDiagonalMove   = r_Random.Next(0, lengthOfListDiagonal);
                currentMoveForComputer          = computerDiagonalMoves[indexOfDiagonalMove];
                currentMoveForComputer.MoveType = eMoveType.Diagonal;
                MakeMove.Invoke(currentMoveForComputer, EventArgs.Empty);
                currentMoveForComputer.MoveOnTable(r_GameTable);
            }
            v_TurnPlayer1 = !v_TurnPlayer1;
        }
示例#6
0
        private void OnPanelMouseClick(object sender, MouseEventArgs e)
        {
            if (IsPlaceholder)
            {
                if (MakeMove != null)
                {
                    MakeMove.Invoke(this, EventArgs.Empty);
                }

                return;
            }

            if (Pawn == null || !Pawn.AvailableMoves.Any())
            {
                return;
            }

            if (CapturedMouse)
            {
                CapturedMouse = false;

                if (ReleaseMouse != null)
                {
                    ReleaseMouse.Invoke(this, EventArgs.Empty);
                }
            }
            else
            {
                CapturedMouse = true;

                if (CaptureMouse != null)
                {
                    CaptureMouse.Invoke(this, EventArgs.Empty);
                }
            }
        }