Click here to Skip to main content
11,648,094 members (64,609 online)
Click here to Skip to main content

Lines.NET game

, 11 May 2004 CPOL 80.1K 554 29
Rate this:
Please Sign up or sign in to vote.
The Lines.NET logical game for mobile devices.

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.

Appearance of Lines.NET game in Windows CE.NET emulator

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.

Appearance of Lines.NET game in Pocket PC 2002 emulator

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.

The traditional color lines playing field

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).

A ball can move only in horizontal and vertical directions

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:

  1. Supports of Microsoft ® Pocket PC 2002/2003 and Microsoft ® Windows CE 4.0/4.1 operating systems with .NET Compact Framework installed.
  2. 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).
  3. Plays sounds for ball movement and ball removal from the board.
  4. Serializes player's high score.
  5. Stores player's preferences.
  6. 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.

 Appearance of Lines.NET in real life on a SIMpad device

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:

  1. Allow player to configure the complete set of game settings via friendly graphic user interface, but not through editing settings.xml file.
  2. Allow player to configure colors (ball, board, indicator, etc.) and other game appearance settings by enhancing Lines.GUI.Preferences class.
  3. 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:

  1. Visual Studio.NET emulator for Pocket PC 2002 device (see Fig. 2).
  2. Visual Studio.NET emulator for Windows CE.NET 4.0 device (see Fig. 1).
  3. Simens SIMpad with Windows CE.NET 4.1 operating system installed on (see Fig. 5).
  4. 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!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Vladimir L.
Software Developer (Senior)
Russian Federation Russian Federation
No Biography provided

You may also be interested in...

Comments and Discussions

 
GeneralMy vote of 5 Pin
qwreqwer10-Nov-10 21:36
memberqwreqwer10-Nov-10 21:36 
GeneralError. Can't not playing game or run application from source code. [modified] Pin
phamanhquoc6-Nov-09 2:14
memberphamanhquoc6-Nov-09 2:14 
GeneralRe: Error. Can't not playing game or run application from source code. Pin
Vladimir L.17-Nov-09 12:02
memberVladimir L.17-Nov-09 12:02 
QuestionAbout License Pin
vitor.shofar16-Sep-08 8:34
membervitor.shofar16-Sep-08 8:34 
AnswerRe: About License [modified] Pin
Vladimir L.19-Sep-08 12:12
memberVladimir L.19-Sep-08 12:12 
GeneralCan't debug on Pocket PC 2002 Emulart [modified] Pin
tr_hoaiphong23-Jun-06 22:20
membertr_hoaiphong23-Jun-06 22:20 
GeneralSome questions.... Pin
_LiPh_21-Jun-06 5:28
member_LiPh_21-Jun-06 5:28 
AnswerRe: Some questions.... Pin
Pravin Wagh11-Dec-06 14:08
memberPravin Wagh11-Dec-06 14:08 
GeneralMS Smartphone Pin
benjymous4-Jan-05 5:32
memberbenjymous4-Jan-05 5:32 
GeneralRe: MS Smartphone Pin
Vladimir L.10-Jan-05 7:38
memberVladimir L.10-Jan-05 7:38 
GeneralGreat Work Pin
Shail_Srivastav28-May-04 19:13
memberShail_Srivastav28-May-04 19:13 
GeneralDamn, I was going to make this one :-) Pin
Alejandro Mezcua18-May-04 1:18
memberAlejandro Mezcua18-May-04 1:18 
GeneralRe: Damn, I was going to make this one :-) Pin
Vladimir L.18-May-04 5:35
memberVladimir L.18-May-04 5:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150804.4 | Last Updated 12 May 2004
Article Copyright 2004 by Vladimir L.
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid