-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPassageLibrary.cs
More file actions
64 lines (58 loc) · 2.25 KB
/
Copy pathPassageLibrary.cs
File metadata and controls
64 lines (58 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using Qwertide.Client.Models;
namespace Qwertide.Client.Services;
/// <summary>
/// Static passage source for v1 (PDD §6). Bundled in the client; a random
/// /api/passages endpoint is a stretch goal. Passages are deliberately ordinary
/// prose and real code, not motivational filler.
/// </summary>
public sealed class PassageLibrary
{
private readonly Random _rng = new();
private readonly Passage[] _passages =
{
new()
{
Id = 1, Difficulty = Difficulty.Short, Source = "warmup",
Text = "The keyboard remembers what the hands forget."
},
new()
{
Id = 2, Difficulty = Difficulty.Short, Source = "warmup",
Text = "Type the line, not the letters, and the speed arrives on its own."
},
new()
{
Id = 3, Difficulty = Difficulty.Medium, Source = "prose",
Text = "A good typist does not chase the next key. They settle into a rhythm, " +
"let the words come in clean groups, and trust the fingers to land where " +
"they have landed a thousand times before."
},
new()
{
Id = 4, Difficulty = Difficulty.Medium, Source = "prose",
Text = "Most of the time the cursor sits still, waiting, and the only sound in " +
"the room is the small click of a thought turning into a sentence that " +
"someone, somewhere, will eventually read."
},
new()
{
Id = 5, Difficulty = Difficulty.Code, Source = "csharp",
Text = "public static double GrossWpm(int chars, double secs) => secs <= 0 ? 0 : (chars / 5.0) / (secs / 60.0);"
},
new()
{
Id = 6, Difficulty = Difficulty.Code, Source = "csharp",
Text = "var top = scores.OrderByDescending(s => s.Wpm).Take(10).ToList();"
},
};
public Passage Random(Difficulty difficulty)
{
var pool = _passages.Where(p => p.Difficulty == difficulty).ToArray();
if (pool.Length == 0)
{
pool = _passages;
}
return pool[_rng.Next(pool.Length)];
}
public Passage ById(int id) => _passages.FirstOrDefault(p => p.Id == id) ?? _passages[0];
}