public void SetWord(string word, IUser sender) { _lastSender = sender; UsedWords.Add(word.ToLower()); word = _getValidWord(word); _lastLetter = word.Last(); }
/// <summary> /// Generates a name. /// </summary> /// <returns>The name.</returns> public override string GenerateName() { string name = string.Empty; DateTime startTime = DateTime.Now; while (DateTime.Now < startTime.AddMilliseconds(MaxProcessingTime) && !IsNameValid(name)) { string word = string.Empty; while (string.IsNullOrWhiteSpace(word)) { word = inputWords[random.Next(inputWords.Count)]; } name = word.Substring(random.Next(0, word.Length - ORDER), ORDER); while (name.Length < word.Length) { string token = name.Substring(name.Length - ORDER, ORDER); char letter = GetLetter(token); if (letter == '?') { break; } name += letter; } name = name.Substring(0, 1) + name.Substring(1).ToLower(); name = name.ToTitleCase(); } UsedWords.Add(name); return(name); }
public static char[,] CreateTable() { Words.Clear(); int tableHeight = MenuOptionsData.TableHeight; int tableWidth = MenuOptionsData.TableWidth; char[,] table = new char[tableHeight, tableWidth]; Random random = new Random(); AddWords(); while (CheckAr(table, tableHeight, tableWidth)) { if (TrueWords.Count == 0) { UsedWords.Clear(); Words.Clear(); table = CreateTable(); break; } Word word1 = new Word(); char[,] timeTable = (char[, ])table.Clone(); string word = TrueWords[random.Next(0, TrueWords.Count)]; TrueWords.Remove(word); int positionX = random.Next(0, tableWidth); int positionY = random.Next(0, tableHeight); while (!CleanAr(table, positionX, positionY)) { positionX = random.Next(0, tableWidth); positionY = random.Next(0, tableHeight); } table[positionY, positionX] = word[0]; Coords.Push(positionY); Coords.Push(positionX); for (int i = 1; i < word.Length; i++) { if (TruePos(tableWidth, tableHeight, positionX + 1, positionY) && CleanAr(table, positionX + 1, positionY)) { positionX++; table[positionY, positionX] = word[i]; Coords.Push(positionY); Coords.Push(positionX); } else if (TruePos(tableWidth, tableHeight, positionX, positionY - 1) && CleanAr(table, positionX, positionY - 1)) { positionY--; table[positionY, positionX] = word[i]; Coords.Push(positionY); Coords.Push(positionX); } else if (TruePos(tableWidth, tableHeight, positionX - 1, positionY) && CleanAr(table, positionX - 1, positionY)) { positionX--; table[positionY, positionX] = word[i]; Coords.Push(positionY); Coords.Push(positionX); } else if (TruePos(tableWidth, tableHeight, positionX, positionY + 1) && CleanAr(table, positionX, positionY + 1)) { positionY++; table[positionY, positionX] = word[i]; Coords.Push(positionY); Coords.Push(positionX); } else { table = timeTable; Coords.Clear(); break; } } if (Coords.Count == 0) { continue; } UsedWords.Add(word); word1.Name = word; bool c = true; for (int i = word.Length - 1; i >= 0; i--) { positionX = Coords.Pop(); positionY = Coords.Pop(); word1.CoordsX.Add(positionX); word1.CoordsY.Add(positionY); if (CheckFullElem(table, positionX, positionY, tableWidth, tableHeight) || CheckVariants(table, tableWidth, tableHeight, positionX, positionY)) { continue; } else { table = timeTable; Coords.Clear(); UsedWords.Remove(word); c = false; break; } } if (c) { word1.CoordsX.Reverse(); word1.CoordsY.Reverse(); Words.Add(word1); } } return(table); }