Scramble for Pocket PC

This article shows you how to write Scramble for Pocket PC.

While there are lot of examples available for working with .net Compact framework very few are available that show how to use Drawing class with some what limited functionality compared to original GDI+,  as you all know in order to fit everything into 32MB things have to be omitted and they are, but we should gracefully accept what is available. 

I hope this code sample would help reader to get started with game programming on compact framework, and good part is programming with pocket pc does not look very different from windows application.

ppcScrambleImg.jpg
 
Scramble: 
 
Game consist of 5X5 matrix and there are 1-24 numbers randomly placed on board(matrix) and one place is empty. you can move any number to adjacent place or updown if corresponding adjacent or updown place is empty, To finish or win game you have to arrange number in sequence keeping last space in board empty. 

GameLogic.cs : encapsulates logic for game Scramble. 

I have used array of integers to define matrix. GameLogic class contains complete logic for game. all you need to do is create instance of game logic in your client application to implement game. 

Class frmScramble.cs: is a form containing user interface for Scramble game.

I have used off-Screen drawing combined with opaque background by overriding OnPaintBackground method of form to Produce flicker free and smooth rendering of User interface.  

An important thing to be considered for speed up drawing process is avoid creating brushes and pens in onpaint event, instead of that declare and initialize all brushes and pen at start of program and then use them through out application life. 

As I talked about less functionality in graphics class one of such example is lack of facility to measure string,also absence important methods like DrawArc and DrawPie makes life harder. 

Performance and speed of graphics intensive application should always be tested directly on Device, I have seen lot of performance difference between device and emulator.