Header Sep
Symbian OS Tips, Tricks & Code
Score
Login to rate page

September 2005
A smartphone board game code example

[Back]

There are different approaches to developing graphical applications, such as games, for smartphones. For example, 2D or 3D games with frequent updates of the screen could use direct screen access. For board games, such as chess or checkers, another approach is to use the Windows server, and CCoeControl derived controls.

Here's an example of how such games can be designed, using a Minesweep example application:

Download example application>>

The screen shot below shows the running application:

Although the game is small, important programming idioms are shown and the application architecture can be reused for other board games. For these, the rules and behavior of the game have to be changed, but the principles used in the game design can be re-used.

The game board is divided into equal-sized squares. Each square in the game is a CCoeControl-derived control, which means that it has the ability to draw itself since it implements the Draw()-method. The same functionality could be achieved by drawing directly to the screen without using the control framework, but when using controls in this manner, the Windows server will take care of many details that do not need to be taken care of by the application.

Each square is put in a grid, using the grid-class that was shown in a previous Tips, Tricks & Code article: Using grids for the layout of Controls in UIQ applications>>

To speed up the screen update, off-screen drawing is used to draw different squares, (unknown, empty, bomb and flag).  When the actual drawing should be done, the off-screen bitmap is draw to the screen using BitBlt().

The code example is generic regarding the size of the board, and board sizes ranging from 5*5 to 10*10 are used in the game. 

For more details of the board game implementation, see the example application source code.  

 

 

Score
Login to rate page