diff --git a/84 Super Star Trek/csharp/Resources/RegionNames.txt b/84 Super Star Trek/csharp/Resources/RegionNames.txt new file mode 100644 index 00000000..e2f47d79 --- /dev/null +++ b/84 Super Star Trek/csharp/Resources/RegionNames.txt @@ -0,0 +1,8 @@ +Antares Sirius +Rigel Deneb +Procyon Capella +Vega Betelgeuse +Canopus Aldebaran +Altair Regulus +Sagittarius Arcturus +Pollux Spica \ No newline at end of file diff --git a/84 Super Star Trek/csharp/Resources/Strings.cs b/84 Super Star Trek/csharp/Resources/Strings.cs index 4592db31..210d22ba 100644 --- a/84 Super Star Trek/csharp/Resources/Strings.cs +++ b/84 Super Star Trek/csharp/Resources/Strings.cs @@ -14,6 +14,7 @@ namespace SuperStarTrek.Resources public static string Instructions => GetResource(); public static string LowShields => GetResource(); public static string Orders => GetResource(); + public static string RegionNames => GetResource(); public static string RepairEstimate => GetResource(); public static string RepairPrompt => GetResource(); public static string ReplayPrompt => GetResource(); diff --git a/84 Super Star Trek/csharp/Space/Coordinate.cs b/84 Super Star Trek/csharp/Space/Coordinate.cs index b3328c24..87fe6e89 100644 --- a/84 Super Star Trek/csharp/Space/Coordinate.cs +++ b/84 Super Star Trek/csharp/Space/Coordinate.cs @@ -14,6 +14,8 @@ namespace SuperStarTrek.Space public int X { get; } public int Y { get; } + public int RegionIndex => ((X - 1) << 1) + ((Y - 1) >> 2); + public int SubRegionIndex => (Y - 1) % 4; private int Validated(int value, string argumentName) { diff --git a/84 Super Star Trek/csharp/Space/Galaxy.cs b/84 Super Star Trek/csharp/Space/Galaxy.cs index 171ecdea..88361645 100644 --- a/84 Super Star Trek/csharp/Space/Galaxy.cs +++ b/84 Super Star Trek/csharp/Space/Galaxy.cs @@ -1,17 +1,33 @@ using System.Linq; +using SuperStarTrek.Resources; + +using static System.StringSplitOptions; namespace SuperStarTrek.Space { internal class Galaxy { + private static readonly string[] _regionNames; + private static readonly string[] _subRegionIdentifiers; private readonly QuadrantInfo[][] _quadrants; + static Galaxy() + { + _regionNames = Strings.RegionNames.Split(new[] { ' ', '\n' }, RemoveEmptyEntries | TrimEntries); + _subRegionIdentifiers = new[] { "I", "II", "III", "IV" }; + } + public Galaxy() { var random = new Random(); - _quadrants = Enumerable.Range(1, 8).Select(x => - Enumerable.Range(1, 8).Select(y => QuadrantInfo.Create(new Coordinates(x, y), "")).ToArray()) + _quadrants = Enumerable + .Range(1, 8) + .Select(x => Enumerable + .Range(1, 8) + .Select(y => new Coordinates(x, y)) + .Select(c => QuadrantInfo.Create(c, GetQuadrantName(c))) + .ToArray()) .ToArray(); if (StarbaseCount == 0) @@ -30,5 +46,8 @@ namespace SuperStarTrek.Space public int KlingonCount => _quadrants.SelectMany(q => q).Sum(q => q.KlingonCount); public int StarbaseCount => _quadrants.SelectMany(q => q).Count(q => q.HasStarbase); + + private static string GetQuadrantName(Coordinates coordinates) => + $"{_regionNames[coordinates.RegionIndex]} {_subRegionIdentifiers[coordinates.SubRegionIndex]}"; } }