/// <summary> /// Gets the list of words formed by the game board. This method scans column by column, /// row by row, and returns all of the formed words. /// </summary> /// <returns>List of all of the words formed. If the gameboard is invalid, an empty list /// is returned.</returns> public List <WordCoordinate> GetWordList() { var wordsFormedOnGameBoard = new List <WordCoordinate>(); // // If the game board is invalid, return an empty list. // if (!IsGameBoardValid()) { return(wordsFormedOnGameBoard); } // // Iterate through all of the columns. // for (var i = 0; i < BoardSpaceDimension; i++) { int j = 0; while (j < BoardSpaceDimension) { if (_boardMatrix[i, j]._isOccupied) { int jStart = j; var wc = new WordCoordinate { _string = "", _begin = new Point(i, j) }; do { wc._string += _boardMatrix[i, j]._tile.TileContents; j++; }while ((j < BoardSpaceDimension) && (_boardMatrix[i, j]._isOccupied)); wc._end = new Point(i, j - 1); // // Only add a word if it's greater than one tile in length. // if (j - jStart > 1) { wordsFormedOnGameBoard.Add(wc); } } j++; } } // // Iterate through all of the rows // for (var j = 0; j < BoardSpaceDimension; j++) { int i = 0; while (i < BoardSpaceDimension) { if (_boardMatrix[i, j]._isOccupied) { int iStart = i; var wc = new WordCoordinate { _string = "", _begin = new Point(i, j) }; do { wc._string += _boardMatrix[i, j]._tile.TileContents; i++; }while ((i < BoardSpaceDimension) && (_boardMatrix[i, j]._isOccupied)); wc._end = new Point(i - 1, j); // // Only add a word if it's greater than one tile in length. // if (i - iStart > 1) { wordsFormedOnGameBoard.Add(wc); } } i++; } } return(wordsFormedOnGameBoard); }
/// <summary> /// Gets the list of words formed by the game board. This method scans column by column, /// row by row, and returns all of the formed words. /// </summary> /// <returns>List of all of the words formed. If the gameboard is invalid, an empty list /// is returned.</returns> public List<WordCoordinate> GetWordList() { var wordsFormedOnGameBoard = new List<WordCoordinate>(); // // If the game board is invalid, return an empty list. // if (!IsGameBoardValid()) { return wordsFormedOnGameBoard; } // // Iterate through all of the columns. // for (var i = 0; i < BoardSpaceDimension; i++) { int j = 0; while (j < BoardSpaceDimension) { if (_boardMatrix[i, j]._isOccupied) { int jStart = j; var wc = new WordCoordinate { _string = "", _begin = new Point(i, j) }; do { wc._string += _boardMatrix[i, j]._tile.TileContents; j++; } while ((j < BoardSpaceDimension) && (_boardMatrix[i, j]._isOccupied)); wc._end = new Point(i, j - 1); // // Only add a word if it's greater than one tile in length. // if (j - jStart > 1) { wordsFormedOnGameBoard.Add(wc); } } j++; } } // // Iterate through all of the rows // for (var j = 0; j < BoardSpaceDimension; j++) { int i = 0; while (i < BoardSpaceDimension) { if (_boardMatrix[i, j]._isOccupied) { int iStart = i; var wc = new WordCoordinate { _string = "", _begin = new Point(i, j) }; do { wc._string += _boardMatrix[i, j]._tile.TileContents; i++; } while ((i < BoardSpaceDimension) && (_boardMatrix[i, j]._isOccupied)); wc._end = new Point(i - 1, j); // // Only add a word if it's greater than one tile in length. // if (i - iStart > 1) { wordsFormedOnGameBoard.Add(wc); } } i++; } } return wordsFormedOnGameBoard; }