iGIPF — An iOS Game in 2 Weeks

Alexey GrunichevApr 18, 2012

Game Center.

Our next step is multiplayer mode. Imagine our delight when we read that, “in iOS 5, Game Center has a new API that makes it easy to create turn-based games”. Upon learning this, and then looking briefly at the API, we decided to change the minimum supported iOS version to 5.0 and use this functionality. This API is supported even on 3GS model iPhones and it really shouldn’t be a big deal that our game won’t work on models that are already almost 4 years old.

Time Limits

So, the turn-based games API sounded like exactly what we need! Unfortunately, problems began to pop up from the start. Initially we wanted to limit the time per turn to ensure the game was dynamic. As you might already guess, there are no such functionality in API.

That was frustrating, but after a long discussion we agreed that because the game requires thinking and planning, maybe a time limit wasn’t most important feature. Eventually, the joy gained from clear victory won through mental prowess is much more fun than a victory gained by default through timeout. In addition to this benefit, we also realized that dropping timeout limits would allow a player to engage in many matches simultaneously. We decided that using the Game Center API for turn-based games was still worth it.

Auto-Matcher

So resolved on issue, but the net reared its head in less a moment. When you create a new match, you get to play the first turn right away (even if the system hasn’t found an auto match partner yet!) When the system has found someone, he can see your turn. There is currently no other way to initiate a game and though it looks pretty strange, that’s how it’s implemented from Apple’s side.

A player creates a game by sending his or her first turn, which acts as a flag that the game is started and tells auto-matcher to consider the player as candidate for playing. So, players must be aware that if they make their first turn in auto-match mode, that doesn’t mean they are already playing with someone.

As an aside, it is worth noting that match maker takes about a minute to pair 2 players. Also, even if one game is waiting for a player and another player clicks “auto-match”, which you think would, ideally, pair that player with already created game, Game Center sometimes creates new game instead. To say the least, testing interaction with this black box is a very tricky task.

Notifications

Ok, you probably think we have already mentioned most of the possible problems with Game Center and the answer to that thought is …"No, not really." The next problem arose with notifications that occur in the background. Imagine, you are playing a game and switch to another application, spend some time there, and then get a notification that your opponent made his turn and so you switch back to our game. It seems relatively simple, but when we tested this scenario, lo and behold, nothing happened.

So, the game is active, everything is ok, the game moves to the background and the notification arrives (at least at the system iOS level – and you can see it) but the game knows nothing about it. That’s it. It seems that 3-4 seconds after the game goes to the background, all listeners are disabled. That’s probably ok to prevent battery drain etc, but when you switch back to the application it should (why not?) deliver all notifications, but in fact it doesn’t. This is a very frustrating problem and we now need to re-implement all game-initialization (recreate the whole game state) logic every time the game emerges from the background, just to proceed to the next turn.

It works

Despite all of the complaints above, it’s still cool to test game. Even though there have been some minor issues, we’re already almost done and are very excited about delivering the application soon!