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.

}<br />

return EKeyWasNotConsumed;<br />

}<br />

The function examines what type of key was pressed: for UIQ, the hardware navigation and<br />

CONFIRM keys have special key codes that I test for here. The navigation keys result in the<br />

cursor being moved, and the board redrawn to show the new cursor position. A CONFIRM<br />

key event indicates the user shooting at a square. If the square has been shot at before<br />

(IsKnown() is true), then it calls the controller's ViewCmdHitFleet() function so that the<br />

hit request can be processed.<br />

Similarly, the view receives pointer events by implementing the CCoeControl base class<br />

function HandlePointerEventL().<br />

void CFleetView::HandlePointerEventL(const TPointerEvent&<br />

aPointerEvent)<br />

}<br />

{<br />

// check whether we're interested<br />

if (<br />

else<br />

}<br />

aPointerEvent.iType==TPointerEvent::EButton1Down &&<br />

iBoardRect.Contains(aPointerEvent.iPosition)<br />

)<br />

{<br />

// identify the tile that was hit<br />

TInt x=(aPointerEvent.iPosition.iX-iBoardRect.iTl.iX)/<br />

iTileSize;<br />

TInt y=(aPointerEvent.iPosition.iY-iBoardRect.iTl.iY)/<br />

iTileSize;<br />

// move cursor if necessary<br />

TBool iCursorMoved=(x!=iCursorX || y!=iCursorY);<br />

SetCursor(x,y);<br />

// hit square unless it's already known<br />

if (iFleet->IsKnown(x,y))<br />

{<br />

iEikonEnv->InfoMsg(R_GAME_ALREADY_KNOWN);<br />

if (iCursorMoved)<br />

}<br />

DrawTilesNow();<br />

iCmdHandler->ViewCmdHitFleet(x,y);<br />

The function responds to a tap on a screen (a TPointerEvent::EButton1Down event)<br />

by translating the event's x and y coordinates into the coordinates of the relevant square on

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

Saved successfully!

Ooh no, something went wrong!