Fix game loop and finished message

This commit is contained in:
Andrew Cooper
2022-07-14 00:39:17 +10:00
parent 98344717f7
commit 6e47d7fbfd
3 changed files with 12 additions and 7 deletions

View File

@@ -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))
{

View File

@@ -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(' ');

View File

@@ -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));
}