mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-22 07:10:42 -08:00
Add game logic
This commit is contained in:
@@ -7,6 +7,10 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Resources/*.txt" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\00_Common\dotnet\Games.Common\Games.Common.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
using Chief.Resources;
|
||||
using static Chief.Resources.Resource;
|
||||
|
||||
namespace Chief;
|
||||
|
||||
internal class Game
|
||||
@@ -11,6 +14,42 @@ internal class Game
|
||||
|
||||
internal void Play()
|
||||
{
|
||||
_io.Write(Streams.Title);
|
||||
if (!_io.ReadYes(Prompts.Ready))
|
||||
{
|
||||
_io.Write(Streams.ShutUp);
|
||||
}
|
||||
|
||||
_io.Write(Streams.Instructions);
|
||||
|
||||
var result = _io.ReadNumber(Prompts.Answer);
|
||||
|
||||
if (_io.ReadYes(Formats.Bet, (result + 1 - 5) * 5 / 8 * 5 - 3))
|
||||
{
|
||||
_io.Write(Streams.Bye);
|
||||
return;
|
||||
}
|
||||
|
||||
var original = _io.ReadNumber(Prompts.Original);
|
||||
|
||||
_io.WriteLine(Formats.Working, GetStepValues(original).ToArray());
|
||||
|
||||
if (_io.ReadYes(Prompts.Believe))
|
||||
{
|
||||
_io.Write(Streams.Bye);
|
||||
return;
|
||||
}
|
||||
|
||||
_io.Write(Streams.Lightning);
|
||||
}
|
||||
}
|
||||
|
||||
private static IEnumerable<object> GetStepValues(float value)
|
||||
{
|
||||
yield return value;
|
||||
yield return value += 3;
|
||||
yield return value /= 5;
|
||||
yield return value *= 8;
|
||||
yield return value = value / 5 + 5;
|
||||
yield return value - 1;
|
||||
}
|
||||
}
|
||||
|
||||
0
25_Chief/csharp/IReadWriteExtensions.cs
Normal file
0
25_Chief/csharp/IReadWriteExtensions.cs
Normal file
@@ -36,6 +36,6 @@ internal static class Resource
|
||||
}
|
||||
|
||||
private static Stream GetStream([CallerMemberName] string? name = null)
|
||||
=> Assembly.GetExecutingAssembly().GetManifestResourceStream($"Stars.Resources.{name}.txt")
|
||||
=> Assembly.GetExecutingAssembly().GetManifestResourceStream($"Chief.Resources.{name}.txt")
|
||||
?? throw new ArgumentException($"Resource stream {name} does not exist", nameof(name));
|
||||
}
|
||||
Reference in New Issue
Block a user