mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-23 15:37:51 -08:00
Add string resources
This commit is contained in:
@@ -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>
|
||||
|
||||
1
41_Guess/csharp/Resources/Good.txt
Normal file
1
41_Guess/csharp/Resources/Good.txt
Normal file
@@ -0,0 +1 @@
|
||||
Good.
|
||||
9
41_Guess/csharp/Resources/Introduction.txt
Normal file
9
41_Guess/csharp/Resources/Introduction.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
Guezs
|
||||
Creative Computing Morristown, New Jersey
|
||||
|
||||
|
||||
|
||||
This is a number guessing game. I'll think
|
||||
of a number between 1 and any limit you want.
|
||||
The you have to guess what it is.
|
||||
|
||||
1
41_Guess/csharp/Resources/Limit.txt
Normal file
1
41_Guess/csharp/Resources/Limit.txt
Normal file
@@ -0,0 +1 @@
|
||||
What limit do you want
|
||||
39
41_Guess/csharp/Resources/Resource.cs
Normal file
39
41_Guess/csharp/Resources/Resource.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Guess.Resources;
|
||||
|
||||
internal static class Resource
|
||||
{
|
||||
internal static class Streams
|
||||
{
|
||||
public static Stream Introduction => GetStream();
|
||||
public static Stream TooLow => GetStream();
|
||||
public static Stream TooHigh => GetStream();
|
||||
public static Stream Good => GetStream();
|
||||
public static Stream VeryGood => GetStream();
|
||||
}
|
||||
|
||||
internal static class Formats
|
||||
{
|
||||
public static string Thinking => GetString();
|
||||
public static string ThatsIt => GetString();
|
||||
public static string ShouldHave => GetString();
|
||||
}
|
||||
|
||||
internal static class Prompts
|
||||
{
|
||||
public static string Limit => 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}'.");
|
||||
}
|
||||
1
41_Guess/csharp/Resources/ShouldHave.txt
Normal file
1
41_Guess/csharp/Resources/ShouldHave.txt
Normal file
@@ -0,0 +1 @@
|
||||
You should have been able to get it in only {0}
|
||||
1
41_Guess/csharp/Resources/ThatsIt.txt
Normal file
1
41_Guess/csharp/Resources/ThatsIt.txt
Normal file
@@ -0,0 +1 @@
|
||||
That's it! You got it in {0} tries.
|
||||
2
41_Guess/csharp/Resources/Thinking.txt
Normal file
2
41_Guess/csharp/Resources/Thinking.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
I'm thinking of a number between 1 and {0}
|
||||
Now you try to guess what it is.
|
||||
1
41_Guess/csharp/Resources/TooHigh.txt
Normal file
1
41_Guess/csharp/Resources/TooHigh.txt
Normal file
@@ -0,0 +1 @@
|
||||
Too high. Try a smaller answer.
|
||||
1
41_Guess/csharp/Resources/TooLow.txt
Normal file
1
41_Guess/csharp/Resources/TooLow.txt
Normal file
@@ -0,0 +1 @@
|
||||
Too low. Try a bigger answer.
|
||||
1
41_Guess/csharp/Resources/VeryGood.txt
Normal file
1
41_Guess/csharp/Resources/VeryGood.txt
Normal file
@@ -0,0 +1 @@
|
||||
Very good.
|
||||
Reference in New Issue
Block a user