The most important thing about a tech-based game is this: it has to work.
It has to work totally, transparently, and absolutely. What would be a minor irritation in application software is immersion-breaking in games.
Turns out, this isn’t so easy. If you control the hardware, it gets easier, but I really don’t see us starting a game of Citydash by handing out a hundred £300 phones.
It’ll use Faye to make a websockets connection. This is ideal – low-latency, low-energy, reliable.
If the device doesn’t support websockets (for example, an older Android phone), it’ll use Faye to emulate websockets using long-polling.
If that doesn’t work, or if the connection drops, it’ll make an ordinary AJAX call to the server on a 90-second timer. iPhones and Windows phones (but not Androids) drop all their network connections when the screen goes off, causing them to lose messages. We now detect the connection dropping and kick off an AJAX call as soon as the screen comes back on, to get back in sync.
Older Android phones are a bit more interesting: they don’t always drop the connection, but when they do, they don’t tell you. There’s no connection-loss event to trigger that AJAX call. So, instead, we have a watchdog timer that fires every second, and checks how long it was since it last fired. If it’s more than two seconds, then execution has been paused, meaning the screen was off, meaning we’ve probably dropped the connection. Fire the AJAX call.
Windows phones like to play a fun game where, for a couple of seconds after they’ve woken back up, outgoing network connections will fail silently – 25 seconds after you make them. For those, the resync AJAX call is delayed by five seconds.
If for any reason the AJAX call fails, the whole page is reloaded. Since a full copy of the game state is sent on page load, this is guaranteed to get you back into sync.
If that doesn’t work, it’s probably because your mobile provider is having an outage, or your battery is flat. We handle that too. We have spare batteries we can lend you at the start point.. and we’ve got you all in teams of 3-4, so the odds of all your phones breaking are low.
If all the phones are out (sunspots? nuclear apocalypse?), we’ve got the Meltdown Sheets. If we have to run this game on paper, we can.
They say that sufficiently advanced technology is indistinguishable from magic. But I’d rather this was indistinguishable from nothing. The whole point of this is to build a system that you don’t even notice, because you’re too busy running around and having fun.