public bool HasWinner() { // Create a for loop that checks if there is a row, column, or diagonal // that contains 3 of the same input (e.g. someone has won). Usin inbuilt functions for(int i = 0; i < 3 ; i++) { if (Board.GetRow(i) == "XXX" || Board.GetRow(i) == "OOO") return true; if (Board.GetColumn(i) == "XXX" || Board.GetColumn(i) == "OOO") return true; } string leftDiagonal = Board.GetDiagonal(true); string rightDiagonal = Board.GetDiagonal(false); if (leftDiagonal == "XXX" || leftDiagonal == "OOO") return true; if (rightDiagonal == "XXX" || leftDiagonal == "OOO") return true; else return false; }
public string GetDiagonal(bool topLeftToBottomRight) { string diagonalString = ""; if (topLeftToBottomRight) { for (int i = 0; i < board.GetLength(0); i++) { diagonalString += board[i, i]; } } else { for (int i=0; i < board.GetLength(0); i++) { diagonalString += board[i, board.GetLength(1) -1 -i]; } } return diagonalString; }