Пример #1
0
        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();
            }
        }
Пример #2
0
 public void RestartGame()
 {
     setUpNewGame();
     m_GameState = eGameState.Play;
     if (EndOfMove != null)
     {
         EndOfMove.Invoke(this, EventArgs.Empty);
     }
 }
Пример #3
0
 private void continueToNextMove()
 {
     switchPlayerToMove();
     m_Board.PieceSetup();
     m_Board.SetValidMoves(NextPlayerToMove);
     if (EndOfMove != null)
     {
         EndOfMove.Invoke(this, EventArgs.Empty);
     }
 }