Browse Groups

• /**************#####################**************** program by Shreeharsha Perla you are free to use, modify or distribute this program. for more programs,
Message 1 of 187 , Nov 1, 2011
View Source
/**************#####################****************
program by Shreeharsha Perla
you are free to use, modify or distribute this program.

website: www.ibi_edu.yahoogroups.com
email: ibi_edu@...

IBRAHEEM-JAVED
Asian College
Punjab university
Gujranwala
Pakistan

simple game.
Try to sort the number in ascending order.

**************#####################****************/

#include"graphics.h"
#include"time.h"
#include<conio.h>
#include<stdio.h> /* sorting game */
#include<stdlib.h>
void check(int [4][4]);

void main()
{
int i,j,n[4][4],key,x1=200,y1=200,mx,my;
int gd=DETECT,gm=EGAHI;
int cx,cy,level=1;

srand(time(NULL));

initgraph(&gd,&gm,"c:\\tc\\bgi");
settextstyle(1,0,6);
setcolor(4);
outtextxy(130,200,"IBI BEST OF LUCK");
setcolor(YELLOW);
outtextxy(132,202,"IBI BEST OF LUCK");
settextstyle(3,0,2);
outtextxy(172,404,"Hello Press any key to start");
getch();

do{
clearviewport();
for(i=0;i<=3;i++)
{
for(j=0;j<=3;j++) /* clear all the blocks */
{
n[i][j]=0;

}
}

for(i=1;i<=15;i++)
{
do
{
mx=rand()%4;
my=rand()%4; /* fill numers from 1 to 15 in empty blocks */
} while(n[mx][my]);
n[mx][my]=i;
}
rectangle(180,180,420,420);
setcolor(RED);
rectangle(182,182,418,418);
rectangle(184,184,416,416);
setcolor(YELLOW);
rectangle(186,186,414,414);

gotoxy(2,2);
printf(" exit: Esc restart: Ctrl+R move: Arrows\nIBRAHEEM-JAVED MALIK \t\t\tClass:BCS");
setcolor(1);
my=0;
do
{
for(i=0;i<=3;i++)
{
for(j=0;j<=3;j++)
{
setfillstyle(SOLID_FILL,n[i][j]);
bar(x1+i*50+2,y1+j*50+2,x1+50+i*50,y1+50+j*50);

gotoxy(29+6*i,15+3*j);
if(n[i][j]!=0)
printf("%d",n[i][j]);
else
{
printf(" ");
cx=i; cy=j;
}
}
}
key=getch();

mx=0;
switch (key)
{
case 75: /* movements of numbers */
if (cx==3) break;
n[cx][cy]=n[cx+1][cy];
n[cx+1][cy]=0;
mx=1;
break;
case 72:
if(cy==3) break;
n[cx][cy]=n[cx][cy+1];
n[cx][cy+1]=0;
mx=1 ;
break;
case 80:
if(cy==0) break;
n[cx][cy]=n[cx][cy-1];
n[cx][cy-1]=0;
mx=1;
break;
case 77:
if(cx==0) break;
n[cx][cy]=n[cx-1][cy];
n[cx-1][cy]=0;
mx=1;

}

gotoxy(14,10);
if(mx==1)
{
printf(" * good move * ");
my++;
rectangle(10, 100, my+10, 80);
printf("\t\t No. of moves: %d ",my);
if(my>650)
{
my=1;
level++;
setcolor(level%16);
}

}
else printf("which side? "); /* bad key */
check(n);
}while(key!=27 &&key!=18);

}while(key==18); /* (Ctrl) restart */

closegraph();

}
void check(int order[4][4]) /* check how many numbers are in orrect */
{ /* position */
int t=0,ox,oy,state=0,diff;

for( ox=0;ox<=3;ox++)
{
for (oy=0;oy<=3;oy++)
{
t=(t++ %16);
if(t==order[oy][ox]) state++;

}
}
gotoxy(14,11);
printf(" %d numbers are in correct position.",state);
if(state<5)
puts(" Try to improve ");
else if(state <10)
puts(" You can do it ");
else if( state<13 )
puts(" Very GOOD...Come on, ");
else printf(" You are realy Great ");

if(state==15)
{
setcolor(2);
outtextxy(131,451," -CONGRAGULATIONS-YOU DID IT-");
setcolor(12);
outtextxy(130,450," -CONGRAGULATIONS-YOU DID IT-");
}
}
• /**************#####################**************** program by Shreeharsha Perla you are free to use, modify or distribute this program. for more programs,
Message 187 of 187 , Dec 1 2:04 AM
View Source
/**************#####################****************
program by Shreeharsha Perla
you are free to use, modify or distribute this program.

website: www.ibi_edu.yahoogroups.com
email: ibi_edu@...

IBRAHEEM-JAVED
Asian College
Punjab university
Gujranwala
Pakistan

simple game.
Try to sort the number in ascending order.

**************#####################****************/

#include"graphics.h"
#include"time.h"
#include<conio.h>
#include<stdio.h> /* sorting game */
#include<stdlib.h>
void check(int [4][4]);

void main()
{
int i,j,n[4][4],key,x1=200,y1=200,mx,my;
int gd=DETECT,gm=EGAHI;
int cx,cy,level=1;

srand(time(NULL));

initgraph(&gd,&gm,"c:\\tc\\bgi");
settextstyle(1,0,6);
setcolor(4);
outtextxy(130,200,"IBI BEST OF LUCK");
setcolor(YELLOW);
outtextxy(132,202,"IBI BEST OF LUCK");
settextstyle(3,0,2);
outtextxy(172,404,"Hello Press any key to start");
getch();

do{
clearviewport();
for(i=0;i<=3;i++)
{
for(j=0;j<=3;j++) /* clear all the blocks */
{
n[i][j]=0;

}
}

for(i=1;i<=15;i++)
{
do
{
mx=rand()%4;
my=rand()%4; /* fill numers from 1 to 15 in empty blocks */
} while(n[mx][my]);
n[mx][my]=i;
}
rectangle(180,180,420,420);
setcolor(RED);
rectangle(182,182,418,418);
rectangle(184,184,416,416);
setcolor(YELLOW);
rectangle(186,186,414,414);

gotoxy(2,2);
printf(" exit: Esc restart: Ctrl+R move: Arrows\nIBRAHEEM-JAVED MALIK \t\t\tClass:BCS");
setcolor(1);
my=0;
do
{
for(i=0;i<=3;i++)
{
for(j=0;j<=3;j++)
{
setfillstyle(SOLID_FILL,n[i][j]);
bar(x1+i*50+2,y1+j*50+2,x1+50+i*50,y1+50+j*50);

gotoxy(29+6*i,15+3*j);
if(n[i][j]!=0)
printf("%d",n[i][j]);
else
{
printf(" ");
cx=i; cy=j;
}
}
}
key=getch();

mx=0;
switch (key)
{
case 75: /* movements of numbers */
if (cx==3) break;
n[cx][cy]=n[cx+1][cy];
n[cx+1][cy]=0;
mx=1;
break;
case 72:
if(cy==3) break;
n[cx][cy]=n[cx][cy+1];
n[cx][cy+1]=0;
mx=1 ;
break;
case 80:
if(cy==0) break;
n[cx][cy]=n[cx][cy-1];
n[cx][cy-1]=0;
mx=1;
break;
case 77:
if(cx==0) break;
n[cx][cy]=n[cx-1][cy];
n[cx-1][cy]=0;
mx=1;

}

gotoxy(14,10);
if(mx==1)
{
printf(" * good move * ");
my++;
rectangle(10, 100, my+10, 80);
printf("\t\t No. of moves: %d ",my);
if(my>650)
{
my=1;
level++;
setcolor(level%16);
}

}
else printf("which side? "); /* bad key */
check(n);
}while(key!=27 &&key!=18);

}while(key==18); /* (Ctrl) restart */

closegraph();

}
void check(int order[4][4]) /* check how many numbers are in orrect */
{ /* position */
int t=0,ox,oy,state=0,diff;

for( ox=0;ox<=3;ox++)
{
for (oy=0;oy<=3;oy++)
{
t=(t++ %16);
if(t==order[oy][ox]) state++;

}
}
gotoxy(14,11);
printf(" %d numbers are in correct position.",state);
if(state<5)
puts(" Try to improve ");
else if(state <10)
puts(" You can do it ");
else if( state<13 )
puts(" Very GOOD...Come on, ");
else printf(" You are realy Great ");

if(state==15)
{
setcolor(2);
outtextxy(131,451," -CONGRAGULATIONS-YOU DID IT-");
setcolor(12);
outtextxy(130,450," -CONGRAGULATIONS-YOU DID IT-");
}
}
Your message has been successfully submitted and would be delivered to recipients shortly.
• Changes have not been saved
Press OK to abandon changes or Cancel to continue editing
• Your browser is not supported
Kindly note that Groups does not support 7.0 or earlier versions of Internet Explorer. We recommend upgrading to the latest Internet Explorer, Google Chrome, or Firefox. If you are using IE 9 or later, make sure you turn off Compatibility View.