Tuesday, February 10, 2009

PUZZLE GAME MADE in C++

Hey Guys.....here is a code for making puzzle game in c++....
Try this code....the program as a question i.e. unsolved is present in Let us C....in chapter Arrays....first read the ques from book...nd than try dis code out....If dere is any problem in understanding the code....do write in comments and if u find some other way to make dis program more efficient do give me your reviews and suggestions.........
Here is the program-:

#include"iostream.h"
#include"conio.h"
#include"dos.h"
#include"process.h"
int arr[4][4]={1,4,15,7,8,10,2,11,14,3,6,13,12,9,5,0},temp,i,j;
char c;
void input()
{
for(i=0;i<4;i++)
{
cout<<" -- -- -- --\n";
for(j=0;j<4;j++)
{
cout<<"|"<<<"|";
}

cout<<"\n -- -- -- --\n";
}

}
void sesw()
{
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
if(arr[i][j]==0)
{
switch(c)
{
case 'H':
temp=arr[i+1][j];
arr[i+1][j]=arr[i][j];
arr[i][j]=temp;
break;
case 'K':
temp=arr[i][j+1];
arr[i][j+1]=arr[i][j];
arr[i][j]=temp;
break;
case 'M':
temp=arr[i][j-1];
arr[i][j-1]=arr[i][j];
arr[i][j]=temp;
break;
case 'P':
temp=arr[i-1][j];
arr[i-1][j]=arr[i][j];
arr[i][j]=temp;
break;
default:
cout<<"Wrong key\n";
break;
}
}
}
}
}
getkey()
{
union REGS i,o;
while(!kbhit())
i.h.ah=0;
int86(22,&i,&o);
return(o.h.ah);
}
void main()
{
clrscr();
input();
cout<<"Enter the key\n";
c=getkey();
sesw();
input();
lab:
cout<<"Do you want enter more keys\ Y/N\n";
char s=getch();
if(s=='y' || s=='Y')
{
cout<<"ENter the key\n";
c=getkey();
sesw();
input();
goto lab;
}
else
exit(0);
getch();
}

No comments: