mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2026-01-17 15:32:18 -08:00
Create program structure
This commit is contained in:
18
77_Salvo/csharp/Game.cs
Normal file
18
77_Salvo/csharp/Game.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
6
77_Salvo/csharp/Program.cs
Normal file
6
77_Salvo/csharp/Program.cs
Normal 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();
|
||||
29
77_Salvo/csharp/Resources/Resource.cs
Normal file
29
77_Salvo/csharp/Resources/Resource.cs
Normal 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}'.");
|
||||
}
|
||||
5
77_Salvo/csharp/Resources/Title.txt
Normal file
5
77_Salvo/csharp/Resources/Title.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
Salvo
|
||||
Creative Computing Morristown, New Jersey
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user