Skip to content

Commit

Permalink
Fix: typing an invalid number in battle would result in no input
Browse files Browse the repository at this point in the history
Game now correctly tells you, that was an invalid input.
  • Loading branch information
nightblade9 committed Dec 15, 2024
1 parent 6de8021 commit 9253a73
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions source/TextBlade.Core/Battle/CharacterTurnProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,10 @@ private static T PickFromList<T>(IEnumerable<T> items)
Console.WriteLine($" {i + 1}: {item}");
}

var target = 0;
while (target == 0 || target > items.Count())
int target;
while (!int.TryParse(Console.ReadKey().KeyChar.ToString().Trim(), out target) || target == 0 || target > items.Count())
{
if (!int.TryParse(Console.ReadKey().KeyChar.ToString().Trim(), out target))
{
Console.WriteLine($"That's not a valid number! Enter a number from 1 to {items.Count()}: ");
}
Console.WriteLine($"That's not a valid number! Enter a number from 1 to {items.Count()}: ");
}

return items.ElementAt(target - 1);
Expand Down

0 comments on commit 9253a73

Please sign in to comment.