0
\$\begingroup\$

So I am developing a poker card game using JS +node.js + socket.io.

It is turn-based game. There will be a host and 4 other players.The flow is the players need to make a yes/no choice, then the host need to make a yes/no choice upon players' move, then players will need to make another yes/no choice, then the server will determine who wins.

Put simply,

1:Host set up the hand ----->2: inform all players----> 3:A player make a move(ticking yes or no) --> 4:this move will show up on the host's screen--->5:the host need to make his/her move(ticking yes or no)--->6: the host's move show up on players' screen, they make another yes/no choice----> 7:the server determine who wins.

The issue lies on step 5.

There will be multiple moves waiting for the host to process. Now the current design is all moves are shown by the form of a custom confirm box. It has yes/no button. It works perfect when there is only one host and one player. But when there is more than 2 players, there is a serious clashing problem.

If player A makes a move, it shows on the host's screen, and before the host ticking anything, player B makes a move and then player B's move (confirm box) will replace player A 's confirm box. In this case the host will not be able to process player A's move and the game cannot finalise.

How to get this clashing issue sorted? I hope I am not making this issue sound too complicated but I have been scratching my head.

\$\endgroup\$
0
\$\begingroup\$

Have a queue of decisions to make which is processes first-in-first-out. You can easily implement it as an array in JavaScript.

When an event happens which requires a decision and the decision window is already open, that new decision is pushed to the end of the decision queue.

When the player made the decision, the current decision window is closed. You check if there are elements in the decision queue, and if there is you remove the oldest decision from the queue and reopen the window with that decision.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.