mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-29 14:15:08 -08:00
Add quadrant names
This commit is contained in:
8
84 Super Star Trek/csharp/Resources/RegionNames.txt
Normal file
8
84 Super Star Trek/csharp/Resources/RegionNames.txt
Normal file
@@ -0,0 +1,8 @@
|
||||
Antares Sirius
|
||||
Rigel Deneb
|
||||
Procyon Capella
|
||||
Vega Betelgeuse
|
||||
Canopus Aldebaran
|
||||
Altair Regulus
|
||||
Sagittarius Arcturus
|
||||
Pollux Spica
|
||||
@@ -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();
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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]}";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user