Page 1 of 1

Making the result of a trick obvious (with a delay?)

Posted: 04 June 2020, 17:07
by Bids
Hi all!
I would like to get some advice on this: In Bids there is a special card that means that players are not knowing for how many points they are bidding in that turn. This is called the "surprise" card. In the real game this happens when the surprise card is laying on top of the black card pile. When every player has placed his bid for that turn, the next black card is turned around, and that's the card that the player will win.
I was thinking to implement this as follows:

Code: Select all

function stSurpriseCard() {
    	$nextBlack = $this->cards->getCardOnTop('blackontop');
        self::notifyAllPlayers( 'newTrick', clienttranslate('new trick'),array( 'nextBlack' => $nextBlack ));
        sleep(3);
	$this->gamestate->nextState("");	
    }
    
So when the trick is finished, normally the nextState will be "newTrick", but if the special card was laying on top, the next state will be "surpriseCard" which activates this function. The black card on top will be replaced with a new black card. After waiting 3 seconds, the next state will be activated, which will be "newTrick".
So a double question here: how do I use the "sleep" function correctly, because the code like this is not working. Or is there another way of implementing this logic, such that it is obvious for the players what the winner of that trick will win?
Many thanks in advance!

Re: Making the result of a trick obvious (with a delay?)

Posted: 04 June 2020, 18:26
by hersh
you don't need the server to sleep. you can still send the move to the client and delay the reveal or transition back to 'newTrick' on the client.

depending on situation maybe use of setTimeout() or synchronous notifications

Re: Making the result of a trick obvious (with a delay?)

Posted: 04 June 2020, 19:12
by Bids
Thanks a lot! This was exactly what I was looking for.