This question starts with the same words of a bunch of others... "I'm trying to do a card game in c#", i've seen a lot of similar questions, but no one is actually solving my problem.
I'll introduce my problem with a little scenario:
Player A plays card X with target B
Player B needs to choose a countercard Y or pass
Player B view contains his cards and each card is represented by a picturebox.
To continue the game i need the controller of player B to await until he clicks on card of type Y, or to pass the turn.
To me, the easiest way to do something like this is faking await using booleans. It's easy to record which was the last card played (E.g X) and then wait until the card.Click event is triggered on a card of type Y or if the pass button is pressed.
The problem with that is that it requires the use of a large number of boolean variables and if/else to handle those "events".
What would be a better implementation of something like this?
Edit.
GameController.cs
public void XCardPlayed(string target)
{
if (this.players[0].Username.Equals(target))
{
// I'm the target
lastCardPlayed = "X";
PlayYCard();
}
else
{
// display the card on the table
}
}
public void PlayYCard()
{
gameView.NotifyPlayYCard();
}
GameForm.cs
public void PlayCardFromHand(int index)
{
if (playY)
{
// Check if card at index is instance of Y
}
}
public void NotifyPlayYCard()
{
playY = true;
}
public void CardClick(object sender, EventArgs e)
{
PictureBox current = (PictureBox)sender;
PlayCardFromHand(pnl_cards.Controls.IndexOf(current));
}