123 Eng

Engineering the engineers™


Latest Jobs   Forum Map

 


Home
Source Codes
Engineering Colleges

Training  Reports
Seminar Reports
Placement Papers

Forums

   Computer Science / IT
   Electronics
   Electrical
   Mechanical
   Chemical
   Civil

   CAT / MBA

   GMAT / Foreign MBA
Latest Jobs

Engineering Jobs / Technical Jobs
Management Jobs

Sitemap
Terms of use

Displaying  Source Code(s)  
 

 
Numbers Arranged game (Mini Project)

--------------------------------------------------------------------------------

Description : Not Specified

Code :

#include<graphics.h>
#include<stdlib.h>
#include<stdio.h>
int ser_arr[4][4]={ {1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,0}};
int h,m,s;
main()
{
int gd=DETECT,gm;
void swap(int *z,int *m);
int main_arr[4][4]={ {1,12,3,14},{5,9,7,6},{8,10,0,11},{13,4,15,2}};
struct time *timep;
int i,j,x,y,num[1],d=0,c,ch,k,l;
char number[1],a[1];
initgraph(&gd,&gm,"z:\lngs\tc\bgi");
cleardevice();

rectangle(100,100,300,300);
line(100,150,300,150);
line(150,100,150,300);
line(100,200,300,200);
line(200,100,200,300);
line(100,250,300,250);
line(250,100,250,300);

y=125;
for(i=0;i<4;i++)
{
x=125;
for(j=0;j<4;j++)
{
if(main_arr[i][j]==0)
{
setcolor(BLACK);
num[0]=main_arr[i][j];
sprintf(number,"%d",num[0]);
outtextxy(x,y,number);
x=x+50;

}
else
{
c=random(100);
for(k=0;k<7;k++)
if(c==16*k)
c=1;
setcolor(c);
num[0]=main_arr[i][j];
sprintf(number,"%d",num[0]);
outtextxy(x,y,number);
x=x+50;
}
}
y=y+50;
}

i=2;
j=2;

while(1)
{
fflush(stdin);
ch=getch();

if(ch==75 && j!=0)
{ d++;
swap(&main_arr[i][j],&main_arr[i][j--]);
}
else if(ch==77 && j!=3)
{ d++;
swap(&main_arr[i][j],&main_arr[i][j++]);
}
else if(ch==72 && i!=0)
{ d++;
swap(&main_arr[i][j],&main_arr[i--][j]);
}
else if(ch==80 && i!=3)
{d++;
swap(&main_arr[i][j],&main_arr[i++][j]);
}
else if(ch==27)
exit(0);

cleardevice();
c=random(100);
for(m=0;m<7;m++)
if(c==16*m)
c=1;
setcolor(c);
rectangle(100,100,300,300);
line(100,150,300,150);
line(150,100,150,300);
line(100,200,300,200);
line(200,100,200,300);
line(100,250,300,250);
line(250,100,250,300);

y=125;
for(k=0;k<4;k++)
{
x=125;
for(l=0;l<4;l++)
{
if(main_arr[k][l]==0)
{
setcolor(BLACK);
num[0]=main_arr[k][l];
sprintf(number,"%d",num[0]);
outtextxy(x,y,number);
x=x+50;

}
else
{
c=random(100);
for(m=0;m<7;m++)
if(c==16*m)
c=1;
setcolor(c);
num[0]=main_arr[k][l];
sprintf(number,"%d",num[0]);
outtextxy(x,y,number);
x=x+50;
}
}
y=y+50;
}
sprintf(a,"%d",d);
outtextxy(330,200,a);
c=0;
for(k=0;k<4;k++)
for(l=0;l<4;l++)
if(main_arr[k][l]==ser_arr[k][l])
c++;
if(c==16)
{
for(i=0;i<100;i++)
{
setcolor(i);
settextstyle(GOTHIC_FONT,HORIZ_DIR,2);
outtextxy(300,310,"Well Played Congratulations ...");
delay(10000);
delay(10000);
delay(10000);
}
getch();
break;
}
}
}
void swap(int *z,int *m)
{
int t;
t=*z;
*z=*m;
*m=t;
}


 

 

 

Contribute content or training reports / feedback / Comments
job placement papers
All rights reserved © copyright 123ENG