Пример #1
0
        public bool WonAcross(UserInfo userInfo)
        {
            bool result = false;
            int num = 0;
            int counter = 0;

            while (counter < 3)
            {
                for (int i = counter; i < counter + 1; i++)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        if (GameBoard.gameBoard[i, j] == userInfo.UserMarker)
                        {
                            num += 1;
                            if (num > 2)
                            {
                                result = true;
                            }
                        }
                    }

                }
                counter += 1;
                num = 0;
            }

            return result;
        }
Пример #2
0
        public UserInfo SetUpPlayer()
        {
            UserInfo userInfo = new UserInfo();
            userInfo.UserTurn = _userTurn;

            userInfo.UserName = SetUserName(userInfo.UserTurn);
            userInfo.UserMarker = SetUserMarker(userInfo.UserTurn);

            nextTurn();
            return userInfo;
        }
Пример #3
0
 public UserInfo GetPlayersTurn(UserInfo userOne, UserInfo userTwo)
 {
     if (_playersTurn == 1)
     {
         _playersTurn = 2;
         return userOne;
     }
     else
     {
         _playersTurn = 1;
         return userTwo;
     }
 }
Пример #4
0
        public string RequestPlayerMove(UserInfo userInfo)
        {
            string userInput = "";
            int validNum = -1;

            while (validNum < 0 || validNum > 10)
            {
                Console.WriteLine("{0}, please enter the space you would like to select", userInfo.UserName);
                userInput = Console.ReadLine();
                bool isAValidNum = int.TryParse(userInput, out validNum);
                if (isAValidNum)
                    validNum = int.Parse(userInput);
            }

            return userInput;
        }
Пример #5
0
        public bool KeepPlaying(UserInfo userInfo)
        {
            bool result = false;

            result = WonAcross(userInfo);
            if (!result)
            {
                result = WonUpAndDown(userInfo);
                if (!result)
                {
                    result = WonDiagonal(userInfo);
                    if (!result)
                    {
                        result = IsItATie();
                    }
                }

            }
            return result;
        }
Пример #6
0
        public static bool UpdateGameBoard(string userSelection, UserInfo currentPlayer)
        {
            bool foundChoice = false;

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    if (GameBoard.gameBoard[i, j] == userSelection)
                    {
                        GameBoard.gameBoard[i, j] = currentPlayer.UserMarker;
                        foundChoice = true;
                    }
                }
            }
            Console.Clear();
            DisplayGameBoard();
            if (!foundChoice)
                InValidChoice();

            return foundChoice;
        }
Пример #7
0
        public bool WonDiagonal(UserInfo userInfo)
        {
            bool result = false;
            int num = 0;

            if (GameBoard.gameBoard[0, 2] == userInfo.UserMarker && GameBoard.gameBoard[2, 0] == userInfo.UserMarker && GameBoard.gameBoard[1, 1] == userInfo.UserMarker)
                num += 3;

            else if (GameBoard.gameBoard[0, 0] == userInfo.UserMarker && GameBoard.gameBoard[2, 2] == userInfo.UserMarker && GameBoard.gameBoard[1, 1] == userInfo.UserMarker)
                num += 3;

            if (num == 3)
            {
                result = true;
            }
            return result;
        }
Пример #8
0
        public int WonOrTie(UserInfo userInfo)
        {
            bool wonAcross = WonAcross(userInfo);
            bool wonUpAndDown = WonUpAndDown(userInfo);
            bool wonDiagonal = WonDiagonal(userInfo);
            bool itIsATie = IsItATie();
            int result = 0;

            if (wonAcross)
                result = 1;
            else if (wonUpAndDown)
                result = 2;
            else if (wonDiagonal)
                result = 3;
            else if (itIsATie)
                result = 4;
            return result;
        }