As the name indicate its a puzzle game developed for windows mobile using c# and .net compact framework 2.0
The game contains 15 numbered blocks with a single empty space which acts as a slider space for number swap

Game concept
a number set containing numbers ranging from 1 to  15 is randomly arranged using a random number generator depending on the users difficulty level
What the players have to do is rearrange them within a fixed number of moves and within a selected time frame

What make it stand out from other puzzle games
the game provide some  advance game play features like hints, autoplay... etc
and if  you are a player who choose user interfacer features over advanced algorithms, then thhis game is for you

Hint for the next move and animated autoplay
All the player moves will be taken in to account for both hint and autoplay facilities
Depending on the moves history the most efficient next move will be predicted and is shiwn to the players as a blinking number
The autoplay facility also uses an algorithm which takes the dynamically changing player moves history in to account for predicting the most efficient autoplay move Set
the game also conntains facilities like takeback (lets the users undo any number of  moves), reset initial state (lets the user to restart from the beginning), resume  play (depending on the game exit status the  players can resume from where they left off or start a new game)

if that's not enough  the game also comes with a rich set of sweet animations which will enhance the users game ay experience

Development details (technical defficulties faced and how I get over with them)

When I first received tHe project the main concern was to enhance the game play experience of the user by providing them with  well written algorithms as well as with the best possible user interfaces
Before I started mobile development I had good experience with developing windows applications so I was like, "ok lets get it over with, I’m good at ui designing so what the hell".

The initiatial application consisted of labels where the label.text property is changed in order to swap two numbers. but I decided to add an animation where the two numbers will get swaped with an animation showing the translation. So in order to accomplish this I dedided to add buttons instead of labels. which will enable me to add a good button image as well.
He ! what am I thinking, then I got to know that there's no background image property for buttons in the compact framework. What I did was, Icreated a custom control from scratch combinning a picture box and a label

then i rewrote the useful properties using get, set
eg.
public Color LabelBackColor
        {
            get
            {
                return label1.BackColor;
            }
            set
            {
                label1.BackColor = value;
                this.Refresh();
            }
        }

i also controlled how the controls inner items will behave when its resized
private void pictureButtonController_Resize(object sender, EventArgs e)
        {
            pictureBox1.Width = this.Width;
            pictureBox1.Height = this.Height;// -label1.Height;
            label1.Left = (pictureBox1.Width / 2)-(label1.Width/2);
            label1.Top = (pictureBox1.Height / 2)-(label1.Height/2);
           
        }

and after all these are done, i had my button at my service

The next challenge was to maintain the history of how the buttons got swapped and what is their position in the UI after each swap

What i did was i decided to maintain a button Map with the assistance of some custom written methods
i'll post them so anyone who is doing a similar thing will benefit ffrom it\
:-)

think of the button map in this way
 btn01 btn02 btn03 btn04
 btn05 btn06 btn07 btn08
 btn09 btn10 btn11   btn12
 btn13 btn14 btn15   btn16

btn16 is the empty button when the user click on a button the algorithm will check if it is adjacent to the empty button im a non diagonal direction and swap it with the empty one

following are the helper methods i wrote in order to achive this

        #region find the btnmap position[,] for a given item
        private static int[] findIndex(int item)
        {            
            int[] a = new int[2];
            bool breakStatus = false;
            for (int i = 0; i <>
            {
                for (int j = 0; j <>
                {
                    if (Module11.buttonMap[i, j] == item)
                    {
                        breakStatus = true;
                        a[0] = i;
                        a[1] = j;
                        break;
                    }
                }
                if (breakStatus)
                {
                    break;
                }
            }
            return a;
        } 
        #endregion

        #region set the btnmap to the start state
        private void setFirstState()
        {
            int btnLabel = 1;
            for (int i = 0; i <>
            {
                for (int j = 0; j <>
                {
                    Module11.firstBtnMap[i, j] = Module11.buttonMap[i, j];
                }
            }
        } 
        #endregion

        #region find the place count for the empty button
        private static int findEmptyPosition()
        {
            int place = 1;
            bool breakStatus = false;
            for (int i = 0; i <>
            {
                for (int j = 0; j <>
                {
                    if (Module11.buttonMap[i, j] == 16)
                    {
                        breakStatus = true;
                        break;
                    }
                    place++;
                }
                if (breakStatus)
                {
                    break;
                }
            }
            return place;
        } 
        #endregion

        #region find the place count for a specific button
        private static int findPosition(int item)
        {
            int place = 1;
            bool breakStatus = false;
            for (int i = 0; i <>
            {
                for (int j = 0; j <>
                {
                    if (Module11.buttonMap[i, j] == item)
                    {
                        breakStatus = true;
                        break;
                    }
                    place++;
                }
                if (breakStatus)
                {
                    break;
                }
            }
            return place;
        } 
        #endregion

        #region find the btnmap position[,] for a given place count
        private int[] findPositionOf(int index)
        {
            int[] a = new int[2];
            int count = 1;
            bool breakState = false;
            for (int i = 0; i <>
            {
                for (int j = 0; j <>
                {
                    if (count == index)
                    {
                        a[0] = i;
                        a[1] = j;
                        breakState = true;
                        break;
                    }
                    else
                    {
                        count++;
                    }
                }
                if (breakState)
                {
                    break;
                }
            }
            return a;
        } 
        #endregion

next I'll tell you how i handled the animations

first of all my animations worked on my custom control so i added the following code to the custom controll class

public void Move(Point newLocation)
        {
            if(this.Name.Equals("picCtrl16"))
            {
                this.Location=newLocation;
                goto a;
            }
            BringToFront();

            Point startLoc = this.Location;
            Point newLoc=this.Location;

            int defX = newLocation.X - startLoc.X;
            int defY = newLocation.Y - startLoc.Y;            
                        
            for (int step = 1; step <>
            {
                int factor = step*step;
                Thread.Sleep(10);

                newLoc.X = startLoc.X + (defX * factor) / 100;
                newLoc.Y = startLoc.Y + (defY * factor) / 100;                       
                this.Location = newLoc;              
                Parent.Update();

                if (defX==0)
                {
                    if (newLocation.Y - newLoc.Y <= 1)
                        break;
                }
                if (defY==0)
                {
                    if (newLocation.X - newLoc.X <= 1)
                        break;
                }
                                
            }

            this.Location = newLocation;

        a:
            ;
        }

public void MoveFastest(Point newLocation)
        {
            if (this.Name.Equals("picCtrl16"))
            {
                this.Location = newLocation;
                goto a;
            }
            BringToFront();

            Point startLoc = this.Location;
            Point newLoc = this.Location;

            int defX = newLocation.X - startLoc.X;
            int defY = newLocation.Y - startLoc.Y;           

            this.Location = newLocation;
            Parent.Update();
        a:
            ;
        }

the methods are invoked in the following manner

btn01.MoveFaster(loc02);

what it does is, it'll move the btn01 to location 02 slowly depending on the thread sleep time and the factor of distance getting changed each time its moved

any comments will be appriciated
contact me if u need any help
dhanushka131@yahoo.com
dhanushka8715@gmail.com
bye for now...
:-)

0 comments:

Post a Comment