From 6e47d7fbfd8a9a9a8e755fa7533c38744d906b10 Mon Sep 17 00:00:00 2001 From: Andrew Cooper Date: Thu, 14 Jul 2022 00:39:17 +1000 Subject: [PATCH] Fix game loop and finished message --- 16_Bug/csharp/Game.cs | 11 ++++++++--- 16_Bug/csharp/Parts/PartCollection.cs | 4 ++-- 16_Bug/csharp/Resources/Message.cs | 4 ++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/16_Bug/csharp/Game.cs b/16_Bug/csharp/Game.cs index 2b5c0711..8ea1cecf 100644 --- a/16_Bug/csharp/Game.cs +++ b/16_Bug/csharp/Game.cs @@ -36,10 +36,15 @@ internal class Game while (true) { - if (TryBuild(yourBug, m => m.You) || TryBuild(myBug, m => m.I)) + var partAdded = TryBuild(yourBug, m => m.You); + Thread.Sleep(500); + _io.WriteLine(); + partAdded |= TryBuild(myBug, m => m.I); + + if (partAdded) { - if (yourBug.IsComplete) { _io.WriteLine(Message.Complete.You); } - if (myBug.IsComplete) { _io.WriteLine(Message.Complete.I); } + if (yourBug.IsComplete) { _io.WriteLine("Your bug is finished."); } + if (myBug.IsComplete) { _io.WriteLine("My bug is finished."); } if (!_io.ReadString("Do you want the picture").Equals("no", InvariantCultureIgnoreCase)) { diff --git a/16_Bug/csharp/Parts/PartCollection.cs b/16_Bug/csharp/Parts/PartCollection.cs index 6e6034de..9a0fd2ee 100644 --- a/16_Bug/csharp/Parts/PartCollection.cs +++ b/16_Bug/csharp/Parts/PartCollection.cs @@ -36,10 +36,10 @@ internal class PartCollection { if (_count == 0) { return; } - builder.Append(' ', offset); - for (var i = 0; i < length; i++) { + builder.Append(' ', offset); + for (var j = 0; j < _count; j++) { builder.Append(character).Append(' '); diff --git a/16_Bug/csharp/Resources/Message.cs b/16_Bug/csharp/Resources/Message.cs index 4c719475..20a59d9a 100644 --- a/16_Bug/csharp/Resources/Message.cs +++ b/16_Bug/csharp/Resources/Message.cs @@ -27,7 +27,7 @@ internal class Message public static Message Complete = new("bug is finished."); private Message(string common) - : this("I " + common, "You" + common) + : this("I " + common, "You " + common) { } @@ -40,7 +40,7 @@ internal class Message public string I { get; } public string You { get; } - public static Message DoNotHaveA(Part part) => new($"do no have a {part.Name}"); + public static Message DoNotHaveA(Part part) => new($"do not have a {part.Name}"); public Message ForValue(int quantity) => new(string.Format(I, quantity), string.Format(You, quantity)); } \ No newline at end of file