static public void ReadWordsFromFile(string path) { if (File.Exists(path)) { var text = File.ReadLines(path); if (text.Count() > 0) { string[] output = new string[text.Count()]; int i = 0; foreach (var word in text) { output[i] = word; i++; } WordsSet = new WordsSet(output); } else { WordsSet = new WordsSet(new string[0]); } } else { File.Create("words.txt"); WordsSet = new WordsSet(new string[0]); } }
public void CreateNewField(int xSize, int ySize, WordsSet words) { XSize = xSize; YSize = ySize; CellLetter = new char[XSize, YSize]; CellColor = new int[XSize, YSize]; bool[,] preField = CreateFieldOfFreeCells(); var coordList = new List <MyVectorInt>(); FillFieldWithWordTemplates(preField, coordList); BreakWormIntoWords(words); FillFieldWithWords(coordList); }
private void BreakWormIntoWords(WordsSet words) { int cellNum; List <int> wordsLenghtList; int tryNum = 0; do { WordsList = new List <string>(); cellNum = XSize * YSize; List <int> wordsLenghtNum = new List <int>(); wordsLenghtList = new List <int>(); for (int i = 0; i < words.WordsSetList.Count; i++) { wordsLenghtNum.Add(words.WordsSetList[i].Count); } do { int wordLenght; int i = 0; do { i++; if (i >= 50 || cellNum <= 2) { wordLenght = 0; break; } wordLenght = rnd.Next(Math.Min(wordsLenghtNum.Count - 1, cellNum) - 2) + 3; if (wordLenght < 5 || wordLenght > 8) { wordLenght = rnd.Next(Math.Min(wordsLenghtNum.Count - 1, cellNum) - 2) + 3; } if (wordLenght < 5 || wordLenght > 8) { wordLenght = rnd.Next(Math.Min(wordsLenghtNum.Count - 1, cellNum) - 2) + 3; } } while (wordsLenghtNum[wordLenght] == 0); if (wordLenght == 0) { break; } wordsLenghtNum[wordLenght]--; cellNum -= wordLenght; wordsLenghtList.Add(wordLenght); WordsList.Add(words.WordsSetList[wordLenght][rnd.Next(words.WordsSetList[wordLenght].Count)]); } while (cellNum > 0); if (cellNum == 0 && WordsList.Count < Settings.WordNumMin) { continue; } tryNum++; if (tryNum > 10000) { Environment.Exit(0); } } while (cellNum > 0); }