Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Advice for turn based game, web and mobile


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 nickwinters   Members   -  Reputation: 183

Like
0Likes
Like

Posted 03 April 2011 - 01:16 AM

I'm attempting to build a turn based game that can be played on both WP7 and from a website (Silverlight), and am having thinking of ways to architect the server. The game will be played over several weeks, and each player will have a day or two to do their turn, which could take as little as a few seconds, to several minutes depending on the player.

Initially, I was considering creating a web service for the client to call. The difficulty with this is that there's no way to notify players when something has happened, so clients would have to poll regularly, possibly every few minutes. Because of this, I'm considering creating a server that communicates with the clients using TCP. My concern is for mobile devices. If I switched to sockets, how would it fare? I assume mobile device connections drop often due to inconsistent reception.

Is there a better way to do this?

Thanks.

-Nick

Sponsor:

#2 typedef struct   Members   -  Reputation: 234

Like
0Likes
Like

Posted 03 April 2011 - 05:13 AM

TCP will handle this for you. Any connection issues will manifest as high latency, which won't really affect you since you're turn-based.

However, Silverlight only runs on Windows Phone, so that will limit you to like 5 people.
Anthony Umfer

#3 hplus0603   Moderators   -  Reputation: 6665

Like
1Likes
Like

Posted 03 April 2011 - 01:47 PM

TCP will handle this for you. Any connection issues will manifest as high latency, which won't really affect you since you're turn-based.


Not really. TCP can't deal with events like changing the IP address of the host, which I believe will happen when your phone goes out of coverage and comes back into coverage (or gets turned off, or whatever).
Also, your particular game may very well be killed by the phone because it's low priority, when the game is in the background and the user is using the phone for other things (surfing youtube or whatever).
Thus, I suggest you poll the service. If the game play speed is "days" then I suggest you poll maybe once an hour by default, and have a user option to poll manually if needed. The Twitter API, which probably has a lot more immediacy than a game where a turn is a day, is still based around polling.

I suggest that you keep a queue of events that the user needs to see. These can be numbered. When the user polls, you simply check whether there are any events with an id higher than what the user last saw -- which can be provided by the client. If you use Redis to keep state, or if you use a primary key of (userid, eventid), then the query will be fairly efficient. The code on the client is super simple, too:

1) find the highest event id seen since last poll
2) query https://mygame.com/events?last=<last-event-id> using HTTP Basic authorization for username/password (convenient, and safe over HTTPS)
3) for each event returned, deal with it, and save it as the highest seen event id
enum Bool { True, False, FileNotFound };




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS