mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2026-01-05 01:27:42 -08:00
Add Scoreboard abstraction
This commit is contained in:
28
07_Basketball/csharp/IReadWriteExtensions.cs
Normal file
28
07_Basketball/csharp/IReadWriteExtensions.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using Games.Common.IO;
|
||||
|
||||
namespace Basketball;
|
||||
|
||||
internal static class IReadWriteExtensions
|
||||
{
|
||||
public static float ReadDefense(this IReadWrite io, string prompt)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
var defense = io.ReadNumber(prompt);
|
||||
if (defense >= 6) { return defense; }
|
||||
}
|
||||
}
|
||||
|
||||
public static int ReadShot(this IReadWrite io, string prompt)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
var shot = io.ReadNumber(prompt);
|
||||
if ((int)shot == shot && shot >= 0 && shot <= 4) { return (int)shot; }
|
||||
io.Write("Incorrect answer. Retype it. ");
|
||||
}
|
||||
}
|
||||
|
||||
public static void WriteScore(this IReadWrite io, string format, string opponent, Dictionary<string ,int> score) =>
|
||||
io.WriteLine(format, "Dartmouth", score["Dartmouth"], opponent, score[opponent]);
|
||||
}
|
||||
Reference in New Issue
Block a user