Add some comments and game loop

This commit is contained in:
Andrew Cooper
2022-04-17 19:47:22 +10:00
parent c9cd477022
commit ab48a16f7f
2 changed files with 18 additions and 15 deletions

View File

@@ -11,25 +11,28 @@ internal class Game
_io = io;
}
public void Play()
public void Play(Func<bool> playAgain)
{
_io.Write(Streams.Title);
_io.Write(Streams.Instructions);
var timeIncrement = _io.ReadParameter("Time increment (sec)");
var velocity = _io.ReadParameter("Velocity (fps)");
var elasticity = _io.ReadParameter("Coefficient");
var bounce = new Bounce(velocity);
var bounceCount = (int)(Graph.Row.Width * timeIncrement / bounce.Duration);
var graph = new Graph(bounce.MaxHeight, timeIncrement);
var time = 0f;
for (var i = 0; i < bounceCount; i++, bounce = bounce.Next(elasticity))
while (playAgain.Invoke())
{
time = bounce.Plot(graph, time);
}
var timeIncrement = _io.ReadParameter("Time increment (sec)");
var velocity = _io.ReadParameter("Velocity (fps)");
var elasticity = _io.ReadParameter("Coefficient");
_io.WriteLine(graph);
var bounce = new Bounce(velocity);
var bounceCount = (int)(Graph.Row.Width * timeIncrement / bounce.Duration);
var graph = new Graph(bounce.MaxHeight, timeIncrement);
var time = 0f;
for (var i = 0; i < bounceCount; i++, bounce = bounce.Next(elasticity))
{
time = bounce.Plot(graph, time);
}
_io.WriteLine(graph);
}
}
}

View File

@@ -3,4 +3,4 @@ global using Games.Common.Numbers;
using Bounce;
new Game(new ConsoleIO()).Play();
new Game(new ConsoleIO()).Play(() => true);