From 6927c5ad1448b25c427005cd6d4497e5e4d1f1e0 Mon Sep 17 00:00:00 2001 From: Andrew Cooper Date: Fri, 15 Apr 2022 22:48:59 +1000 Subject: [PATCH] Add game logic --- 25_Chief/csharp/Chief.csproj | 4 +++ 25_Chief/csharp/Game.cs | 41 ++++++++++++++++++++++++- 25_Chief/csharp/IReadWriteExtensions.cs | 0 25_Chief/csharp/Resources/Resource.cs | 2 +- 4 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 25_Chief/csharp/IReadWriteExtensions.cs diff --git a/25_Chief/csharp/Chief.csproj b/25_Chief/csharp/Chief.csproj index 2e7a4432..3870320c 100644 --- a/25_Chief/csharp/Chief.csproj +++ b/25_Chief/csharp/Chief.csproj @@ -7,6 +7,10 @@ enable + + + + diff --git a/25_Chief/csharp/Game.cs b/25_Chief/csharp/Game.cs index 29f3fec6..95839cb5 100644 --- a/25_Chief/csharp/Game.cs +++ b/25_Chief/csharp/Game.cs @@ -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); } -} \ No newline at end of file + + private static IEnumerable 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; + } +} diff --git a/25_Chief/csharp/IReadWriteExtensions.cs b/25_Chief/csharp/IReadWriteExtensions.cs new file mode 100644 index 00000000..e69de29b diff --git a/25_Chief/csharp/Resources/Resource.cs b/25_Chief/csharp/Resources/Resource.cs index 637a4983..4255d6c6 100644 --- a/25_Chief/csharp/Resources/Resource.cs +++ b/25_Chief/csharp/Resources/Resource.cs @@ -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)); } \ No newline at end of file