03.01.2013 Views

Chapter 1

Chapter 1

Chapter 1

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Figure 9.2<br />

On the right, you can see the familiar GUI application classes – application, document, app<br />

UI, and app view.<br />

On the left, you can see the classes that represent the application's persistent data: the<br />

controller and engine. The engine has two fleet objects: iMyFleet stores the actual layout<br />

of the fleet of ships the player is trying to sink; iOppFleet stores what the player has<br />

discovered so far about the fleet (by making shots at it). Each fleet object has a number of<br />

ships in it, represented by TShip, a class not shown on the diagram.<br />

Note<br />

'Engine' is a synonym for 'model' in the model-view-controller (MVC) sense.<br />

Inside Symbian, these words are used interchangeably.<br />

The application's view displays the target fleet, and handles input (the user's shots). The<br />

MGameViewCmdHandler interface class is used to communicate from the view to the<br />

controller.<br />

Note that the document class owns only the objects that hold the application data (controller,<br />

engine, fleets), while the app UI owns only the object that displays it (view). This separation<br />

will be essential when we come to add persistence to the program.<br />

9.2.2 The Engine<br />

Solo Ships is a simple, one-player game in which the user plays against a randomly<br />

generated layout of battleships. However, the application has been designed with flexibility in<br />

mind so it can be expanded to a full, multiplayer game in future: Solo Ships and the full<br />

Battleships game have the same engine code.<br />

As mentioned earlier, the engine has two fleet objects:<br />

� One fleet object (termed the 'opponent' fleet) is initialized to be entirely empty at the<br />

beginning of the game. This is the fleet displayed in the application's view, and it<br />

represents what the player has discovered so far about the target fleet that they are<br />

trying to sink.<br />

� The real information about the target fleet (termed 'my fleet') is contained in the other<br />

fleet object. This is initialized randomly at the beginning of the game.<br />

Each time the user shoots at a square, the controller asks the 'my fleet' object what is at that<br />

square, and updates the 'opponent fleet' object appropriately. This is then reflected in the<br />

view. So, during the game, the player gets to know more and more about the opponent fleet<br />

until – when he's sunk it entirely – he knows everything about it.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!