mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-22 15:16:33 -08:00
Add player input routines
This commit is contained in:
26
53_King/csharp/ValidityTest.cs
Normal file
26
53_King/csharp/ValidityTest.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
namespace King;
|
||||
|
||||
internal class ValidityTest
|
||||
{
|
||||
private readonly Predicate<float> _isValid;
|
||||
private readonly Func<string> _getError;
|
||||
|
||||
public ValidityTest(Predicate<float> isValid, string error)
|
||||
: this(isValid, () => error)
|
||||
{
|
||||
}
|
||||
|
||||
public ValidityTest(Predicate<float> isValid, Func<string> getError)
|
||||
{
|
||||
_isValid = isValid;
|
||||
_getError = getError;
|
||||
}
|
||||
|
||||
public bool IsValid(float value, IReadWrite io)
|
||||
{
|
||||
if (_isValid(value)) { return true; }
|
||||
|
||||
io.Write(_getError());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user