Reader Level:
ARTICLE

Scramble For Pocket PC in VB.NET

Posted by Jigar Desai Articles | Visual Basic .NET November 10, 2012
This article shows you how to write Scramble for Pocket PC.
  • 0
  • 0
  • 3909
Download Files:
 

While there are many examples available for working with the .Net Compact Framework, very few are available that show how to use the Drawing class with the somewhat limited functionality compared to the 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 the reader to get started with game programming on the Compact Framework, and the good part is that programming with a Pocket PC does not look very different from Windows applications.

ppcScrambleImg-in-vb.net.jpg

Scramble

The game consists of a 5X5 matrix and there are 1-24 numbers randomly placed on the board (matrix) and one place is empty. You can move any number to any adjacent place or up or down if the corresponding adjacent, above or below place is empty; to finish or win the game you have to arrange the numbers sequentially keeping the last space in the board empty.

GameLogic.vb

encapsulates the logic for the game Scramble. 

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

Class frmScramble

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

I have used off-Screen drawing combined with an opaque background by overriding the OnPaintBackground method of the form to produce a flicker-free and smooth rendering of the user interface.  

An important thing to be considered for speeding up the drawing process is to avoid creating brushes and pens in the OnPaint event, instead of that declare and initialize all brushes and pens at the start of the program and then use them throughout the application's life. 

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

The performance and speed of graphics-intensive applications should always be tested directly on the device. I have seen many performance differences between a device and the emulator.

COMMENT USING

Trending up