trivia fix, scramble answer
If you type "idfk" after 10 or more seconds after the trivia question has appeared, you will get a scrambled answer hint.
This commit is contained in:
parent
33e4734d58
commit
a3762848e2
@ -9,6 +9,22 @@ namespace NadekoBot
|
|||||||
{
|
{
|
||||||
public static class Extensions
|
public static class Extensions
|
||||||
{
|
{
|
||||||
|
public static string Scramble(this string word) {
|
||||||
|
|
||||||
|
var letters = word.ToArray();
|
||||||
|
for (int i = 0; i < letters.Length; i++)
|
||||||
|
{
|
||||||
|
if (i % 3 == 0)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (letters[i] != ' ')
|
||||||
|
letters[i] = '_';
|
||||||
|
}
|
||||||
|
return "`"+string.Join(" ", letters)+"`";
|
||||||
|
}
|
||||||
|
|
||||||
public static void Shuffle<T>(this IList<T> list)
|
public static void Shuffle<T>(this IList<T> list)
|
||||||
{
|
{
|
||||||
RNGCryptoServiceProvider provider = new RNGCryptoServiceProvider();
|
RNGCryptoServiceProvider provider = new RNGCryptoServiceProvider();
|
||||||
|
@ -3,6 +3,7 @@ using Discord.Commands;
|
|||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
@ -38,14 +39,13 @@ namespace NadekoBot
|
|||||||
{
|
{
|
||||||
return async e =>
|
return async e =>
|
||||||
{
|
{
|
||||||
Console.WriteLine("doign the func");
|
|
||||||
TriviaGame tg;
|
TriviaGame tg;
|
||||||
if ((tg = StartNewGame(e))!=null)
|
if ((tg = StartNewGame(e))!=null)
|
||||||
{
|
{
|
||||||
await client.SendMessage(e.Channel, "**Trivia game started!**\nFirst player to get to 10 points wins! You have 30 seconds per question.\nUse command [tq] if game was started by accident.");
|
await client.SendMessage(e.Channel, "**Trivia game started!**\nFirst player to get to 10 points wins! You have 30 seconds per question.\nUse command [tq] if game was started by accident.\nTyping [idfk] 15 seconds after the question has started will give you a hint.");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
await client.SendMessage(e.Channel, "Trivia game is already running on this server. The question is:\n**"+GetCurrentQuestion(e.Server.Id).Question+"**\n[tq quits trivia]\n[@NadekoBot clr clears my messages]");
|
await client.SendMessage(e.Channel, "Trivia game is already running on this server. The question is:\n**"+GetCurrentQuestion(e.Server.Id).Question+"**");
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,6 +139,7 @@ namespace NadekoBot
|
|||||||
private bool active = false;
|
private bool active = false;
|
||||||
|
|
||||||
private Timer timeout;
|
private Timer timeout;
|
||||||
|
private Stopwatch stopwatch;
|
||||||
private bool isQuit = false;
|
private bool isQuit = false;
|
||||||
|
|
||||||
public TriviaGame(CommandEventArgs starter, DiscordClient client) {
|
public TriviaGame(CommandEventArgs starter, DiscordClient client) {
|
||||||
@ -152,6 +153,7 @@ namespace NadekoBot
|
|||||||
|
|
||||||
timeout = new Timer();
|
timeout = new Timer();
|
||||||
timeout.Interval = 30000;
|
timeout.Interval = 30000;
|
||||||
|
stopwatch = new Stopwatch();
|
||||||
timeout.Elapsed += (s, e) => { TimeUp(); };
|
timeout.Elapsed += (s, e) => { TimeUp(); };
|
||||||
|
|
||||||
LoadNextRound();
|
LoadNextRound();
|
||||||
@ -162,10 +164,16 @@ namespace NadekoBot
|
|||||||
if (e.Server.Id != _serverId || !active)
|
if (e.Server.Id != _serverId || !active)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (e.Message.Text.ToLower().Equals("idfk")) {
|
||||||
|
GetHint(e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (e.Message.Text.ToLower() == currentQuestion.Answer.ToLower())
|
if (e.Message.Text.ToLower() == currentQuestion.Answer.ToLower())
|
||||||
{
|
{
|
||||||
active = false; //start pause between rounds
|
active = false; //start pause between rounds
|
||||||
timeout.Enabled = false;
|
timeout.Enabled = false;
|
||||||
|
stopwatch.Stop();
|
||||||
|
|
||||||
if (!users.ContainsKey(e.User.Id))
|
if (!users.ContainsKey(e.User.Id))
|
||||||
users.Add(e.User.Id, 1);
|
users.Add(e.User.Id, 1);
|
||||||
@ -186,6 +194,14 @@ namespace NadekoBot
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async void GetHint(MessageEventArgs e) {
|
||||||
|
if (timeout != null && !isQuit && stopwatch.ElapsedMilliseconds > 10000)
|
||||||
|
await client.SendMessage(e.Channel, currentQuestion.Answer.Scramble());
|
||||||
|
else {
|
||||||
|
await client.SendMessage(e.Channel, $"You have to wait {10-stopwatch.ElapsedMilliseconds/1000} more seconds in order to get a hint.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void StopGame() {
|
public void StopGame() {
|
||||||
isQuit = true;
|
isQuit = true;
|
||||||
}
|
}
|
||||||
@ -214,6 +230,8 @@ namespace NadekoBot
|
|||||||
await client.SendMessage(ch, currentQuestion.ToString());
|
await client.SendMessage(ch, currentQuestion.ToString());
|
||||||
t.Enabled = false;
|
t.Enabled = false;
|
||||||
timeout.Enabled = true;//starting countdown of the next question
|
timeout.Enabled = true;//starting countdown of the next question
|
||||||
|
stopwatch.Reset();
|
||||||
|
stopwatch.Start();
|
||||||
};
|
};
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -229,6 +247,8 @@ namespace NadekoBot
|
|||||||
client.MessageReceived -= PotentialGuess;
|
client.MessageReceived -= PotentialGuess;
|
||||||
timeout.Enabled = false;
|
timeout.Enabled = false;
|
||||||
timeout.Dispose();
|
timeout.Dispose();
|
||||||
|
stopwatch.Stop();
|
||||||
|
stopwatch.Reset();
|
||||||
Trivia.FinishGame(this);
|
Trivia.FinishGame(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user