private async Task StartGame(DiscordChannel channel) { var message = await BotMethods.SendMessage(this, new SendMessageEventArgs { Message = "Choosing a puzzle...", Channel = channel, LogMessage = "WheelOfFortuneGameStart" }); await semaphore.WaitAsync(); currentChannel = channel; eliminatedUsers.Clear(); var random = new Random(); currentPuzzle = puzzles[random.Next(0, puzzles.Count)]; semaphore.Release(); for (int i = 5; i > 0; --i) { await message.ModifyAsync($"Game starting in {i} second{(i != 1 ? "s" : string.Empty)}..."); await Task.Delay(1000); } var messageListener = new WheelOfFortuneMessageListener(this); BotMethods.AddMessageListener(this, GuildId, messageListener); string revealedPuzzle = currentPuzzle.Phrase.ToUpper(); for (char c = 'A'; c <= 'Z'; ++c) { revealedPuzzle = revealedPuzzle.Replace(c, '˷'); } await message.ModifyAsync($"{currentPuzzle.Category}\n\n{revealedPuzzle}".CodeBlock()); int timeToWait = 30000 / revealedPuzzle.Count(c => c == '˷'); while (currentChannel != null && revealedPuzzle != currentPuzzle.Phrase.ToUpper()) { await Task.Delay(timeToWait); if (currentChannel != null) { bool replacedUnderscore = false; while (!replacedUnderscore) { int index = random.Next(0, revealedPuzzle.Length); if (revealedPuzzle[index] == '˷') { revealedPuzzle = revealedPuzzle.Substring(0, index) + currentPuzzle.Phrase.ToUpper()[index] + revealedPuzzle.Substring(index + 1); replacedUnderscore = true; } } await message.ModifyAsync($"{currentPuzzle.Category}\n\n{revealedPuzzle}".CodeBlock()); } } await semaphore.WaitAsync(); if (currentChannel != null) { await BotMethods.SendMessage(this, new SendMessageEventArgs { Message = $"No one got the puzzle! The answer was {revealedPuzzle.Code()}. Thanks for playing!", Channel = channel, LogMessage = "WheelOfFortuneGameLose" }); } else { await message.ModifyAsync($"{$"{currentPuzzle.Category}\n\n{revealedPuzzle}".CodeBlock()}\n{lastWinningMessage.Author.Mention} got the correct answer {currentPuzzle.Phrase.ToUpper().Code()}"); } currentChannel = null; eliminatedUsers.Clear(); currentPuzzle = null; semaphore.Release(); BotMethods.RemoveMessageListener(this, GuildId, messageListener); }