speedtyping almost done, only leniency left
This commit is contained in:
parent
5e23aa848f
commit
f1e34ca1bd
@ -19,18 +19,20 @@ namespace NadekoBot {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//todo add leniency and stuff
|
||||||
public class TypingGame {
|
public class TypingGame {
|
||||||
public static float WORD_VALUE { get; } = 4.5f;
|
public static float WORD_VALUE { get; } = 4.5f;
|
||||||
private Channel channel;
|
private Channel channel;
|
||||||
public string currentSentence;
|
public string currentSentence;
|
||||||
public bool IsActive;
|
public bool IsActive;
|
||||||
private Stopwatch sw;
|
private Stopwatch sw;
|
||||||
|
private List<ulong> finishedUserIds;
|
||||||
|
|
||||||
public TypingGame(Channel channel) {
|
public TypingGame(Channel channel) {
|
||||||
this.channel = channel;
|
this.channel = channel;
|
||||||
currentSentence = SentencesProvider.GetRandomSentence();
|
|
||||||
IsActive = false;
|
IsActive = false;
|
||||||
sw = new Stopwatch();
|
sw = new Stopwatch();
|
||||||
|
finishedUserIds = new List<ulong>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Channel Channell { get; internal set; }
|
public Channel Channell { get; internal set; }
|
||||||
@ -38,6 +40,7 @@ namespace NadekoBot {
|
|||||||
internal async Task<bool> Stop() {
|
internal async Task<bool> Stop() {
|
||||||
if (!IsActive) return false;
|
if (!IsActive) return false;
|
||||||
NadekoBot.client.MessageReceived -= AnswerReceived;
|
NadekoBot.client.MessageReceived -= AnswerReceived;
|
||||||
|
finishedUserIds.Clear();
|
||||||
IsActive = false;
|
IsActive = false;
|
||||||
sw.Stop();
|
sw.Stop();
|
||||||
sw.Reset();
|
sw.Reset();
|
||||||
@ -46,17 +49,23 @@ namespace NadekoBot {
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal async Task Start() {
|
internal async Task Start() {
|
||||||
|
if (IsActive) return; // can't start running game
|
||||||
IsActive = true;
|
IsActive = true;
|
||||||
|
currentSentence = SentencesProvider.GetRandomSentence();
|
||||||
|
int i = (int)(currentSentence.Length / WORD_VALUE * 1.7f);
|
||||||
|
await channel.SendMessage($":clock2: Next contest will last for {i} seconds. Type the bolded text as fast as you can.");
|
||||||
|
|
||||||
|
|
||||||
var msg = await channel.SendMessage("Starting new typing contest in **3**...");
|
var msg = await channel.SendMessage("Starting new typing contest in **3**...");
|
||||||
await Task.Delay(1000);
|
await Task.Delay(1000);
|
||||||
await msg.Edit("Starting new typing contest in **2**...");
|
await msg.Edit("Starting new typing contest in **2**...");
|
||||||
await Task.Delay(1000);
|
await Task.Delay(1000);
|
||||||
await msg.Edit("Starting new typing contest in **1**...");
|
await msg.Edit("Starting new typing contest in **1**...");
|
||||||
await Task.Delay(1000);
|
await Task.Delay(1000);
|
||||||
await msg.Edit($"**{currentSentence}**");
|
await msg.Edit($":book:**{currentSentence}**:book:");
|
||||||
sw.Start();
|
sw.Start();
|
||||||
HandleAnswers();
|
HandleAnswers();
|
||||||
int i = (int)(currentSentence.Length / WORD_VALUE * 1.7f);
|
|
||||||
while (i > 0) {
|
while (i > 0) {
|
||||||
await Task.Delay(1000);
|
await Task.Delay(1000);
|
||||||
i--;
|
i--;
|
||||||
@ -77,8 +86,13 @@ namespace NadekoBot {
|
|||||||
|
|
||||||
var guess = e.Message.RawText;
|
var guess = e.Message.RawText;
|
||||||
|
|
||||||
if (currentSentence == guess) {
|
if (currentSentence == guess && !finishedUserIds.Contains(e.User.Id)) {
|
||||||
|
finishedUserIds.Add(e.User.Id);
|
||||||
await channel.Send($"{e.User.Mention} finished in **{sw.Elapsed.Seconds}** seconds, **{ currentSentence.Length / TypingGame.WORD_VALUE / sw.Elapsed.Seconds * 60 }** WPM!");
|
await channel.Send($"{e.User.Mention} finished in **{sw.Elapsed.Seconds}** seconds, **{ currentSentence.Length / TypingGame.WORD_VALUE / sw.Elapsed.Seconds * 60 }** WPM!");
|
||||||
|
if (finishedUserIds.Count % 2 == 0) {
|
||||||
|
await e.Send($":exclamation: `A lot of people finished, here is the text for those still typing:`\n\n:book:**{currentSentence}**:book:");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -137,6 +151,7 @@ namespace NadekoBot {
|
|||||||
await obj.SaveAsync();
|
await obj.SaveAsync();
|
||||||
await e.Send("Added new typing article.");
|
await e.Send("Added new typing article.");
|
||||||
});
|
});
|
||||||
|
|
||||||
//todo add user submissions
|
//todo add user submissions
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user