Understanding Multiplayer Games

Have you ever played a first-person-shooter game against others through a video game console or your personal computer? These games make video game companies hundreds of millions of dollars each year because of their ability to engage other players, not just computer-created characters.

Online games that involved entire worlds are also very popular (think of World of Warcraft). Tablets and phones are also catching onto this craze for more and more connectivity. Possibly the newest genre of multiplayer game is the social game. Farmville, Mafia Wars, and the various other products connect to social networking sites (most notably Facebook) to transfer information about your progress to the games that your friends are playing.

Multiplayer Games through a Server

All the games just mentioned involve connecting players through a server. This means the devices or players aren’t connecting directly to each other but rather through another entity. In fact, web sites on the Internet use this same method: you (the client) get the web material from the web site (the server).

Figure 7-1 is a simple diagram that illustrates several people connecting to a server in order to play a multiplayer game.

images

Figure 7-1. A group of players from different locations log onto a central server and are then able to play against one another.

Before you examine the advantages and disadvantages of server-type multiplayer games, it’s helpful to be able to compare this approach to something else. Let’s look at the peer-to-peer method.

Multiplayer Games with Peer-to-Peer

When players connect directly to one another, then they’re using a peer-to-peer (P2P) network. P2P-enabled games played by opponents within a few feet of each other are typically implemented using Bluetooth, a local area network protocol available on most Android tablets. This means no entity is controlling all of the communications. If you’ve used a P2P file-sharing network (for example, using torrents to download large files from other users rather than a single server), then you’ve connected to other computers like your own to download files; you didn’t need a large server to which everyone was connected. Many large video games for consoles don’t use peer-to-peer because you would be limited to just a few players at a time.

To see the difference between a server-client game and a peer-to-peer game, take a look at Figure 7-2.

images

Figure 7-2. Two players connect directly to one another in order to compete in a game.

Obviously, these two strategies for multiplayer games are very different, but you may wonder which is better. There is no right answer; rather, there are instances when one is superior to the other.

Choosing a Multiplayer Method

Table 7-1 and Table 7-2 hash out some of the major pros and cons for the two multiplayer methods. This isn’t an official list (and some people may disagree about whether something is a positive or a negative), but it gives you a very important grasp of how to choose your solutions.

images

images

If you’ve looked over these tables thoroughly, you should have noticed that the Pros column for the server-client method is the Cons column for the peer-to-peer, and the Pros for the peer-to-peer are the Cons of the server-client. However, adding up the pros and cons of each type doesn’t lead to a correct choice. Instead, you must have a plan for what you desire to create and then select the method that best allows your goals to be achieved.

In the rest of this chapter, you adapt the Tablet Paddle game you built in Chapter 6 for two players, each of whom has control over one of two paddles displayed on their tablet. Because multiplayer programming can be complex, this chapter goes over the main concepts. The entire code is available here for you to work with: http://code.google.com/p/android-tablet-games/.

Because you only need to accommodate two players at a time, and you want to use the most efficient means of creating such a game, you use the peer-to-peer multiplayer game model. And instead of using an Internet connection over a 3G or Wi-Fi network to connect the players, you connect them directly using the Bluetooth network available on most Android devices. By choosing this path, you save huge amounts of time that would have been spent setting up server architecture and ensuring that devices could properly connect.

images Tip For the beginning game programmer, it’s best to stay away from server-client multiplayer games because they’re nearly always much more complex. Don’t be discouraged by this; you can create a plethora of great games from a Bluetooth connection. The added excitement for players in this case is that they’re almost always near each other and can either talk each other through tricky levels or engage in some fun trash-talking.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.7.7