ex-col-02-bucket-chain/BucketChain/Program.cs
github-classroom[bot] 593d8ebfea
Initial commit
2024-11-17 08:52:38 +00:00

92 lines
No EOL
1.8 KiB
C#

using System.Text;
using BucketChain;
Console.OutputEncoding = Encoding.UTF8;
Console.WriteLine("*** BucketChain ***");
const int MaxSteps = 100;
var stepCount = 0;
var well = new Well(20D, 0.5D);
var fire = new Fire(5D, 0.25D);
var people = new Person[9];
for (var i = 0; i < people.Length; i++)
{
people[i] = new Person();
}
var chain = new Chain(8, 6, 1.25D, well, fire, people[0]);
while (stepCount < MaxSteps)
{
stepCount++;
switch (stepCount)
{
case 1:
{
// 01
people[1].JoinChain(people[0], true);
}
break;
case 2:
{
// 021
people[2].JoinChain(people[1], false);
}
break;
case 3:
{
// 3021
people[3].JoinChain(people[0], false);
}
break;
case 5:
{
// 30214
people[4].JoinChain(people[1], true);
}
break;
case 9:
{
// 302145678
var left = 4;
for (var i = 5; i < people.Length; i++)
{
people[i].JoinChain(people[left++], true);
}
}
break;
}
if (chain.Operate(stepCount, out var error))
{
PrintChain();
break;
}
if (error)
{
Console.WriteLine("Error moving bucket");
break;
}
PrintChain();
await Task.Delay(TimeSpan.FromSeconds(1));
continue;
void PrintChain()
{
Console.Clear();
Console.WriteLine($"#{stepCount:000}: {chain}");
}
}
Console.WriteLine(fire.Extinguished ? "Fire extinguished 🥳" : "Fire destroyed the city 🥵");
Console.WriteLine($"{Environment.NewLine}Press any key to exit...");
Console.ReadKey();