public void populate(string inFileName) { StreamReader reader = new StreamReader(inFileName, Encoding.UTF8); string line; string [] parts; wordInfo wi; while ((line = reader.ReadLine()) != null) { wi = new wordInfo(); parts = line.Split(new char[] { ',', '\t' }); wi.wordLowerCase = parts[0]; wi.wordLowerCaseHyphen = parts[1]; wi.wordUpperCase = wi.wordLowerCase.ToUpper(); wi.wordUpperCaseHyphen = wi.wordLowerCaseHyphen.ToUpper(); //wi.soundFileName = baseDir + @"Media\" + parts[4]; wi.imgFileName = baseDir + @"Media\" + parts[3]; wi.category = parts[2]; words.Add(wi); if (!categories.Contains(wi.category)) { categories.Add(wi.category); } if (!wordsByCategory.ContainsKey(wi.category)) { wordsByCategory.Add(wi.category, new List <wordInfo>()); } wordsByCategory[wi.category].Add(wi); if (!wordsByLetter.ContainsKey(wi.wordUpperCase[0])) { wordsByLetter.Add(wi.wordUpperCase[0], new List <wordInfo>()); } wordsByLetter[wi.wordUpperCase[0]].Add(wi); if (!wordsByLength.ContainsKey(wi.wordUpperCase.Length)) { wordsByLength.Add(wi.wordUpperCase.Length, new List <wordInfo>()); } wordsByLength[wi.wordUpperCase.Length].Add(wi); } reader.Close(); }
public SingleWordQuestion(azbukaGame azbuka, int diff, int numLetters, Random r) { int minLen = 0; int maxLen = 20; switch (diff) { case 3: minLen = 8; maxLen = 20; break; case 2: minLen = 5; maxLen = 7; break; default: minLen = 1; maxLen = 4; break; } word = azbuka.getRandomWords(1, minLen, maxLen)[0]; if (r == null) { keyLetterPosition = 0; } else { keyLetterPosition = r.Next(1, word.wordUpperCase.Length); } answerLetter = word.wordUpperCase[keyLetterPosition]; candidateLetters = azbuka.getRandomLetters(numLetters, answerLetter); answerIndex = candidateLetters.IndexOf(answerLetter); }