Ejemplo n.º 1
0
        // Event Handlers
        // Handle feedback received from last move executed (notify user of error or continue to next turn)
        public void AnalyzeMoveFeedback(eMoveFeedback i_MoveFeedback)
        {
            switch (i_MoveFeedback)
            {
            case eMoveFeedback.Failed:
            {
                MessageBox.Show("Invalid move.");
                break;
            }

            case eMoveFeedback.FailedCouldCapture:
            {
                MessageBox.Show("Capture available, you must perform it.");
                break;
            }

            // case the move was successfully executed
            default:
            {
                m_BoardForm.HighlightCurrentPlayerLabel();
                if (m_Game.IsOver())
                {
                    endRound();
                }

                // if the AI is about to play- use a timer to pause so we can see his move
                if (m_Game.CurrentPlayer.IsAi)
                {
                    m_AiThinkingTimer.Start();
                }

                break;
            }
            }
        }
Ejemplo n.º 2
0
        // Execute the given move, returns true if it was executed successfully
        public void ExecuteMove(Move i_Move)
        {
            eMoveFeedback moveFeedback = eMoveFeedback.Failed;
            Piece         piece        = m_Board.GameBoard[i_Move.FromRow, i_Move.FromCol].CurrentPiece;

            if (piece != null)
            {
                // User chose simple move
                if (MoveValidator.IsSimpleMove(CurrentPlayer, m_Board, i_Move))
                {
                    // If the player can capture- the move fails (he must choose to capture)
                    if (MoveValidator.IsPlayerHasCapture(CurrentPlayer, m_Board))
                    {
                        moveFeedback = eMoveFeedback.FailedCouldCapture;
                    }
                    else
                    {
                        // If the moving piece is NOT a king
                        if (piece.IsKing == false)
                        {
                            // If tries to move in the opposite direction- the move fails
                            if (MoveValidator.IsMovingInValidDirection(CurrentPlayer, i_Move, piece) == false)
                            {
                                moveFeedback = eMoveFeedback.Failed;
                            }
                            else
                            {
                                m_Board.MovePiece(CurrentPlayer, piece, new Point(i_Move.ToRow, i_Move.ToCol));
                                moveFeedback = eMoveFeedback.Success;
                            }
                        }
                        // moving piece is a king
                        else
                        {
                            m_Board.MovePiece(CurrentPlayer, piece, new Point(i_Move.ToRow, i_Move.ToCol));
                            moveFeedback = eMoveFeedback.Success;
                        }
                    }
                }
                // User chose capture move
                else if (MoveValidator.IsCaptureMovePossible(CurrentPlayer, m_Board, i_Move))
                {
                    Player enemyPlayer = CurrentPlayer == PlayerOne ? PlayerTwo : PlayerOne;
                    m_Board.MoveCapturingPiece(CurrentPlayer, enemyPlayer, piece, new Point(i_Move.ToRow, i_Move.ToCol));
                    moveFeedback = eMoveFeedback.Success;

                    // check double capture option
                    if (MoveValidator.CanPieceCapture(m_Board, m_Board.GameBoard[i_Move.ToRow, i_Move.ToCol].CurrentPiece))
                    {
                        moveFeedback = eMoveFeedback.CanDoubleCapture;
                    }
                }
            }

            if (moveFeedback == eMoveFeedback.Success)
            {
                m_TurnCount++;
            }

            // Notify listeners of move execution completed
            MoveExecuted?.Invoke(moveFeedback);
        }