Add quadrant names

This commit is contained in:
Andrew Cooper
2021-03-03 09:21:40 +11:00
parent fb88b706fd
commit cbcfebfeb3
4 changed files with 32 additions and 2 deletions

View File

@@ -0,0 +1,8 @@
Antares Sirius
Rigel Deneb
Procyon Capella
Vega Betelgeuse
Canopus Aldebaran
Altair Regulus
Sagittarius Arcturus
Pollux Spica

View File

@@ -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();

View File

@@ -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)
{

View File

@@ -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]}";
}
}