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; }
public UserInfo SetUpPlayer() { UserInfo userInfo = new UserInfo(); userInfo.UserTurn = _userTurn; userInfo.UserName = SetUserName(userInfo.UserTurn); userInfo.UserMarker = SetUserMarker(userInfo.UserTurn); nextTurn(); return userInfo; }
public UserInfo GetPlayersTurn(UserInfo userOne, UserInfo userTwo) { if (_playersTurn == 1) { _playersTurn = 2; return userOne; } else { _playersTurn = 1; return userTwo; } }
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; }
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; }
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; }
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; }
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; }