CSHARP-53 Create program sturcture

This commit is contained in:
Andrew Cooper
2022-10-21 21:48:58 +11:00
parent 399a2a7e81
commit 9b471073b0
7 changed files with 110 additions and 0 deletions

28
53_King/csharp/Game.cs Normal file
View File

@@ -0,0 +1,28 @@
namespace King;
internal class Game
{
const int TermOfOffice = 8;
private readonly IReadWrite _io;
private readonly IRandom _random;
public Game(IReadWrite io, IRandom random)
{
_io = io;
_random = random;
}
public void Play()
{
_io.Write(Resource.Title);
var response = _io.ReadString(Resource.Instructions_Prompt).ToUpper();
if (!response.StartsWith('N'))
{
_io.Write(Resource.Instructions_Text(TermOfOffice));
}
_io.WriteLine();
}
}

View File

@@ -6,4 +6,12 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="Resources/*.txt" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\00_Common\dotnet\Games.Common\Games.Common.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,6 @@
global using Games.Common.IO;
global using Games.Common.Randomness;
global using King.Resources;
using King;
new Game(new ConsoleIO(), new RandomNumberGenerator()).Play();

View File

@@ -0,0 +1 @@
Do you want instructions

View File

@@ -0,0 +1,17 @@
Congratulations! You've just been elected Premier of Setats
Detinu, a small communist island 30 by 70 miles long. Your
job is to decide upon the country's budget and distribute
money to your countrymen from the communal treasury.
The money system is rallods, and each person needs 100
rallods per year to survive. Your country's income comes
from farm produce and tourists visiting your magnificent
forests, hunting, fishing, etc. Half your land if farm land
which also has an excellent mineral content and may be sold
to foreign industry (strip mining) who import and support
their own workers. Crops cost between 10 and 15 rallods per
square mile to plant.
Your goal is to complete your {0} year term of office.
Good luck!

View File

@@ -0,0 +1,45 @@
using System.Reflection;
using System.Runtime.CompilerServices;
namespace King.Resources;
internal static class Resource
{
public static Stream Title => GetStream();
public static string Instructions_Prompt => GetString();
public static string Instructions_Text(int years) => string.Format(GetString(), years);
internal static class Formats
{
public static string Player => GetString();
public static string YouLose => GetString();
}
internal static class Prompts
{
public static string WantInstructions => GetString();
public static string HowManyPlayers => GetString();
public static string HowManyRows => GetString();
public static string HowManyColumns => GetString();
public static string TooManyColumns => GetString();
}
internal static class Strings
{
public static string TooManyColumns => GetString();
public static string TooManyRows => GetString();
}
private static string GetString([CallerMemberName] string? name = null)
{
using var stream = GetStream(name);
using var reader = new StreamReader(stream);
return reader.ReadToEnd();
}
private static Stream GetStream([CallerMemberName] string? name = null) =>
Assembly.GetExecutingAssembly().GetManifestResourceStream($"{typeof(Resource).Namespace}.{name}.txt")
?? throw new Exception($"Could not find embedded resource stream '{name}'.");
}

View File

@@ -0,0 +1,5 @@
King
Creative Computing Morristown, New Jersey