public override void Reply(CChatMaster chatMaster, CWindow window, CMessage message) { if (!(bool)window.PermaVariables.GetVariable("AcceptInput")) { return; } if (string.IsNullOrWhiteSpace(message.Message)) { return; } string sSwitch = ""; string[] sTokens; if (!message.Message.Contains(" ")) { sSwitch = message.Message; } else { sTokens = message.Message.Split(' '); sSwitch = sTokens[0]; } switch (sSwitch.ToLower()) { case "start": Start(chatMaster, window); break; case "restart": Restart(chatMaster, window); break; case "stop": Close(chatMaster, window); break; default: if (!(bool)window.PermaVariables.GetVariable("InGame")) { chatMaster.SendMessageToWindow(window, "Hi, " + window.ChatName + ". I'm not available, but would you like a game of hangman?" + " If so, type 'start' to play!"); } else { if (message.Message.Length > 1) { if (sSwitch == new string((char[])window.PermaVariables.GetVariable("CurrentWord"))) { Win(chatMaster, window); } else { chatMaster.SendMessageToWindow(window, "I don't know what \"" + message.Message + "\" means. If you're trying to play the game, " + "please remember you can only try one letter at a time!"); } } else { TryLetter(chatMaster, window, sSwitch.ToLower()[0]); } } return; } base.Reply(chatMaster, window, message); }
private void TryLetter(CChatMaster chatMaster, CWindow window, char sSwitch) { if (HasTriedLetter(window, sSwitch)) { chatMaster.SendMessageToWindow(window, "You've already tried " + sSwitch.ToString() + "!"); return; } char[] currentword = (char[])window.PermaVariables.GetVariable("CurrentWord"); char[] progress = (char[])window.PermaVariables.GetVariable("Progress"); if (currentword.Contains(sSwitch)) { for (int i = 0; i < currentword.Length; i++) { if (currentword[i] == sSwitch) { progress[i] = sSwitch; } } window.PermaVariables.EditVariable("Progress", progress); if (new string(currentword) == new string(progress)) { Win(chatMaster, window); return; } } else { IncrementStage(chatMaster, window); } AddTriedLetter(window, sSwitch); chatMaster.SendMessageToWindow(window, GetProgress(chatMaster, window)); }
private void Win(CChatMaster chatMaster, CWindow window) { chatMaster.SendMessageToWindow(window, "Congratulations! You won! Hope you had fun! :)"); Reset(chatMaster, window); window.PermaVariables.EditVariable("InGame", false); }
public void Close(CChatMaster chatMaster, CWindow window) { chatMaster.SendMessageToWindow(window, "Ok. I've stopped the game!"); Reset(chatMaster, window); window.PermaVariables.EditVariable("InGame", false); }
private void GetRandomWord(CChatMaster chatMaster, CWindow window) { SetAcceptInput(window, false); chatMaster.SendMessageToWindow(window, "Finding a word!"); WebClient wc = new WebClient(); wc.DownloadDataCompleted += delegate(object sender, DownloadDataCompletedEventArgs e) { this.BeginGame(chatMaster, window, CDataProcess.GetRandomWordFromRaw(e.Result)); ((WebClient)sender).Dispose(); }; wc.DownloadDataAsync(new Uri("http://www.thefreedictionary.com/dictionary.htm")); }
private void Death(CChatMaster chatMaster, CWindow window) { chatMaster.SendMessageToWindow(window, "Oh dear! You got hung! The word was " + new string((char[])window.PermaVariables.GetVariable("CurrentWord")) + ". Maybe you should try again?"); Reset(chatMaster, window); window.PermaVariables.EditVariable("InGame", false); }
private void BeginGame(CChatMaster chatMaster, CWindow window, string strWord) { char[] word = strWord.ToCharArray(); char[] progress = new char[word.Length]; window.PermaVariables.EditVariable("CurrentWord", word); for (int i = 0; i < progress.Length; i++) { progress[i] = '_'; } window.PermaVariables.EditVariable("Progress", progress); window.PermaVariables.EditVariable("InGame", true); SetAcceptInput(window, true); chatMaster.SendMessageToWindow(window, "Remember you can stop at any time by typing 'stop'.\n" + GetProgress(chatMaster, window)); }
public void Restart(CChatMaster chatMaster, CWindow window) { chatMaster.SendMessageToWindow(window, "Ok. I'll start a new game!"); window.PermaVariables.EditVariable("InGame", false); Start(chatMaster, window); }