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.

If you compare this with the Solo Ships design described in <strong>Chapter</strong> 9, you'll notice that<br />

� instead of the document owning the controller, and the app UI owning the view, the<br />

app UI owns the controller, and the controller owns the view,<br />

� the engine and view classes perform the same function as in Solo Ships,<br />

� there are actually five views in this application: each player's fleet view and their view<br />

of the opponent's fleet plus a hider view.<br />

There are two interesting aspects to this program:<br />

� It does some interesting Uikon tricks: it has five app views, and it manipulates its menu<br />

options. It's useful to know this kind of trick, so we'll have a closer look at the code.<br />

� It doesn't use communications to get information about the other player's fleet :<br />

instead, it uses object-oriented plumbing. We'll have a look at the code involved, and<br />

we'll explain why changing the ten or so lines of plumbing to support communications is<br />

going to take several hard chapters to explain a suitable replacement for them. Or, put<br />

another way, we'll understand why I wanted to take the tp-ships shortcut before<br />

doing all that communications work.<br />

Let's look at these two things in turn.<br />

16.2.1 View and Menu Tricks<br />

As we saw in <strong>Chapter</strong> 9, a GUI application can have more than a single view. Many of the<br />

built-in Symbian OS applications have more than one view:<br />

� Agenda can have day, week, month, year, to-do, and anniversary views<br />

� Contacts has card and list views<br />

� Messaging supports various types of message types and has appropriate views for<br />

each of them.<br />

In a Symbian OS GUI application, it's very easy to change views without changing the app<br />

UI, because the view is quite a distinct entity from the app UI.<br />

The app UI has seven members, five of which are views:<br />

CGameController* iController; //Controller for both players<br />

COppFleetView* iP1OppFleetView; //Fleet views for P1 fleet and<br />

target fleet<br />

CMyFleetView* iP1MyFleetView;<br />

COppFleetView* iP2OppFleetView; //Fleet views for P2 fleet and<br />

target fleet<br />

CMyFleetView* iP2MyFleetView;<br />

CHiderView* iHiderView; //Hider view<br />

CFleetView* iActiveView;<br />

There are also three associated flags that control whether the views are visible. The Hide<br />

menu option calls CmdHideL() which is coded as:<br />

void CGameAppUi::CmdHideL()<br />

{<br />

ActivateViewL(TVwsViewId(KUidTpShips,KHiderViewUID));<br />

iActiveView = NULL;<br />

// toggle player turn

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

Saved successfully!

Ooh no, something went wrong!