In C# I want to go over a series of template-objects and want the user to select a coordinate in a grid. Now I have an enumerator and I'm moving to the next object in the ClickEventHandler. But as it is more easily readable I think I wanna try it with async/await. (My project is getting pretty big and I need something well strucutured). So currently I have something like this:
public void OnPositionClicked(object sender, MouseEventArgs e)
{
process(((Selection) sender).point, templateEnumerator.Current);
templateEnumerator.MoveNext();
}
But I want to have something more human-readable like this
foreach (var template in templateEnumerator)
{
var position = await PositionGotClicked();
process(position, template);
}
How would I implement the async PositionGotClicked()
-Method/delegate that blocks a seperate thread until the user clicks something?
I hope it is clear what I'm asking, I don't really know a word for it.
Edit - Purpose: The Purpose of this is to create a game of sinking ships. In the selection-mode where you place all of you ships I want to go over the different types (submarines, cruisers, battelships ...) which differ in size. So I have created a class ShipType
that specifies how many ships there are of each type, how big each type is, it's color and name. Then I want for each ship-type to let the user select 'n' positions (depending on how many there are of each type) and afterwards go to the next ship, select a position for it and so on.