private void GetSideWordsForWordPlayedHorizontal(List<TileControl> playedTiles, ref List<UpWord> playedWords) { foreach (TileControl tile in playedTiles) { // If there are letters on the board above the played tile then add those first. if (tile.GridY > 0 && m_boardTiles[tile.GridX, tile.GridY - 1] != null) { int Y = tile.GridY - 1; UpWord wordCreated = new UpWord(); // Work up the column until an empty space is found. while (Y > 0 && m_boardTiles[tile.GridX, Y - 1] != null) { Y--; } // Now work back down to build up the word. while (Y < GRID_SIZE && (m_boardTiles[tile.GridX, Y] != null || Y == tile.GridY)) { if (Y == tile.GridY) { wordCreated.AppendLetter(tile); } else { wordCreated.AppendLetter(m_boardTiles[tile.GridX, Y]); } Y++; } if (wordCreated.Word.Length > 1 && wordCreated.Word != "QU") { playedWords.Add(wordCreated); } } // If there are letters on the board below the played tile then start with the played tile and go from there. else if (tile.GridY + 1 < GRID_SIZE && m_boardTiles[tile.GridX, tile.GridY + 1] != null) { int Y = tile.GridY + 1; UpWord wordCreated = new UpWord(); wordCreated.AppendLetter(tile); // Now work back down to build up the word. while (Y < GRID_SIZE && m_boardTiles[tile.GridX, Y] != null) { wordCreated.AppendLetter(m_boardTiles[tile.GridX, Y]); Y++; } if (wordCreated.Word.Length > 1 && wordCreated.Word != "QU") { playedWords.Add(wordCreated); } } } }
private void GetSideWordsForWordPlayedVertical(List<TileControl> playedTiles, ref List<UpWord> playedWords) { foreach (TileControl tile in playedTiles) { // If there are letters on the board to the left of the played tile then add those first. if (tile.GridX > 0 && m_boardTiles[tile.GridX - 1, tile.GridY] != null) { int X = tile.GridX - 1; UpWord wordCreated = new UpWord(); // Work back along the row until an empty space is found. while (X > 0 && m_boardTiles[X - 1, tile.GridY] != null) { X--; } // Now work forward to build up the word. while (X < GRID_SIZE && (m_boardTiles[X, tile.GridY] != null || X == tile.GridX)) { if (X == tile.GridX) { wordCreated.AppendLetter(tile); } else { wordCreated.AppendLetter(m_boardTiles[X, tile.GridY]); } X++; } if (wordCreated.Word.Length > 1 && wordCreated.Word != "QU") { playedWords.Add(wordCreated); } } // If there are letters on the board to the right of the played tile then start with the played tile and go from there. else if (tile.GridX + 1 < GRID_SIZE && m_boardTiles[tile.GridX + 1, tile.GridY] != null) { int X = tile.GridX + 1; UpWord wordCreated = new UpWord(); wordCreated.AppendLetter(tile); // Now work forward to build up the word. while (X < GRID_SIZE && m_boardTiles[X, tile.GridY] != null) { wordCreated.AppendLetter(m_boardTiles[X, tile.GridY]); X++; } if (wordCreated.Word.Length > 1 && wordCreated.Word != "QU") { playedWords.Add(wordCreated); } } } }
private UpWord GetMainWordPlayedVertical(List<TileControl> playedTiles) { int index; int lastY = -1; UpWord wordCreated = new UpWord(); // Find the word that has been played. wordCreated.AppendLetter(playedTiles[0]); // Prepend any letters that appear before the played word. if (playedTiles[0].GridY > 0) { int previousY = playedTiles[0].GridY - 1; while (previousY >= 0 && m_boardTiles[playedTiles[0].GridX, previousY] != null) { wordCreated.PrependLetter(m_boardTiles[playedTiles[0].GridX, previousY]); previousY--; } } // Now fill in the played letters and any that are already on the board. lastY = playedTiles[0].GridY; for (index = 1; index < playedTiles.Count; index++) { // Fill in any letters that are already on the board. if (lastY != playedTiles[index].GridY - 1) { for (int Y = lastY + 1; Y < playedTiles[index].GridY; Y++) { if (m_boardTiles[playedTiles[index].GridX, Y] != null) { wordCreated.AppendLetter(m_boardTiles[playedTiles[index].GridX, Y]); } else { ShowMessage("There seems to be a gap in your word!"); wordCreated = null; return null; } } } // Add the current tile. wordCreated.AppendLetter(playedTiles[index]); // Save the last Y value; lastY = playedTiles[index].GridY; } // Append any letters that appear after the played word. if (lastY < GRID_SIZE) { int nextY = lastY + 1; while (nextY < GRID_SIZE && m_boardTiles[playedTiles[0].GridX, nextY] != null) { wordCreated.AppendLetter(m_boardTiles[playedTiles[0].GridX, nextY]); nextY++; } } return wordCreated; }