//Author - Sameer Panse //This is not my code, but still I would like to pass it on. // You will have to experiment with this code. //Brainvit.c #include#include #include #include int m1,m2,blx[50],bly[50],emp[50],sam; int fun1(int,int),fun2(int,int),fun3(int,int,int,int,int),fun4(),fun5(),help(); main() { int c,m3,m4,m5=0,i,j=1,k=1,m6,m7; int em1[35],em2[35],graphdriver,graphmode,i4,so=1; char fil1[20]; FILE *fp1; fun4(); for(i=0;i<=49;i++) { blx[i]=0; bly[i]=0; emp[i]=10; } for(m3=0.1*m1;m3<=0.7*m1;m3=m3+0.1*m1) { k=1; for(m4=0.1*m2;m4<=0.7*m2;m4=m4+0.1*m2) { if((j%4==0)&&(k%4==0)) { k++; continue; } if(((j%3==0)&&(j%6!=0))||(j%4==0)||(j%5==0)||((k%3==0)&&(k%6!=0))||(k%4==0)||(k%5==0)) { fun2(m3,m4); bly[m5]=m4; blx[m5]=m3; } if(m5==23) { bly[24]=0.4*m2; blx[24]=0.4*m1; m5++; } m5++; k++; } j++; } j=2; k=2; emp[24]=0; m5=0; m3=0; i4=-1; do { if(j<0)j=48; if(j>48)j=2; fun1(blx[j],bly[j]); c=getch(); if(((c=='s')||(c=='s'))&&(so==0))so=1; else if(((c=='s')||(c=='s'))&&(so==1))so=0; if((c==80)||(c==72)||(c==75)||(c==77)) { setcolor(BLACK); if(k!=j)fun1(blx[j],bly[j]); if(c==80) { j++; while(blx[j]==0) { j++; if(j>48)j=0; } } if(c==72) { j--; while(blx[j]==0) { j--; if(j<0)j=48; } } if(c==77) { j=j+7; if(j==51)j=3; if(j==52)j=4; while(blx[j]==0) { j++; if(j>48)j=0; } } if(c==75) { j=j-7; if(j==-4)j=44; if(j==-3)j=45; if(j<0)j=0; while(blx[j]==0) { j--; if(j<0)j=48; } } setcolor(WHITE); } if((c=='t')||(c=='T')||(c=='n')||(c=='N')||(c=='i')||(c=='T')||(c=='o')||(c=='O')) { while(m3!=0) { if(m3>0)m3--; setcolor(WHITE); fun2(blx[em2[m3]],bly[em2[m3]]); fun2(blx[(em1[m3]+em2[m3])/2],bly[(em1[m3]+em2[m3])/2]); setcolor(BLACK); fun2(blx[em1[m3]],bly[em1[m3]]); emp[em2[m3]]=10; emp[(em1[m3]+em2[m3])/2]=10; emp[em1[m3]]=0; if((c=='t')||(c=='T'))break; }; setcolor(WHITE); if((c=='f')||(c=='F')||(c=='i')||(c=='T')||(c=='o')||(c=='O')) { if((c=='i')||(c=='T')||(c=='o')||(c=='O')) { if((c=='i')||(c=='T')) { closegraph(); printf("\n\n\nType the file name to save this game.\n"); scanf("%s",fil1); fp1=fopen(fil1,"w+t"); clrscr(); fun4(); fun5(); } if((c=='o')||(c=='O')) { closegraph(); printf("\n\nType the file name to retrive the game.\n"); scanf("%s",fil1); fp1=fopen(fil1,"r+t"); clrscr(); fun4(); fun5(); m7=0; while(fscanf(fp1,"%d%d",&em1[m7],&em2[m7])!=EOF) { emp[(em1[m7]+em2[m7])/2]=0; emp[em2[m7]]=0; emp[em1[m7]]=10; m7++; } i4=m7-1; m3=0; } } while((m3<=i4)&&(i4>=0)) { setcolor(BLACK); fun2(blx[em2[m3]],bly[em2[m3]]); fun2(blx[(em1[m3]+em2[m3])/2],bly[(em1[m3]+em2[m3])/2]); setcolor(WHITE); fun2(blx[em1[m3]],bly[em1[m3]]); emp[em2[m3]]=0; emp[(em1[m3]+em2[m3])/2]=0; emp[em1[m3]]=10; m3++; if((c=='i')||(c=='I')) fprintf(fp1,"%d%d\n",em1[m3-1],em2[m3-1]); if((c=='f')||(c=='F'))break; }; if((c=='i')||(c=='I'))fclose(fp1); } } if((c=='w')||(c=='W')) { help(); } if(c==13) { setcolor(RED); fun1(blx[k],bly[k]); if(fun3(emp[j],j,k,emp[(j+k)/2],emp[k])==10) { fun2(blx[k],bly[k]); fun2(blx[(j+k)/2],bly[(j+k)/2]); if(so==1)for(m5=1;m5<6;m5++) { sound(m5*100); delay(75); nosound(); em1[m3]=j; em2[m3]=k; i4=m3; m3++; } /*for so*/ setcolor(WHITE); fun1(blx[j],bly[j]); if(fun3(emp[j],j,k,emp[(j+k)/2],emp[k])==10) fun2(blx[j],bly[j]); if(fun3(emp[j],j,k,emp[(j+k)/2],emp[k])==10) { emp[k]=0; emp[(j+k)/2]=0; emp[j]=10; }/*for fun3*/ k=j; }/*for fun3*/ }/*for enter i.e. ASCII value=13*/ }while(c!=3); closegraph(); return 0; } int fun1(int x,int y) { rectangle(x-0.01*m1,y-0.01*m2,x+0.08*m1,y+0.06*m2); return 0; } int fun2(int m3,int m4) { int i; for(i=1;i<=0.05*m2;i++) line(m3,m4+i,m3+0.07*m1,m4+i); return 0; } int fun3(int i1,int j,int k,int i2,int i3) { if(((i1==0)&&(i2==10)&&(i3==10)&&(((j%7==(k%7)) ||((j-(j%7))==(k-(k%7))))))&&(((j-k)==2) ||((k-j)==2) ||((j-k)==14) ||((k-j)==14))) return 10; return 0; } int fun4() { int graphdriver,graphmode; int registerbgidriver(void(*EGA_driver)(void)); int registerbgidriver(void(*VGA_driver)(void)); detectgraph(&graphdriver,&graphmode); initgraph(&graphdriver,&graphmode,"//turboc2//EGAVGA.BGI"); cleardevice(); setbkcolor(BLACK); m1=getmaxx(); m2=getmaxy(); printf("To quit press'ctrl + C'.For help press w.\n"); printf("For sound on/off press s.\n\nTo save press i.\n\n" "To retrive old game\npress o.\n"); settextstyle(0,0,1); outtextxy(0.58*m1,0.02*m2,"To move rectangle use arrow keys."); outtextxy(0.6*m1,0.06*m2,"To select block press enter."); outtextxy(0.6*m1,0.10*m2,"To move block:With arrow keys"); outtextxy(0.6*m1,0.14*m2,"move rectangle over adjacent"); outtextxy(0.6*m1,0.18*m2,"block and press enter."); outtextxy(0.6*m1,0.67*m2,"for new game press n."); outtextxy(0.6*m1,0.71*m2,"To take back move press t."); outtextxy(0.51*m1,0.78*m2,"To move forward earlier move press f"); outtextxy(0.05*m1,0.80*m2,"you are genius if one block remains"); outtextxy(0.05*m1,0.84*m2,"you are brilliant if two block remains"); outtextxy(0.05*m1,0.88*m2,"you are intelligent if three blocks remain"); outtextxy(0.05*m1,0.92*m2,"Practice more if more than three blocks remain."); settextstyle(0,0,3); outtextxy(0.7*m1,0.85*m2,"SAMEER"); moveto(0.08*m1,0.26*m2); lineto(0.28*m1,0.26*m2); lineto(0.28*m1,0.08*m2); lineto(0.58*m1,0.08*m2); lineto(0.58*m1,0.26*m2); lineto(0.78*m1,0.26*m2); lineto(0.78*m1,0.56*m2); lineto(0.58*m1,0.56*m2); lineto(0.58*m1,0.76*m2); lineto(0.28*m1,0.76*m2); lineto(0.28*m1,0.56*m2); lineto(0.08*m1,0.56*m2); lineto(0.08*m1,0.26*m2); return 0; } int help() { closegraph(); printf("press any key..."); getch(); clrscr(); fun4(); fun5(); return 0; } int fun5() { int m6; for(m6=0;m6<=49;m6++) if((blx[m6]!=0)&&(emp[m6]==10)) fun2(blx[m6],bly[m6]); return 0; }