示例#1
0
 private void tellCurrentPlayerToPlay(HumanPlayer i_BlackHumanPlayer, HumanPlayer i_WhiteHumanPlayer,
                                      PcPlayer i_BlackPcPlayer, List <Cell> i_BlackPcPlayerOptions, out int io_CurrentMoveRowIndex, out int io_CurrentMoveColumnIndex)
 {
     // this method recieves the players, and the pcplayer options, checks who should play now and tell them to play.
     // the method will keep asking for legal input as long as it is not logicaly legal.
     if (m_GameMode == eGameMode.HumanVsHuman)
     {
         if (m_PlayerTurn == GameUtilities.ePlayerColor.BlackPlayer)
         {
             i_BlackHumanPlayer.Play(m_GameBoard.Size, out io_CurrentMoveRowIndex, out io_CurrentMoveColumnIndex);
         }
         else
         {
             i_WhiteHumanPlayer.Play(m_GameBoard.Size, out io_CurrentMoveRowIndex, out io_CurrentMoveColumnIndex);
         }
     }
     else
     {
         if (m_PlayerTurn == GameUtilities.ePlayerColor.BlackPlayer)
         {
             i_BlackPcPlayer.Play(m_GameBoard, m_GameMode, out io_CurrentMoveRowIndex, out io_CurrentMoveColumnIndex);
         }
         else
         {
             i_WhiteHumanPlayer.Play(m_GameBoard.Size, out io_CurrentMoveRowIndex, out io_CurrentMoveColumnIndex);
         }
     }
 }
示例#2
0
        private static void printPlayersScore(HumanPlayer i_WhiteHumanPlayer, HumanPlayer i_BlackHumanPlayer, PcPlayer i_BlackPCPlayer)
        {
            string whitePlayerName, blackPlayerName;
            int    whitePlayerScore, blackPlayerScore;

            whitePlayerName  = i_WhiteHumanPlayer.Name;
            blackPlayerName  = i_BlackHumanPlayer.Active == true ? i_BlackHumanPlayer.Name : i_BlackPCPlayer.Name;
            whitePlayerScore = i_WhiteHumanPlayer.Score;
            blackPlayerScore = i_BlackHumanPlayer.Active == true ? i_BlackHumanPlayer.Score : i_BlackPCPlayer.Score;

            string scoreMessage = string.Format("{0} : {1}              {2} : {3}", whitePlayerName, whitePlayerScore, blackPlayerName, blackPlayerScore);

            Console.WriteLine(scoreMessage);
        }
示例#3
0
        public static void Draw(Board i_GameBoard, HumanPlayer i_WhiteHumanPlayer, HumanPlayer i_BlackHumanPlayer, PcPlayer i_BlackPCPlayer)
        {
            // this method recieves a board and drawing it.
            StringBuilder stringBuilder = new StringBuilder(string.Empty, 36);

            printPlayersScore(i_WhiteHumanPlayer, i_BlackHumanPlayer, i_BlackPCPlayer);
            printFirstLine(i_GameBoard.Size);
            printLineOfEqualSign(i_GameBoard.Size);
            for (int i = 0; i < (int)i_GameBoard.Size; i++)
            {
                printBoardRowData(i_GameBoard, i);
                printLineOfEqualSign(i_GameBoard.Size);
            }
        }
示例#4
0
 private void restartGame(HumanPlayer i_WhiteHumanPlayer, HumanPlayer i_BlackHumanPlayer, PcPlayer i_BlackPCPlayer)
 {
     // this method restarts a game.
     initialize(i_WhiteHumanPlayer, i_BlackHumanPlayer, i_BlackPCPlayer);
 }
示例#5
0
        public void Run()
        {
            // this method maintains the main loop of the game.
            HumanPlayer   whiteHumanPlayer = new HumanPlayer(GameUtilities.ePlayerColor.WhitePlayer);
            HumanPlayer   blackHumanPlayer = new HumanPlayer(GameUtilities.ePlayerColor.BlackPlayer);
            PcPlayer      blackPCPlayer = new PcPlayer();
            int           currentPlayerMoveRowIndex, currentPlayerMoveColumnIndex;
            bool          isPlayerMoveLegal, isGameEnd = false;
            List <Cell>   cellsToUpdate = new List <Cell>();
            eGameDecision rematchOrExit;

            configureGameSettings(whiteHumanPlayer, blackHumanPlayer, blackPCPlayer);
            initialize(whiteHumanPlayer, blackHumanPlayer, blackPCPlayer);
            while (true)
            {
                UI.Draw(m_GameBoard, whiteHumanPlayer, blackHumanPlayer, blackPCPlayer);
                do
                {
                    tellCurrentPlayerToPlay(blackHumanPlayer, whiteHumanPlayer, blackPCPlayer, m_BlackPlayerOptions,
                                            out currentPlayerMoveRowIndex, out currentPlayerMoveColumnIndex);
                    if (currentPlayerMoveColumnIndex == (int)HumanPlayer.eUserRequest.Exit)
                    {
                        isGameEnd = true;
                        break;
                    }

                    isPlayerMoveLegal = isLegalMove(currentPlayerMoveRowIndex, currentPlayerMoveColumnIndex, ref cellsToUpdate);
                    if (!isPlayerMoveLegal)
                    {
                        UI.InformPlayerItMoveIsntAnOption(m_PlayerTurn);
                    }
                }while (!isPlayerMoveLegal);

                if (isGameEnd)
                {
                    // the user chose to exit the game.
                    break;
                }

                m_GameBoard.UpdateBoard(cellsToUpdate, m_PlayerTurn);
                updatePlayersOptions();
                updatePlayersScore(whiteHumanPlayer, blackHumanPlayer, blackPCPlayer);
                turnChangingManager();
                isGameEnd = isGameOver();
                Ex02.ConsoleUtils.Screen.Clear();
                if (isGameEnd)
                {
                    determineWinner();
                    rematchOrExit = UI.AskUserForRematchOrExit();
                    if (rematchOrExit == eGameDecision.Rematch)
                    {
                        isGameEnd = false;
                        restartGame(whiteHumanPlayer, blackHumanPlayer, blackPCPlayer);
                    }
                    else
                    {
                        // the user chose to exit game
                        break;
                    }
                }
            }

            UI.ShowExitMessage();
            System.Threading.Thread.Sleep(5000);
        }
示例#6
0
 private void initializePlayersScores(HumanPlayer i_WhiteHumanPlayer, HumanPlayer i_BlackHumanPlayer, PcPlayer i_BlackPCPlayer)
 {
     // this method is initializing the players scores
     i_WhiteHumanPlayer.Score = 2;
     i_BlackHumanPlayer.Score = 2;
     i_BlackPCPlayer.Score    = 2;
 }
示例#7
0
 private void initialize(HumanPlayer i_WhiteHumanPlayer, HumanPlayer i_BlackHumanPlayer, PcPlayer i_BlackPCPlayer)
 {
     // this method is initializing the player options, scores and board.
     m_GameBoard.Initialize();
     initializePlayersOptions();
     initializePlayersScores(i_WhiteHumanPlayer, i_BlackHumanPlayer, i_BlackPCPlayer);
     m_PlayerTurn = GameUtilities.ePlayerColor.WhitePlayer;
 }
示例#8
0
        public void configureGameSettings(HumanPlayer i_WhiteHumanPlayer, HumanPlayer i_BlackHumanPlayer, PcPlayer i_BlackPCPlayer)
        {
            // this method is configuring thte game settings
            string whitePlayerName, blackPlayerName;

            GameManager.eGameMode userGameModeChoice;
            Board.eBoardSize      userBoardSizeChoice;

            i_WhiteHumanPlayer.Active = true;
            whitePlayerName           = UI.AskUserForUserName();
            i_WhiteHumanPlayer.Name   = whitePlayerName;
            userGameModeChoice        = UI.AskUserForGameMode();
            m_GameMode = userGameModeChoice;
            if (userGameModeChoice == eGameMode.HumanVsHuman)
            {
                i_BlackHumanPlayer.Active = true;
                blackPlayerName           = UI.AskUserForUserName();
                i_BlackHumanPlayer.Name   = blackPlayerName;
            }
            else
            {
                i_BlackPCPlayer.Active = true;
            }

            userBoardSizeChoice = UI.AskUserForBoardSize();
            m_GameBoard         = new Board(userBoardSizeChoice);
        }
示例#9
0
        private void updatePlayersScore(HumanPlayer i_WhiteHumanPlayer, HumanPlayer i_BlackHumanPlayer, PcPlayer i_BlackPCPlayer)
        {
            // this method is updating the players scores.
            int updatedWhitePlayerScore, updatedBlackPlayerScore;

            updatedWhitePlayerScore  = m_GameBoard.CountSignAppearances((char)GameUtilities.ePlayerColor.WhitePlayer);
            updatedBlackPlayerScore  = m_GameBoard.CountSignAppearances((char)GameUtilities.ePlayerColor.BlackPlayer);
            i_WhiteHumanPlayer.Score = updatedWhitePlayerScore;
            if (i_BlackHumanPlayer.Active)
            {
                i_BlackHumanPlayer.Score = updatedBlackPlayerScore;
            }
            else
            {
                i_BlackPCPlayer.Score = updatedBlackPlayerScore;
            }
        }