Space Game!

The following section describes the complete implementation of a simple multiplayer space combat game. Players are pilots engaged in simple combat with each other. Figure 6 shows two opponents playing the game.

A screen shot of Space Game! in action.

Figure 6. A screen shot of Space Game! in action.

This section is organized a follows: first the data structures for the game state are described, then the main game application, finally the client application is briefly discussed.

Game State

Space Game! is a relatively simple game. There are basically only three types of objects which make up the internal state of the game: Ships, Bullets and the game clock. Each ship obviously represents a particular client in the game. Each client can fire multiple Bullets in an attempt to destroy other player's ships. The game clock is the central arbiter of time in the game. It is used to synchronize action. The class diagram for this game state is shown in Figure 7.

The object model for game state

Figure 7. The object model for game state

The first thing to notice is that all of the game state objects implement a shared moveable interface. The moveable interface simply requires two methods:

public interface Moveable {
   public void move();
   public int getTicks();

The move() method actually moves the moveable object. The getTicks() function returns the current local ...

Get Darkstar: The Java Game Server now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.