Create program structure

This commit is contained in:
drewjcooper
2023-02-19 19:58:24 +11:00
parent 846be86481
commit e6425221bf
4 changed files with 58 additions and 0 deletions

18
77_Salvo/csharp/Game.cs Normal file
View File

@@ -0,0 +1,18 @@
namespace Salvo;
internal class Game
{
private readonly IReadWrite _io;
private readonly IRandom _random;
public Game(IReadWrite io, IRandom random)
{
_io = io;
_random = random;
}
internal void Play()
{
_io.Write(Streams.Title);
}
}

View File

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

View File

@@ -0,0 +1,29 @@
using System.Reflection;
using System.Runtime.CompilerServices;
namespace Salvo.Resources;
internal static class Resource
{
internal static class Streams
{
public static Stream Title => GetStream();
}
internal static class Prompts
{
}
private static string GetPrompt([CallerMemberName] string? name = null) => GetString($"{name}Prompt");
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 @@
Salvo
Creative Computing Morristown, New Jersey