Online Book Reader

Home Category

iPhone Game Development - Chris Craft [111]

By Root 1539 0
probably heard about the value of viral sales time and again. From a business perspective, viral sales should be your overriding goal in turn-based games. For example, assume you want to play Amuck-Tac-Toe with a friend and you know he has an iPhone; however, you don't know if he has the app installed. You could supply your friend's e-mail address and then make your first move, which can send an e-mail to your friend asking her to play. The e-mail she receives contains an iTunes App Store link to install your application. You can expect more and more sales to come from word of mouth as friends ask other friends to compete.

Examining Turn-Based Game Play

We mentioned that turn-based games present fewer technical obstacles to developers than real-time games do. While packet latency is still present, it does not adversely affect game play, and that makes a huge difference in implementation. In a turn-based game, the client generally only needs to send updates to the other player at the close of each turn. Since latency usually falls in the sub-second range, the other player won't even notice the small delay. In fact, the players spend most of their time waiting on the other player to make a move not on the network.

Cross-Reference

For more on packet loss and packet latency, see Chapter 7.

Let's examine the flow of the classic tic-tac-toe game to understand the fundamentals of the process. In tic-tac-toe, players take turns placing Xs or Os on a three-by-three grid until one player places three in a row or the game is declared a draw (Figure 8.1).

FIGURE 8.1

The classic game of tic-tac-toe


Reviewing the game flow

Now let's break down a full game into all of the moves and steps necessary to carry the play from beginning to end. This will help in understanding how a system could be designed to emulate the same behavior. For this example, we examine the moves when Bob and Laurie play a game of tic-tac-toe (Figure 8.2):

1. Bob moves first, placing an X in the top-right square.

2. Laurie places an O in the middle square.

3. Bob places an X in the bottom-left square.

4. Laurie places an O in the top-left square.

5. Bob places an X in the bottom-right square.

6. Laurie places an O in the bottom-middle square.

7. Bob places an X in the right-middle square, giving him three Xs in a row and winning the game.

FIGURE 8.2

Bob and Laurie's game of tic-tac-toe


This is simple enough, especially when it is carried out with pencil and paper. Our challenge is to understand the process so we can translate it to game logic.

Understanding the stages

Reflecting on what you just saw in the game, you can extract the different stages and the actions necessary to move through the process. With this information you can construct a diagram that defines and illustrates the relationship between your states and actions (Figure 8.3).

FIGURE 8.3

A turn-based game diagram helps define the relationship between states and actions.


Your application should carry the players through each of these stages. Along the way make sure to keep track of the following game attributes:

Record information on each player. Make sure you can reconnect later if the connection is lost or if the game play is suspended. Use this same information to quickly start up new matches.

Record the state at each step in the process. Make sure the game can pick up where it left off.

Record the game board after each move. For example, in tic-tac-toe you would record the value of every cell in the three-by-three grid.

As a bonus, keep track of win/loss results between players to foster competiveness.

In the real-time game world we did not try to store the state as it progressed. That would not have been feasible, but it is also much less valuable in a head-to-head or peer-to-peer game. It's important to save the game state so that your players can pause and resume the game at their leisure. This feature of turn-based games can be a huge draw. Games that players would normally never have time to engage in become feasible. A player can spend

Return Main Page Previous Page Next Page

®Online Book Reader