Hangman bug fixed
This commit is contained in:
		| @@ -44,7 +44,8 @@ namespace NadekoBot.Modules.Games.Commands.Hangman | |||||||
|                                        .Concat(data.Things) |                                        .Concat(data.Things) | ||||||
|                                        .ToList(); |                                        .ToList(); | ||||||
|             } |             } | ||||||
|             catch (Exception ex) { |             catch (Exception ex) | ||||||
|  |             { | ||||||
|                 Console.WriteLine(ex); |                 Console.WriteLine(ex); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| @@ -65,7 +66,7 @@ namespace NadekoBot.Modules.Games.Commands.Hangman | |||||||
|                 default: |                 default: | ||||||
|                     return data.All[rng.Next(0, data.All.Count)]; |                     return data.All[rng.Next(0, data.All.Count)]; | ||||||
|             } |             } | ||||||
|              |  | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -150,55 +151,55 @@ namespace NadekoBot.Modules.Games.Commands.Hangman | |||||||
|                         } |                         } | ||||||
|                         catch { } |                         catch { } | ||||||
|                     } |                     } | ||||||
|                 } |  | ||||||
|  |  | ||||||
|                 if (!(char.IsLetter(msg.Content[0]) || char.IsDigit(msg.Content[0])))// and a letter or a digit |                     if (!(char.IsLetter(msg.Content[0]) || char.IsDigit(msg.Content[0])))// and a letter or a digit | ||||||
|                     return; |                         return; | ||||||
|  |  | ||||||
|                 var guess = char.ToUpperInvariant(msg.Content[0]); |                     var guess = char.ToUpperInvariant(msg.Content[0]); | ||||||
|                 if (Guesses.Contains(guess)) |                     if (Guesses.Contains(guess)) | ||||||
|                 { |  | ||||||
|                     MessagesSinceLastPost = 0; |  | ||||||
|                     ++Errors; |  | ||||||
|                     if (Errors < MaxErrors) |  | ||||||
|                         await GameChannel.SendErrorAsync("Hangman Game", $"{msg.Author.Mention} Letter `{guess}` has already been used.\n" + ScrambledWord + "\n" + GetHangman(), |  | ||||||
|                             footer: string.Join(" ", Guesses)).ConfigureAwait(false); |  | ||||||
|                     else |  | ||||||
|                         await End().ConfigureAwait(false); |  | ||||||
|                     return; |  | ||||||
|                 } |  | ||||||
|  |  | ||||||
|                 Guesses.Add(guess); |  | ||||||
|  |  | ||||||
|                 if (Term.Word.ToUpperInvariant().Contains(guess)) |  | ||||||
|                 { |  | ||||||
|                     if (GuessedAll) |  | ||||||
|                     { |                     { | ||||||
|                         try { await GameChannel.SendConfirmAsync("Hangman Game", $"{msg.Author.Mention} guessed a letter `{guess}`!").ConfigureAwait(false); } catch { } |                         MessagesSinceLastPost = 0; | ||||||
|  |                         ++Errors; | ||||||
|                         await End().ConfigureAwait(false); |                         if (Errors < MaxErrors) | ||||||
|  |                             await GameChannel.SendErrorAsync("Hangman Game", $"{msg.Author.Mention} Letter `{guess}` has already been used.\n" + ScrambledWord + "\n" + GetHangman(), | ||||||
|  |                                 footer: string.Join(" ", Guesses)).ConfigureAwait(false); | ||||||
|  |                         else | ||||||
|  |                             await End().ConfigureAwait(false); | ||||||
|                         return; |                         return; | ||||||
|                     } |                     } | ||||||
|                     MessagesSinceLastPost = 0; |  | ||||||
|                     try |                     Guesses.Add(guess); | ||||||
|  |  | ||||||
|  |                     if (Term.Word.ToUpperInvariant().Contains(guess)) | ||||||
|                     { |                     { | ||||||
|                         await GameChannel.SendConfirmAsync("Hangman Game", $"{msg.Author.Mention} guessed a letter `{guess}`!\n" + ScrambledWord + "\n" + GetHangman(), |                         if (GuessedAll) | ||||||
|                       footer: string.Join(" ", Guesses)).ConfigureAwait(false); |                         { | ||||||
|  |                             try { await GameChannel.SendConfirmAsync("Hangman Game", $"{msg.Author.Mention} guessed a letter `{guess}`!").ConfigureAwait(false); } catch { } | ||||||
|  |  | ||||||
|  |                             await End().ConfigureAwait(false); | ||||||
|  |                             return; | ||||||
|  |                         } | ||||||
|  |                         MessagesSinceLastPost = 0; | ||||||
|  |                         try | ||||||
|  |                         { | ||||||
|  |                             await GameChannel.SendConfirmAsync("Hangman Game", $"{msg.Author.Mention} guessed a letter `{guess}`!\n" + ScrambledWord + "\n" + GetHangman(), | ||||||
|  |                           footer: string.Join(" ", Guesses)).ConfigureAwait(false); | ||||||
|  |                         } | ||||||
|  |                         catch { } | ||||||
|  |  | ||||||
|                     } |                     } | ||||||
|                     catch { } |  | ||||||
|  |  | ||||||
|                 } |  | ||||||
|                 else |  | ||||||
|                 { |  | ||||||
|                     MessagesSinceLastPost = 0; |  | ||||||
|                     ++Errors; |  | ||||||
|                     if (Errors < MaxErrors) |  | ||||||
|                         await GameChannel.SendErrorAsync("Hangman Game", $"{msg.Author.Mention} Letter `{guess}` does not exist.\n" + ScrambledWord + "\n" + GetHangman(), |  | ||||||
|                             footer: string.Join(" ", Guesses)).ConfigureAwait(false); |  | ||||||
|                     else |                     else | ||||||
|                         await End().ConfigureAwait(false); |                     { | ||||||
|                 } |                         MessagesSinceLastPost = 0; | ||||||
|  |                         ++Errors; | ||||||
|  |                         if (Errors < MaxErrors) | ||||||
|  |                             await GameChannel.SendErrorAsync("Hangman Game", $"{msg.Author.Mention} Letter `{guess}` does not exist.\n" + ScrambledWord + "\n" + GetHangman(), | ||||||
|  |                                 footer: string.Join(" ", Guesses)).ConfigureAwait(false); | ||||||
|  |                         else | ||||||
|  |                             await End().ConfigureAwait(false); | ||||||
|  |                     } | ||||||
|  |  | ||||||
|  |                 } | ||||||
|             } |             } | ||||||
|             catch (Exception ex) { _log.Warn(ex); } |             catch (Exception ex) { _log.Warn(ex); } | ||||||
|         } |         } | ||||||
| @@ -211,4 +212,4 @@ namespace NadekoBot.Modules.Games.Commands.Hangman | |||||||
|     {(Errors > 4 ? "/" : "  ")} {(Errors > 5 ? "\\" : "  ")}        | |     {(Errors > 4 ? "/" : "  ")} {(Errors > 5 ? "\\" : "  ")}        | | ||||||
|                /-\"; |                /-\"; | ||||||
|     } |     } | ||||||
| } | } | ||||||
		Reference in New Issue
	
	Block a user