Home > Enterprise >  Firebase for turn based game. Is cloud function can count remaining time of each turn?
Firebase for turn based game. Is cloud function can count remaining time of each turn?

Time:12-18

For a Hearthstone-like game(or chess game), how can I safely count a player's turn and opponent turn on server side?

A game has 30 seconds turn for each player and if a player finished his behavior before timer reaches to 30 seconds, it flips turn and count 30secs again from beginning.

I was thinking of Firebase cloud function pubsub. ->Activate a counting function when player turn is activated. But I think there is no way to check if a player ended his turn early(to cancel function). Because pubsub function would be implemented like a fire and forget.

CodePudding user response:

As I understand, you want to implement a turn-based game using Firebase cloud functions. To be able to stop the counting function if the player ends his turn early, you can do the following:

  1. Add a turn field to each game node.
  2. The counting function would have a local copy of the turn value when it started.
  3. If the counting function detects that the live value in the database changes, it stops.

CodePudding user response:

Hello anyone there? I'm trying to get in contact

  • Related