03.01.2013 Views

Chapter 1

Chapter 1

Chapter 1

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

BSP state, and panics the program if it finds otherwise. It is the responsibility of the event<br />

source to precheck validity – for instance, the opponent's fleet view should not issue a hit<br />

request unless the BSP state is my-turn: this particular condition is assured by dimming the<br />

view unless the BSP state is my-turn.<br />

Finally the app UI uses two dialogs, to initiate a game (and RGCP communications session),<br />

and to start a new game (in the context of the same RGCP communications session).<br />

You can find the code for Battleships on the website:<br />

Source Files Purpose<br />

engine.cpp, engine.h The engine, exactly as in Solo Ships<br />

view.cpp, view.h The fleet view, exactly as in Solo Ships<br />

appui.cpp, appui.h The application, document, and app UI classes,<br />

along with the initiate and new game dialogs<br />

controller.cpp, controller.h The controller<br />

battleships.rss,battleships.hrh Resource file and shared constants<br />

If you've read the walkthrough of Solo Ships and the description of BSP, then the<br />

implementation of Battleships will contain few surprises.<br />

I'll pause to look at a few representative functions, so you can get a flavor of how things<br />

hang together in a real TOGS game.<br />

16.5.1 The Status View<br />

Before we get involved in the communications code, let's look at the status view. There's not<br />

much to learn from its code, but there are a couple of reminders of the realities of graphic<br />

design here.<br />

My choice for the design of the status view was primarily determined by the capabilities of<br />

the device it was designed for, in particular the portrait screen format used by UIQ based<br />

devices. In the Battleships application the fleet view occupies the majority of the screen,<br />

leaving very little space for a permanent status view. The simplest, but not necessarily the<br />

best option is to use a dialog to display the game status available and make this available<br />

from the menu options.<br />

This has the advantage of leaving the maximum available area for playing the game and<br />

also offers a more flexible approach to the presentation of the status information rather than<br />

trying to squeeze the information into too small a space.<br />

16.5.2 Handling Hit Requests<br />

Remember that, in Solo Ships, the controller handled hit requests from the view using<br />

void CGameController::ViewCmdHitFleet(TInt aX, TInt aY)<br />

{<br />

__ASSERT_ALWAYS(!(iEngine->iOppFleet.IsKnown(aX, aY)),<br />

Panic(EHitFleetAlreadyKnown));<br />

// hit fleet

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

Saved successfully!

Ooh no, something went wrong!