mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-22 23:26:40 -08:00
Add some comments and game loop
This commit is contained in:
@@ -11,25 +11,28 @@ internal class Game
|
|||||||
_io = io;
|
_io = io;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Play()
|
public void Play(Func<bool> playAgain)
|
||||||
{
|
{
|
||||||
_io.Write(Streams.Title);
|
_io.Write(Streams.Title);
|
||||||
_io.Write(Streams.Instructions);
|
_io.Write(Streams.Instructions);
|
||||||
|
|
||||||
var timeIncrement = _io.ReadParameter("Time increment (sec)");
|
while (playAgain.Invoke())
|
||||||
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))
|
|
||||||
{
|
{
|
||||||
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,4 +3,4 @@ global using Games.Common.Numbers;
|
|||||||
|
|
||||||
using Bounce;
|
using Bounce;
|
||||||
|
|
||||||
new Game(new ConsoleIO()).Play();
|
new Game(new ConsoleIO()).Play(() => true);
|
||||||
Reference in New Issue
Block a user