コード例 #1
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;
                }
            }
        }
コード例 #2
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;
                }
            }
        }
コード例 #3
0
ファイル: GameManager.cs プロジェクト: tooliej/Checkers
        public void PlayTurn(PlayerMove i_Move)
        {
            if (m_GameState.Equals(eGameState.Play))
            {
                if (!NextPlayerToMove.MovePiece(i_Move))
                {
                    if (InvalidMove != null)
                    {
                        InvalidMove.Invoke(this, EventArgs.Empty);
                    }
                }
                else
                {
                    if (NextPlayerToMove.CanEat)
                    {
                        removeEatenPiece(i_Move);
                        if (!hasEaten(i_Move))
                        {
                            continueToNextMove();
                        }
                        else
                        {
                            if (EndOfMove != null)
                            {
                                EndOfMove.Invoke(this, EventArgs.Empty);
                            }
                        }
                    }
                    else
                    {
                        continueToNextMove();
                    }

                    m_GameState = GameState();

                    if (m_GameState.Equals(eGameState.Play))
                    {
                        if (r_Opponent.Equals(eOpponent.Computer) && NextPlayerToMove.PieceType == 'O')
                        {
                            // If it is the computers turn, randomly chooses a move from the valid moves
                            PlayTurn(getComputersMove());
                        }
                    }
                }
            }

            if (m_GameState.Equals(eGameState.Tie))
            {
                exitGame();
            }

            if (m_GameState.Equals(eGameState.Lose))
            {
                Player winner = getOppositionPlayer();
                Player loser  = NextPlayerToMove;
                winner.TotalScore += winner.GameScore - loser.GameScore;
                exitGame();
            }
        }
コード例 #4
0
ファイル: Game.cs プロジェクト: gregstanley/ChessSharp
        public MoveViewer TryMove(int fromSquareIndex, int toSquareIndex, PieceType promotionType = PieceType.None)
        {
            MoveViewer move = null;

            // Second entry into function where the promotion type has now been defined
            if (promotionType != PieceType.None)
            {
                move = TryFindMove(fromSquareIndex, toSquareIndex, promotionType);

                if (move.Value == 0)
                {
                    InvalidMove?.Invoke(this, new InvalidMoveEventArgs(fromSquareIndex, toSquareIndex));

                    return(new MoveViewer(0));
                }

                ApplyMove(board, HumanColour, move);

                return(move);
            }

            var isPawnPromotion = IsMovePromotion(fromSquareIndex, toSquareIndex);

            if (isPawnPromotion)
            {
                // If it is then we have to stop and get the desired promotion type before continuing
                PromotionTypeRequired?.Invoke(this, new PromotionTypeRequiredEventArgs(fromSquareIndex, toSquareIndex));

                return(new MoveViewer(0));
            }

            move = TryFindMove(fromSquareIndex, toSquareIndex);

            if (move.Value == 0)
            {
                InvalidMove?.Invoke(this, new InvalidMoveEventArgs(fromSquareIndex, toSquareIndex));

                return(new MoveViewer(0));
            }

            ApplyMove(board, HumanColour, move);

            return(move);
        }