iPhone Game Development - Chris Craft [113]
Here are some pros and cons of supporting head-to-head:
Pros
Two players can play against each other with just a single device.
It does not require an Internet connection.
It is usually an easy addition to an existing game.
Players do not have to deal with establishing a connection to another player.
Cons
It is difficult for players to conceal moves from each other.
It does not contribute to viral sales as much as other connection options.
It does not fit all turn-based game scenarios, especially long-running games.
Peer-to-peer
In Chapter 7 we discussed establishing peer-to-peer connections. Most of the same lessons apply to turn-based games. All you need to do is follow the same steps as you did in the last chapter to establish a connection. The good news is that when you send messages, you don't need to deal with unreliable messages.
Here are some pros and cons of supporting peer-to-peer:
Pros
It's the easiest way to connect two devices.
It does not require an Internet connection.
It does not require a Web server to manage connections.
It provides more than enough throughput for just about any turn-based game.
Cons
It's not supported on first-generation iPhones or first-generation iPod touches.
It requires players to be in close proximity to each other.
As of this writing, it supports only connecting devices.
Web services
Another option is to connect your players through a central server using Web services. To do this you will need to construct a centralized server that can relay messages between players who are connected. For turn-based games, this can be accomplished with an HTTP server that can serve dynamic content. This should be a straightforward task for anyone who is familiar with hosting dynamic Web pages. To service the needs of a turn-based game, you could use a server side language like PHP, Perl, Java, .NET. . . and the list goes on and on. Whichever technology you pick, you will need to expose services that your application can consume. We'll go into more depth on this topic later in this chapter.
Here are some pros and cons of using Web services:
Pros
Players can connect to anyone in the world who can connect to the Internet.
It has a strong potential for viral sales.
It can connect with all models of iPhones and iPod touches that are connected to the Internet.
The game state can be stored, so a single game could be played with intermittent interaction over the course of several days.
Cons
It requires an active Internet connection.
It requires that the application is running for it to receive messages from the other player.
You must host your services on a central Web server. This requires monthly fees and ongoing maintenance.
You have to implement a system for players to advertise, discover, and connect game sessions with players who are miles apart.
Push notification
Push notification is the newest option you have in your bag of tricks. Using push notification in your game will yield results that are very similar to using Web services. The biggest difference is that you have the ability to send messages to players who do not have your application running. As with Web services, we will cover push notification in more detail when we examine the application later in this chapter.
Here are some pros and cons of using push notification:
Pros
Players can connect to anyone else in world who can connect to the Internet.
The application is not required to be running for it to receive notifications from other players.
It has a strong potential for viral sales.
It can work in conjunction with a game using Web services to connect.
The game state can be stored, so a single game could be played with intermittent interaction over the course of several days.