// Get new word from WordList Words based no letter count public string RetrieveWord(List <string> usedWords, int letterCount) { var wordList = WordList.Instance().WordAndDefinitions.Select(w => w.Word).ToArray(); var wordArray = wordList.Where(w => w.Length == letterCount). Except(usedWords). ToArray(); var word = string.Empty; if (wordArray == null) { var opResults = new OperationResult() { Success = false }; opResults.AddMessage("Ran out of words"); return(null); } if (wordArray.Length == 0) { var opResults = new OperationResult() { Success = false }; opResults.AddMessage("No words with the desired lettercount"); return(null); } return(wordArray[_random.Next(wordArray.Length)]);; }
// After words are placed and sorted, this method looks up the placed word definition public List <PlacedWord> FindDefinitionsAndAssignLocationIndex(List <PlacedWord> placedWords) { var placedWordWithDeets = new List <PlacedWord>(); var previousStartPos = new Tuple <int, int>(-1, -1); var count = 0; for (var i = 0; i < placedWords.Count; i++) { var definitionArray = WordList.Instance().WordAndDefinitions.Where(d => d.Word == placedWords[i].Word).ToArray(); if (definitionArray == null) { return(null); } var definition = definitionArray[0].Definition; if (!previousStartPos.Equals(placedWords[i].StartPos)) { count++; } placedWordWithDeets.Add(new PlacedWord { Word = placedWords[i].Word, StartPos = placedWords[i].StartPos, Direction = placedWords[i].Direction, DefinitionIndex = count.ToString(), Definition = definition, }); // Assign Definition index to placedWord placedWords[i].DefinitionIndex = count.ToString(); previousStartPos = placedWords[i].StartPos; } return(placedWordWithDeets); }