Introduction
The Lines.NET is a logic game that targets .NET Compact Framework platform and may run under Windows CE.NET 4.0/4.1 and Pocket PC 2002/2003 operation systems.
Fig. 1. Appearance of Lines.NET game in Windows CE.NET emulator
Game Rules
The Lines.NET is an application with rules of traditional "color lines" game that was designed to run on mobile devices in .NET Compact Framework environment. The short description of these rules may be found below.
Fig. 2. Appearance of Lines.NET game in Pocket PC 2002 emulator
1. Game field
A color lines game takes place on a rectangle board with square cells. Usually it is 9x9 cells square board. Colored balls are placed on the board in random locations. Traditionally the game starts with 3 balls of random colors (see Fig. 3).
A player can select any ball on the board and move it to a free location if this location can be reached from a current ball's location. Each time player moves a ball 3 new balls appear in random positions on the board that still remain empty. The colors of new balls are randomly selected from a set of 6 (in classical color lines game) different colors.
Fig. 3. The traditional color lines playing field
2. Ball movement
Any ball on the board can be moved from its location to any free cell. The length of a route to reach a new location is unlimited. A ball can only go through empty cells and only in vertical and horizontal directions (see Fig. 4) in order to reach its new location. The ball will not be moved to a free cell if this cell is blocked by surrounding cells, which are occupied by other balls.
Player can move only one ball per step, though the length of this movement is not limited. At the end of each step a new set of balls appear on the board (usually it is a set of 3 balls with random colors).
Fig. 4. A ball can move only in horizontal and vertical directions
3. Lines
When balls of the same color compose a line of length 5 or more, this line will be removed from the board, player will be rewarded with score points, and set of new balls will be postponed until the end of a next movement. The lines to remove could be of any direction: horizontal, vertical and even diagonal.
If it happened that by the last movement two or more cross-over lines were completed then all of them will be removed from the game field.
4. Player's goals
The major player's goal is to achieve the highest score and get into a "hi score" list of the game. A player is rewarded by 1 point for each movement he or she does. 5 additional points assigned to the player's score if he/she managed to remove a line of 5 balls by his/her last movement. If player was able to remove more then 5 balls at once each extra ball will be rewarded with 2 extra points in arithmetical progression of increment 2. For example,
- 6 balls -> 5 pt (base) + 2 pt (1st extra ball) = 7 points
- 7 balls -> 5 pt (base) + 2 pt (1st extra ball) + 4 pt (2nd extra ball) = 11 points
- 8 balls -> 5 pt (base) + 2 pt (1st extra ball) + 4 pt (2nd extra ball) + 6 pt (3rd extra ball) = 17 points
- etc.
Thus the longer lines player composes the more points he or she receives, the closer he or she gets to the major goal.
However player should be careful with constructing long lines. Though the major goal is to achieve the highest score, the local goal of player is to do not get the board flooded with balls, because if there is no place on the board for new set of ball to appear the game will be over and no more chance to increase a score. Therefore player should try to keep the game board clean and remove lines of reasonable size.
Features
Lines.NET is a "color lines" game that targets mobile devices with Microsoft ® Pocket PC 2002/2003 and Microsoft ® Windows CE.NET 4.0/4.1 operating systems. The key features of Lines.NET are highlighted here:
- Supports of Microsoft ® Pocket PC 2002/2003 and Microsoft ® Windows CE 4.0/4.1 operating systems with .NET Compact Framework installed.
- Automatically scales the size of the game board to the best fit on the screen (devices with Windows CE usually have bigger screen resolution then Pocket PC models).
- Plays sounds for ball movement and ball removal from the board.
- Serializes player's high score.
- Stores player's preferences.
- Supports enhanced configuration via settings.xml such as a size of game board, sound files locations, etc. (see documentation about
AppSettings
class for more details).
Installation
Before starting an installation process, make sure your mobile device is connected to PC station and connection is established via ActiveSync software. If you don't have ActiveSync installed, get the latest version here:
http://www.microsoft.com/windowsmobile/resources/downloads/pocketpc/activesync37.mspx
1. .NET Compact Framework installation
Download the latest release of .NET Compact Framework redistributable package, run installation process and follow further instructions that will appear during installation. The .NET Compact Framework 1.0 SP2 Redistributable might be found under this link:
http://www.microsoft.com/downloads/details.aspx?familyid=359ea6da-fc5d-41cc-ac04-7bb50a134556
2. Lines.NET installation
You have two ways to install the Lines.NET on your mobile device.
The first one is to install a program from under you PC station. Simply run Lines_NET.exe file from Lines_NET_install.zip archive and follow installation instructions. Your mobile must be connected to the PC station and ActiveSync should be activated. Note that Lines_NET.CAB file is not needed if you install the application using Lines_NET.exe.
The second way is to copy Lines_NET.CAB file (you may find it in Lines_NET_install.zip archive) to your mobile device manually and then, using file explorer of your mobile device, find the location of copied cabinet file and start installation directly from the device.
Design & Implementation
The Lines.NET application is built with taking into account the classical MVC (model-view-controller) pattern. All classes of application are split into 4 namespaces.
1. Lines namespace
This is a root namespace of Lines.NET application. It contains all classes that implements GUI forms and dialogs that are used in the game including MainForm
class. The MainForm
class, in addition to be a representation of a main form of Lines.NET and containing the main entry point for the application, also takes a role of controller by providing intercommunication between Model and View classes. It takes care of handling events from either sides and making decision where to redirect them to. Some other dialogs such as InputBox
, AboutBox
, HiScoreForm
are also located in this namespace.
The only outsider among the classes in this namespace is AppSettings
class that holds the currently running game settings and employs Properties
class from Lines.Utils
namespace to serialize them into settings.xml file on exit and read them from this file during startup. This class provides static getters and setters to all properties of Lines.NET application.
These classes are written for .NET Compact Framework only and cannot be used in .NET Framework environment except maybe AppSettings
class. One must rewrite them in order to run the game in .NET Framework environment.
2. Lines.Core namespace
This namespace contains classes that present the core functionality of Lines.NET game. It consists of model classes from the MVC pattern point of view, such as Ball
, Board
, Game
, etc. Classes that enclose game algorithms to find a shortest path and lines compositions on the board are placed here too.
These classes are absolutely independent of .NET Compact Framework specifics and might be freely used in .NET Framework environment.
3. Lines.GUI namespace
This namespace contains visual controls that match to classes from the Lines.Core
namespace to display them in .NET Compact Framework environment. For instance, BallCtrl
is used to visualize a Ball
object from the Lines.Core
namespace. Note: these classes have some Compact Framework specifics and should be adjusted to be properly used in .NET Framework.
4. Lines.Utils namespace
This namespace contains some useful classes that simplify some routine job, but doesn't actually belong to any of the namespaces listed above. One of those is a class to play sound files in .NET Compact Framework environment, which was adopted from http://www.gotdotnet.com/ web site ( Sound.cs). Thanks a lot to their developers who shared this code.
Another one might be interesting for your own application. It is a Properties
class that provides a functionality to write and read application properties in XML format. The key feature of this class is native type support, so that you don't need to bother yourselves with formatting/parsing/casting strings to native types and vice versa.
PathHelper
class, which is also located in this namespace, helps to find and use a location of application directory the application is launched from.
For more details please refer to the Lines.NET API documentation that you can find in "doc" folder of source code file from download section. As an option you may also read C# comments throughout the source code, which are reflected in the documentation.
.NET Compact Framework specific issues
While programming the Lines.NET game I have encountered several issues with usage of .NET Compact Framework, and some times had to use ad hoc decisions to solve them, because I couldn't find any proper solution.
First of those issues is operating system detection. Though the behavior of .NET Compact Framework applications under Pocket PC 2002/2003 and Windows CE.NET 4.0/4.1 is different I wasn't able to find out how can I programmatically detect the current operating system my application is running on from under .NET Compact Framework. Lines.NET is using configuration file to define the OS. However I'm sure there must be a way to detect it without this ad hoc.
The good example of different behavior could be a usage of SIP (soft input panel) in Pocket PC version: in order to give a user a possibility to fill up a form a SIP panel is used. SIP panel and button to display it appears on the screen only if the MainMenu
object is placed on the form. Thus even though there is no need to have a context menu for a dialog one has to place a dummy MainMenu
object, which looks just ugly in Windows CE.NET OS where SIP panel is not needed.
Another example of difference is MainMenu
itself, under Pocket PC 2002/2003 it is placed at the bottom whereas under Windows CE.NET it is placed at the top of dialog and one should always take into consideration its size to place GUI components under menu. I wasn't able to find the way to detect a height of MainMenu
object, hence again I had to put this property into configuration file of application.
The second major problem was revealed while using threads and creating dialogs out of non-main thread. The ball movement is run as in separate thread. By the end of the movement the game field is examined whether there is a place on the board for a next step, if there is no such the end of the game event is fired. The handler of a game over event is displaying a game over dialog and requests from player to enter his or her name in order to save the record. Then a new game started. That's the ideal scenario which is supposed to work just fine. However, after the dialog was shown from a side thread, the strange unnamed thread (I could see this while debugging the application) has been launched, this happens though only when a MainMenu
is placed on displayed dialog. When player tries to close application the termination of this unnamed thread causes some strange Runtime Exceptions from inside of .NET Compact Framework core. It seems like an internal problem of .NET Compact Framework. In order to get rid of this problem the watch dog timer was used to determine the end of a game and display game over dialogs from the main thread.
There were a lot more problems, which were successfully resolved while developing Lines.NET.
Fig. 5. Appearance of Lines.NET in real life on a SIMpad device
Future Plans
Although the Lines.NET version 1.1 is released with the whole set of desired features there are some more of them is likely to see in the next versions, such as:
- Allow player to configure the complete set of game settings via friendly graphic user interface, but not through editing settings.xml file.
- Allow player to configure colors (ball, board, indicator, etc.) and other game appearance settings by enhancing
Lines.GUI.Preferences
class.
- Implement undo for the last step.
Even though there are still some things to implement and improve one can already enjoy the game.
The list of devices where Lines.NET game has been successfully tested:
- Visual Studio.NET emulator for Pocket PC 2002 device (see Fig. 2).
- Visual Studio.NET emulator for Windows CE.NET 4.0 device (see Fig. 1).
- Simens SIMpad with Windows CE.NET 4.1 operating system installed on (see Fig. 5).
- ASUS MyPal A620 with Pocket PC 2003 operating system installed on.
Useful Links
Here is a list of resources which are surely will be useful to anybody who develops applications for .NET Compact Framework platform:
Thanks
Thanks a lot to my father whose eager to play "color lines" has encouraged me to write this application. The Lines.NET game is dedicated to my lovely dad. It is his birthday present from me along with SIMpad device you may see on the Fig. 5. He is a greatest fan of "color lines" game I've ever seen, though he always lacks a possibility to play it at the time he would like to.
It took me a while to finish with my present, but now I'm fairly glad that my father can enjoy it!