Game Overview


You are probably familiar with the common game of tic-tac-toe. For this chapter I have created a version of the game that can be played by two people over the Internet (or a network). As you probably already know and should, by now! a game that can be played in this way is called a multiplayer game. Tic-tac-toe is played on a simple board (or a piece of paper) that displays a 3-by-3 grid. Each player has a letter that he or she can place in a grid space; this is usually either X or O. After a move is made, the other player can then make a move. The winner of the game is the first person to establish a horizontal, vertical, or diagonal straight line of three of the same letters. If the board is filled and there has been no match, then there is no winner of this game but the game is over.

Here is how a game of multiplayer tic-tac-toe would typically be initiated and played. There are at least two people in a room in the chat. One of them decides to challenge another. The challenge is made by clicking the user name in the user list. Let's call the challenger Player 1. The person who was challenged, Player 2, can then either accept or decline the challenge. If Player 2 accepts the challenge, then both players are immediately taken to the game screen.

graphics/17fig01.gif

When both players get to the game screen, they are prompted with a pop-up box that tells them the game has begun. Player 1 is informed that it is his turn, and Player 2 is informed that it is her opponent's turn. To move, Player 1 must click any of the nine tiles. When he does this, the letter X appears in that spot, and Player 2 is informed of this move. It is then Player 2's turn, and she can click any of the remaining eight tiles to add an O. The first player to establish three of his or her own letters in a vertical, horizontal, or diagonal straight line wins the game. When the game has been won, a pop-up box displays a little message telling the players if they have won or lost the game. If the board is filled and no one has won, then the game ends in a tie. In this event, a pop-up window tells both players that the game has no winner. Either player can restart the game by clicking the Restart button at the bottom-right part of the screen. When a game is restarted, the board is reset so that it contains no letters, and Player 1 gets the first turn again.

graphics/17fig02.gif

graphics/17fig03.gif

There is a chat window on the screen so the players can still chat. One of the toughest things to do in a multiplayer game is to find room on the stage for the chat window. In tic-tac-toe this is not an issue, but in many games it can cause layout problems.

graphics/cd_icon.gif

The Flash file used for this game is called tic_tac_toe.fla and is located in the Chapter17 directory on the CD. This file was created by taking the chat_full_featured.fla file from Chapter 13, "Dissecting a Chat," and creating the tic-tac-toe game on the Game frame label. Everything up to the Game label was discussed in Chapter 13, so we will not cover it again here but will skip right to the ActionScript and movie clips that are on the Game label. In the next section we talk about the multiplayer actions needed to make this game work. Then, in the final section, we go over the ActionScript that controls the game's rules and interactivity.

graphics/hand_icon.gif

To test this game, you need to start ElectroServer on port 1024. This game file is configured to connect to localhost, which is the same as the IP address 127.0.0.1, on port 1024. Both of these properties can be changed easily in the file's Chat System frame if needed.

Turn-Based Games vs. Real-Time Games

Tic-tac-toe and all of the multiplayer games in this book are turn-based. In a turn-based game, only one player at a time can make a move. In chess, for example, Player 1 makes a move. Then Player 2 makes a move. At no time can both Player 1 and Player 2 make a move at the same time.

A real-time game is one in which both players can make moves simultaneously. A good example of this is a Mortal Kombat style fighting game. Both players can move, jump, kick, punch, and eviscerate simultaneously. This type of game is not impossible with Flash, but it is very difficult for several reasons. To name one, network latency is a big issue. Let's say that at time1, Player 1 punches Player 2. At precisely that instant, out there on his own computer, Player 2 moves out of the way. Due to network latency, the information about Player 2's moving has not yet reached Player 1. Likewise, the information about Player 2's getting punched has not yet reached Player 2, and he is now out of the way. This presents a problem. There are workarounds for this issue, but they are beyond the scope of this book.



Macromedia Flash MX Game Design Demystified(c) The Official Guide to Creating Games with Flash
Macromedia Flash MX Game Design Demystified: The Official Guide to Creating Games with Flash -- First 1st Printing -- CD Included
ISBN: B003HP4RW2
EAN: N/A
Year: 2005
Pages: 163
Authors: Jobe Makar

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net