mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-23 15:37:51 -08:00
Implement stars game
This commit is contained in:
31
82 Stars/csharp/Stars/Input.cs
Normal file
31
82 Stars/csharp/Stars/Input.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
|
||||
namespace Stars
|
||||
{
|
||||
internal static class Input
|
||||
{
|
||||
// Float, because that's what the BASIC input operation returns
|
||||
internal static float GetNumber(string prompt)
|
||||
{
|
||||
Console.Write(prompt);
|
||||
|
||||
while (true)
|
||||
{
|
||||
var response = Console.ReadLine();
|
||||
if (float.TryParse(response, out var value))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
Console.WriteLine("!Number expected - retry input line");
|
||||
Console.Write("? ");
|
||||
}
|
||||
}
|
||||
|
||||
internal static string GetString(string prompt)
|
||||
{
|
||||
Console.Write(prompt);
|
||||
return Console.ReadLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user