Search code examples
c#xamarin.iosmauiuitapgesturerecognizer

How do I add a pause after a tap gesture runs?


I am working on creating a single player game with a computer opponent and I would like to add a pause between when the human player and the computer takes their turns so it doesn´t feel so calculated.

I have tried put the thread to sleep in the MakeMove method and in the ComputerMove method and either way the player move from the MakeMove method isn't rendered visually until after the entire code from the tap gesture recognizer has run.

_tapGestureRecognizer.Tapped += async (s, e) =>
{
    var boardcell = (BoardCell)s;

    if (boardcell.GamePiece.Fill == null)
    {
        var isMoveValid = MakeMove(boardcell);

        if (!GameViewModel.Game.IsTwoPlayer && isMoveValid)
        {
            ComputerMove();
        }
    }
};

The only thought I have is to find some way to pull the ComputerMove out of the tap gesture recognizer and into its own method but I am not sure how to run the method after the other has run. Thoughts?


Solution

  • await Task.Delay(1000); will block the task (async method)