public override async void loose() { string finalStr = "You lost." + Environment.NewLine; string[] corrWords = words.Where(x => x[0] == currentWord[currentWord.Length - 1]).ToArray(); if (corrWords.Length == 0) { finalStr += "To be honest, I didn't know a word to answer too." + Environment.NewLine; } else { string word = corrWords[b.rand.Next(0, corrWords.Length)]; string[] insideWord = word.Split('$'); finalStr += "Here's a word you could have say: " + JishoModule.toRomaji(insideWord[0]) + " - Meaning: " + insideWord[1] + Environment.NewLine; } relationPlayer.increaseShiritoriGames(); if (score > relationPlayer.getShiritoriBestScore()) { finalStr += "Congratulation, you beat the previous best score of " + relationPlayer.getShiritoriBestScore() + " with a new score of " + score + "." + Environment.NewLine; } else if (score == relationPlayer.getShiritoriBestScore()) { finalStr += "You equilized the previous best score of " + score + "."; } else { finalStr += "You didn't beat the current best score of " + relationPlayer.getShiritoriBestScore() + " with the score of " + score + "." + Environment.NewLine; } relationPlayer.setShiritoriScore(score); await chan.SendMessageAsync(finalStr); }
public override async void post() { if (currentWord == null) { currentWord = "しりとり"; if (romajiOnly) { await chan.SendMessageAsync("shiritori"); } else { await chan.SendMessageAsync("しりとり"); } } else { string[] corrWords = words.Where(x => x[0] == currentWord[currentWord.Length - 1]).ToArray(); if (corrWords.Length == 0) { await chan.SendMessageAsync("I don't know any other word..."); } else { string word = corrWords[b.rand.Next(0, corrWords.Length)]; string[] insideWord = word.Split('$'); if (romajiOnly) { await chan.SendMessageAsync(JishoModule.toRomaji(insideWord[0]) + " - Meaning: " + insideWord[1]); } else { await chan.SendMessageAsync(insideWord[0] + " - Meaning: " + insideWord[1]); } words.Remove(insideWord[0]); currentWord = insideWord[0]; alreadySaid.Add(insideWord[0]); } } timeQuestion = DateTime.Now; }
public override async void isCorrect(string name, ulong userId) { if (timeQuestion == DateTime.MinValue) { await chan.SendMessageAsync("Please wait until I posted all the images."); } else { name = JishoModule.toHiragana(name); foreach (char c in name) { if (c < 0x3041 && c > 0x3096) { await chan.SendMessageAsync("I'm sorry but I'm only handling hiragana and romaji for now."); return; } } string json; using (WebClient wc = new WebClient()) { wc.Encoding = Encoding.UTF8; json = wc.DownloadString("http://www.jisho.org/api/v1/search/words?keyword=" + name); } bool isCorrect = false; foreach (string s in BooruModule.getElementXml("\"japanese\":[", "", json, '$').Split(new string[] { "\"japanese\":[" }, StringSplitOptions.None)) { string hiragana = BooruModule.getElementXml("\"reading\":\"", "", s, '"'); if (name == hiragana) { isCorrect = true; if (BooruModule.getElementXml("parts_of_speech\":[\"", "", json, '"') != "Noun") { await chan.SendMessageAsync("This word isn't a noun."); relationPlayer.increaseShiritoriAttempt(false); return; } break; } } if (!isCorrect) { await chan.SendMessageAsync("This word doesn't exist."); relationPlayer.increaseShiritoriAttempt(false); return; } if (name[0] != currentWord[currentWord.Length - 1]) { await chan.SendMessageAsync("Your word must begin by a " + currentWord[currentWord.Length - 1] + "."); relationPlayer.increaseShiritoriAttempt(false); return; } if (alreadySaid.Contains(name)) { await chan.SendMessageAsync("This word was already said."); lost = true; relationPlayer.increaseShiritoriAttempt(false); return; } if (name[name.Length - 1] == 'ん') { await chan.SendMessageAsync("Your word is finishing with a ん."); lost = true; relationPlayer.increaseShiritoriAttempt(false); return; } timeQuestion = DateTime.MinValue; words.Remove(name); currentWord = name; post(); relationPlayer.increaseShiritoriAttempt(true); score++; } }