iPhone Game Development - Chris Craft [115]
Caution
It is paramount that you make it easy for players to connect or your game will fail. If the connection process is difficult, many players will get frustrated, delete your app, and give you a bad rating.
FIGURE 8.6
The workflow of two players with the application already installed
Connecting players without the application installed
Connecting players without the application installed is a slightly bigger challenge. However, this is your opportunity to increase your sales virally. It was no accident that we chose to use the e-mail address as the unique identifier. Not only is it unique and verifiable, but we can also use it to communicate with players outside of the constraints of our application. If a player does not have the application installed, we can simply send an e-mail and ask him to install it. Here is an expanded version of the workflow you just looked at, but now we are sending out an e-mail to player 2 if he does not already have the application installed (Figure 8.7).
Adding push notification to the process
Push notification is an exciting feature added to the iPhone SDK beginning with version 3.0. Without push notification, you are limited to receiving game requests via e-mail, via SMS, or when your game is open. When you add push notification, you can alert players whenever a friend challenges them to a new game or even when they make a new move. With push notification, you can issue the following alert types:
Alert box. An alert box is a standard alert box similar to the one you see when you receive an SMS text message without the application open.
Sound. A sound alert is exactly what you would expect: a sound that plays when the notification is received. The sound that is played must be in your application bundle.
FIGURE 8.7
The workflow of two players connecting if one does not have the application installed
Badge. A badge is a counter that appears in the corner of your application's Home screen. This is the same badge that you see on other applications such as Mail. For example, when you receive e-mails without the e-mail client open, the number in the e-mail badge will be incremented. You can use badges in your application; however, push notification allows you to set the badge value without opening your application.
Adding push notification to your process definitely enriches the user experience. Implementing push notification is a little more of a challenge than setting up a simple Web server. Your server must maintain a connection to the Apple Push Notification server in order to send push notifications. Figure 8.8 shows a modified version of the workflow you saw earlier, but with the Apple Push Notification server included.
Notice in this workflow that player 2 is interrupted with a phone call. Push notification helps you continue the game flow with a user-friendly experience. Again, building the server side of push notification is outside the scope of this book, but there is good documentation on the Apple Developer Connection site, and example implementations of the server can be found in the user forums for several different server side languages. This information is changing daily; for more information, see Appendix A or check our site, www.appsamuckcom/gameservices.
FIGURE 8.8
The workflow of the game, including the Apple Push Notification server
Programming: Amuck-Tac-Toe
If you have followed all of the examples we've presented so far in this book, you already know what is necessary to create iPhone games. The example we explain next will add a few more skills to your repertoire. Amuck-Tac-Toe has a very simple game board and set of rules. We like this because we do not want you to have to spend all of your time learning the details of what makes the game tick. Instead, we want you to focus your attention on the new technologies needed to develop this application. After touching