From fc7c7c6cc9e61c4fc32c3e4a1b7ed7817eaa6657 Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Tue, 19 Dec 2017 00:21:11 -0500 Subject: [PATCH] start hangman, finish up with polls --- Commands/Hangman.cs | 49 ++++++++++++++++++++++++++ Services/HangmanService.cs | 15 ++++++++ Services/PollService.cs | 1 - gallows.txt | 71 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 Commands/Hangman.cs create mode 100644 Services/HangmanService.cs create mode 100644 gallows.txt diff --git a/Commands/Hangman.cs b/Commands/Hangman.cs new file mode 100644 index 0000000..286d850 --- /dev/null +++ b/Commands/Hangman.cs @@ -0,0 +1,49 @@ +using Discord.Commands; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; + +namespace dotbot.Commands +{ + [Group("hangman")] + public class Hangman : ModuleBase + { + static internal string[] Gallows = File.ReadAllText("gallows.txt").Split('='); + public HangmanSession CurrentGames; + + [Command] + [Priority(0)] + [Summary("start a game of hangman!")] + public async Task StartGame([Remainder] string secret) + { + CurrentGames = new HangmanSession(secret); + await ReplyAsync($"{CurrentGames}"); + } + } + + + public class HangmanSession + { + internal string SecretWord; + internal char[] SecretWordLetters => SecretWord.ToCharArray().Distinct().OrderBy(a => a).ToArray(); + internal char[] GuessedLetters; + private int Guesses; + public bool GameOver => SecretWordLetters.SequenceEqual(GuessedLetters.OrderBy(c => c)) && Guesses < Hangman.Gallows.Length; + + public HangmanSession(string secretWord) + { + SecretWord = secretWord; + Guesses = 0; + } + + + public override string ToString() + { + var Incorrects = GuessedLetters.Except(SecretWordLetters); + return $"```{Hangman.Gallows[Guesses]}\n{ShowSecretWord()}\n\nGuessed Letters: {string.Join(' ', GuessedLetters)}\nIncorrect Letters: {string.Join(' ', Incorrects)}```"; + } + + public string ShowSecretWord() => $"Word: {SecretWord.ToCharArray().Select(c => $"{(GuessedLetters.Contains(c) ? c : '_')} ")}"; + } +} diff --git a/Services/HangmanService.cs b/Services/HangmanService.cs new file mode 100644 index 0000000..acd18db --- /dev/null +++ b/Services/HangmanService.cs @@ -0,0 +1,15 @@ +using Discord.WebSocket; + +namespace dotbot.Services +{ + public class HangmanService + { + private DiscordSocketClient _discord; + private Dictionary _activeGames; + + public HangmanService(DiscordSocketClient discord) + { + _discord = discord; + } + } +} diff --git a/Services/PollService.cs b/Services/PollService.cs index ef9fc60..b1388d6 100644 --- a/Services/PollService.cs +++ b/Services/PollService.cs @@ -3,7 +3,6 @@ using Discord.WebSocket; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using System; namespace dotbot.Services { diff --git a/gallows.txt b/gallows.txt new file mode 100644 index 0000000..65a54c4 --- /dev/null +++ b/gallows.txt @@ -0,0 +1,71 @@ + _______ + |/ | + | + | + | + | + | + _|___ + = + _______ + |/ | + | (_) + | + | + | + | + _|___ + = + _______ + |/ | + | (_) + | | + | + | + | + _|___ + = + _______ + |/ | + | (_) + | | + | | + | + | + _|___ + = + _______ + |/ | + | (_) + | | + | | + | / + | + _|___ + = + _______ + |/ | + | (_) + | | + | | + | / \ + | + _|___ + = + _______ + |/ | + | (_) + | \| + | | + | / \ + | + _|___ + = + _______ + |/ | + | (_) + | \|/ + | | + | / \ + | + _|___ \ No newline at end of file