Refactor project structure and update documentation. Replace PixiJS with plain DOM for UI rendering, enhance README with game features, and revise protocol documentation for HTTP API. Remove unused files and streamline client code for better maintainability.
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
namespace HSchool.Simulation;
|
||||
|
||||
/// <summary>
|
||||
/// Suggestions for the "random name" button. Lives here rather than in the client because the
|
||||
/// server is the one that knows which names are already taken.
|
||||
/// </summary>
|
||||
public sealed class SchoolNameGenerator(Random? random = null)
|
||||
{
|
||||
private const int AttemptsBeforeNumbering = 24;
|
||||
|
||||
private static readonly string[] Kinds = ["Школа", "Гимназия", "Лицей", "Школа-интернат"];
|
||||
|
||||
private static readonly string[] Epithets =
|
||||
[
|
||||
"Северная", "Приморская", "Заречная", "Нагорная", "Слободская", "Озёрная",
|
||||
"Кленовая", "Рябиновая", "Солнечная", "Луговая", "Тихая", "Ясная",
|
||||
];
|
||||
|
||||
private readonly Random _random = random ?? Random.Shared;
|
||||
|
||||
/// <summary>
|
||||
/// A name that is not in <paramref name="taken"/>. Falls back to a numbered name so the
|
||||
/// button always produces something, even when the pool is exhausted.
|
||||
/// </summary>
|
||||
public string Next(IEnumerable<string> taken)
|
||||
{
|
||||
var used = new HashSet<string>(taken, StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
for (var attempt = 0; attempt < AttemptsBeforeNumbering; attempt++)
|
||||
{
|
||||
var candidate = Compose();
|
||||
if (used.Add(candidate))
|
||||
{
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
|
||||
for (var number = 1; ; number++)
|
||||
{
|
||||
var candidate = $"Школа №{number}";
|
||||
if (!used.Contains(candidate))
|
||||
{
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string Compose()
|
||||
{
|
||||
var kind = Kinds[_random.Next(Kinds.Length)];
|
||||
|
||||
// Half the names are numbered, half are named — both read like a real school.
|
||||
return _random.Next(2) == 0
|
||||
? $"{kind} №{_random.Next(1, 100)}"
|
||||
: $"{kind} «{Epithets[_random.Next(Epithets.Length)]}»";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user