tailieunhanh - Symbian OS C++ for Mobile Phones VOL 1 PHẦN 4
Hình 11,7 mã mà nhìn một cái gì đó như thế này: khoảng trống CFleetView:: Draw (const TRect &) const {DrawBoard () DrawBorders (); DrawTiles ();} này mã: vẽ một hình vuông đen trên khu vực của hội đồng quản trịbao gồm cả khu vực biên giới và khu vực biển, thu hút các chữ cái và số phía dưới, trên cùng, | viewCmdHitFleet shows how the controller ties together the two fleets provided by the engine so that the engine s iOppFleet is what I see on the screen while the engine s iMyFleet is the real data for the opponent s fleet. void CGameController ViewCmdHitFleet TInt aX Tint aY ASSERT ALWAYS IsMyTurn Panic EHitFleetNotMyTurn ASSERT ALWAYS iEngine- aX aY Panic EHitFleetAlreadyKnown Hit fleet iEngine- aX aY iEngine- aX aY iEngine- aX aY Update view iAppView- DrawTilesNow If game is won transition to finished if iEngine- IsWon iState EFinished iEnv- InfoMsg R GAME CONGRATULATIONS Firstly the controller asserts that it has been called in the right circumstances. The conditions asserted should always be true but just in case I didn t implement OfferKeyEventL properly in the view or because of some other problem I didn t think of - those are usually the worst kinds of problem I make this assertion so the program can quickly panic if it gets called in the wrong circumstances. We ll see when we get to the Battleships version of the controller with nine states and many functions that are only valid in certain states that these assertions are extremely useful. I use two simple lines to transfer the knowledge of the real fleet from my fleet to the opponent s fleet and to say I hit that square iEngine- aX aY iEngine- aX aY iEngine- aX aY If I hit a ship the engine takes care of ensuring that surrounding squares on the opponent s fleet are marked as sea. After this I update the opponent s fleet view using DrawTilesNow . Finally I check whether this means I ve won the game. If so I write an information message to say so and set the state to finished. In real Battleships the real complexity in the whole game arises from the fact that this line iEngine- aX aY iEngine- aX aY won t work. Instead of simply doing an .
đang nạp các trang xem trước