Advertisement

How to design animations and turn timers in the client/server architecture of a turn based game?

Started by August 10, 2018 07:13 PM
2 comments, last by hplus0603 6 years, 3 months ago

So I am making a poker game as a mobile app. Naturally, the project is turned based and designed around a client/server architecture.

To summarize, I have created a game server that receives inputs from the player to act, validates the input, processes the new game state, and sends out the current state of the game to all clients. The clients are currently just a graphical representation of the state of the game.

My problem is that I have to design and run animations "in between these game states". So for example, after a betting round completes I have to play the animation of dealing a card and moving the chips to the center.

So all though these animations are just a transition and really have nothing to do with the state of the game, how do I implement them in the client/server system in a way that helps keep clients synced? Also, when it's a players turn to act, is it worth it to implement some kind of ready check from the client to start his turn?

So again my main questions are: 

  • Should the server tell the clients to initiate the animations and wait for a response from all the clients that they have finished their animation?
  • Similarly, should the server wait for a response from the client that they are ready to start their turn?
  • How do I account for minor disconnections during those periods? (i.e. client fails to signal the server that he is ready to start his turn, so the server never receives that signal and the player is on the clock so his turn must expire eventually)

My gut tells me that the server should be decoupled from details of animating the game state, but maybe a bit of syncing is required, either way I am not sure how to go about it.

Why sync animations?  You get the new card(s) data from the server, animate.  You get the chip info of what is going into the pot, animate.  No one cares if they're 2 seconds delayed as there is no advantage possible in a turn based game.  The game can signal it's done animating if you care, but honestly just have a timeout count down running on the server.

"Those who would give up essential liberty to purchase a little temporary safety deserve neither liberty nor safety." --Benjamin Franklin

Advertisement

Is the problem that you get a full state of the game, then time passes, then you get another full state of the game?

If so, you have to write code to detect what changed between these states. If some player has more cards, animate cards to that player. If some player has less chips, animate those chips going away. And, so forth.

If you want to make it a little simpler on yourself, you'd include the command that led to the new state, in the state update you receive. Thus, "player 3 raises by 50; new state is ..." would tell the game to animate 50 chips from player 3 to pot, and separately it knows what the pot is.

Btw, just because it's turn-based, doesn't mean that you can't use real-time networking, or at least real-time-ish networking, to send the events to the players as soon as they happen. Exactly how you do this is up to you, as there are many variables (networking consumption, battery consumption, server capabilities, protocols used, and so forth.)

enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement