© 2014 Firstsoft Technologies (P) Limited. login
Hi 'Guest'
Home SiteMap Contact Us Disclaimer
enggedu
Quick Links
Easy Studies

CPP Program For Moving Ball
#include"graphics.h" #include"dos.h" #include"conio.h" #include"stdlib.h" #define DELAY 1 #define SOUND 3500 void state(int x,int y,int mode); int i; void *ptr1[4],*ptr2[4]; /* 3d Ball */ char ball[20][20]= { {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,12,12,12,12,12,12,12,12,0,0,0,0,0,0}, {0,0,0,0,12,12,12,12,12,12,12,12,12,12,12,12,0,0}, {0,0,0,12,12,12,12,12,12,12,12,12,12,12,12,12,12,0,0,0}, {0,0,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,0,0}, {0,0,12,12,12,12,12,15,15,12,12,12,12,12,12,12,12,12,0,0}, {0,12,12,12,12,12,15,12,12,12,12,12,12,12,12,12,12,12,12,0}, {0,12,12,12,12,15,12,12,12,12,12,12,12,12,12,12,12,12,12,0}, {0,12,12,12,15,15,12,12,12,12,12,12,12,12,12,12,12,12,12,0}, {0,12,12,12,15,15,12,12,12,12,12,12,12,12,12,12,12,12,12,0}, {0,12,12,12,15,15,12,12,12,12,12,12,12,12,12,12,12,12,12,0}, {0,12,12,12,12,15,12,12,12,12,12,12,12,12,12,12,12,12,12,0}, {0,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,0}, {0,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,0}, {0,0,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,0,0}, {0,0,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,0,0}, {0,0,0,12,12,12,12,12,12,12,12,12,12,12,12,12,12,0,0,0}, {0,0,0,0,12,12,12,12,12,12,12,12,12,12,12,12,0,0,0,0}, {0,0,0,0,0,0,12,12,12,12,12,12,12,12,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} }; /* Condition to check out of range */ int COND(int x,int y) { if (x>10 && x10 && y=(getmaxx()-10)||x<=10) { sound(SOUND); switch(mode) { case 0: state(--x,--y,2); break; case 1: state(--x,++y,3); break; case 2: state(++x,--y,0); break; case 3: state(++x,++y,1); break; } } else if(y>=getmaxy()-10||y<=10) { sound(SOUND); switch(mode) { case 0: state(--x,--y,1); break; case 1: state(--x,++y,0); break; case 2: state(++x,--y,3); break; case 3: state(++x,++y,2); break; } } else exit(0); } void main() { int gm,gd=DETECT; int i,j; initgraph(&gd,&gm,"..//bgi"); for(i=0;i<20;i++) for(j=0;j<20;j++) if(ball[i][j]!='0') putpixel(10+i,10+j,ball[j][i]); getimage(10,10,30,30,ptr1[4]); cleardevice(); getimage(10,10,30,30,ptr2[4]); /* start with (20,20) */ state(20,20,0); getch(); }

 
SLogix Student Projects
bottom