mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-29 06:05:36 -08:00
Spaces tend to cause annoyances in a Unix-style shell environment. This change fixes that.
66 lines
1.8 KiB
C#
66 lines
1.8 KiB
C#
namespace SuperStarTrek.Space
|
|
{
|
|
internal class QuadrantInfo
|
|
{
|
|
private bool _isKnown;
|
|
|
|
private QuadrantInfo(Coordinates coordinates, string name, int klingonCount, int starCount, bool hasStarbase)
|
|
{
|
|
Coordinates = coordinates;
|
|
Name = name;
|
|
KlingonCount = klingonCount;
|
|
StarCount = starCount;
|
|
HasStarbase = hasStarbase;
|
|
}
|
|
|
|
internal Coordinates Coordinates { get; }
|
|
|
|
internal string Name { get; }
|
|
|
|
internal int KlingonCount { get; private set; }
|
|
|
|
internal bool HasStarbase { get; private set; }
|
|
|
|
internal int StarCount { get; }
|
|
|
|
internal static QuadrantInfo Create(Coordinates coordinates, string name, Random random)
|
|
{
|
|
var klingonCount = random.GetFloat() switch
|
|
{
|
|
> 0.98f => 3,
|
|
> 0.95f => 2,
|
|
> 0.80f => 1,
|
|
_ => 0
|
|
};
|
|
var hasStarbase = random.GetFloat() > 0.96f;
|
|
var starCount = random.Get1To8Inclusive();
|
|
|
|
return new QuadrantInfo(coordinates, name, klingonCount, starCount, hasStarbase);
|
|
}
|
|
|
|
internal void AddKlingon() => KlingonCount += 1;
|
|
|
|
internal void AddStarbase() => HasStarbase = true;
|
|
|
|
internal void MarkAsKnown() => _isKnown = true;
|
|
|
|
internal string Scan()
|
|
{
|
|
_isKnown = true;
|
|
return ToString();
|
|
}
|
|
|
|
public override string ToString() => _isKnown ? $"{KlingonCount}{(HasStarbase ? 1 : 0)}{StarCount}" : "***";
|
|
|
|
internal void RemoveKlingon()
|
|
{
|
|
if (KlingonCount > 0)
|
|
{
|
|
KlingonCount -= 1;
|
|
}
|
|
}
|
|
|
|
internal void RemoveStarbase() => HasStarbase = false;
|
|
}
|
|
}
|