iPhone Game Development - Chris Craft [114]
Cons
It requires an active Internet connection.
It requires that you host your services on a central Web server, which requires monthly fees and ongoing maintenance.
It requires that you implement a system for players to advertise, discover, and connect game sessions with players who are miles apart.
It require users to be running on iPhone OS 3.0 version. Not all users necessarily upgrade to the latest firmware, particularly in the case of iPod touch users, where the firmware carries an additional expense.
Finding Friends to Compete Against
If you choose to play with a head-to-head connection, your opponent is obviously sitting right next to you since you are playing on a single device. Likewise, if you choose to play with a peer-to-peer connection, you're playing with a known opponent who is in close proximity. However, when connecting with a friend using Web services, finding an opponent or friend to play with can be a challenge.
When looking at the pros and cons of connecting with Web services, we mentioned that there are some challenges involved in getting players connected. This is an opportunity for you to be creative; however, implementing a system to connect players in a fun and engaging way can be very time consuming. Be sure to carve out sufficient time in your schedule to make it happen, or you might end up with a great game that does not encourage players to connect. On the other side of the coin, if you do a good job here you can increase sales virally.
When finding friends to connect with, you have many options to consider. There are several user stories you can follow that lead to two players becoming connected. It all depends on how much time you want to put into it. Here are a few questions a player should ask about connecting to other players:
Can I challenge a friend if he has not registered with the game server?
Can I challenge a friend if she does not have the application running?
Can I challenge a friend if he does not have the application installed?
Can I store game results on a leader board?
Can I connect with random players who are looking for a challenge?
Connecting players with Web services
In order to establish a connection, you will need a server to relay the messages between the two players. The messaging required by a turn-based game can be managed with a standard HTTP server. HTTP servers are commonplace these days and you can program them to manage the game on the server side. You can develop this server logic using a host of different languages. Developing a Web server is outside the scope of this book, but we'll focus on the client side code necessary to connect to such a server. For more information on server side services, go to our Web site, www.appsamuckcom/gameservices. There we have links to resources that will help you build and host your own server side services.
Connecting players with the application installed
Once you have access to a server with the services you need, you can start your connection process. If both of the connecting players have the application installed, establishing a connection is a much smoother process than when it is not installed. There are many ways to approach this process, but the way we have chosen to proceed works much like an e-mail server. In fact, we have chosen the e-mail address to be the value that uniquely identifies players. Here are the basics of the process (see Figure 8.6):
If the application has been launched and no e-mail address has been supplied, prompt the user for his e-mail address. Preferably you would confirm that the e-mail address actually belongs to the user.
If the e-mail address is available, search the game server with the e-mail for friends who are challenging the user.
If the user chooses, he can enter the e-mail address of a friend he wishes to play against. When friends search, they'll see that a buddy is asking to play against them.
You should start with this basic process, but you can (and should) expand on this system to make the process more engaging. For example, you