Created
March 2, 2017 17:55
-
-
Save pethaniakshay/4d7d805a29df374de396287fcafa93bf to your computer and use it in GitHub Desktop.
Sudoku Puzzel with Solver Program.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream.h> | |
#include<conio.h> | |
#include<graphics.h> | |
#include<stdlib.h> | |
#include<string.h> | |
#include "BUTTON.h" | |
#include "mymouse.h" | |
#include "solve.h" | |
#include "play.h" | |
union REGS in2, out2; | |
int mymain2() | |
{ | |
char ch='\0'; | |
int m=5; | |
for(;1;) | |
{ | |
delay(100); | |
if(kbhit()){m=0;} | |
if(m==0) | |
{ | |
x:ch=getche();if(ch==0){goto x;} | |
m=(int)ch; | |
return m; | |
} | |
else | |
{ | |
return 0; | |
} | |
} | |
} | |
int initmouse2() | |
{ | |
in2.x.ax = 5; | |
int86(0X33,&in2,&out2); | |
return ( out5.x.ax ); | |
} | |
int mousehide2() | |
{ | |
in2.x.ax=2; | |
int86(0X33,&in2,&out2); | |
return 1; | |
} | |
void showmouseptr2() | |
{ | |
in2.x.ax = 1; | |
int86(0X33,&in2,&out2); | |
} | |
void getmousepos2(int *button, int *x, int *y) | |
{ | |
in2.x.ax = 5; | |
int86(0X33,&in2,&out2); | |
*button = out2.x.bx; | |
*x = out2.x.cx; | |
*y = out2.x.dx; | |
} | |
int newmouse2(int &x,int &y,int &button) | |
{ | |
int status; | |
int a; | |
status = 1;//initmouse(); | |
if ( status == 0 ) {} | |
else | |
{ | |
showmouseptr2(); | |
getmousepos2(&button,&x,&y); | |
button=0; | |
while(button!=1) | |
{ | |
a=mymain2(); | |
if(a!=0) | |
return a; | |
else | |
getmousepos2(&button,&x,&y); | |
} | |
} | |
return 0; | |
} | |
void setscreen() | |
{ | |
cleardevice(); | |
setbkcolor(7); | |
setcolor(BLUE); | |
for(int i=0;i<10;i++) | |
rectangle(0+i,0+i,639-i,479-i); | |
for(i=0;i<5000;i++) | |
{ | |
putpixel(random(639),random(479),i); | |
} | |
setcolor(BLUE); | |
for(i=0;i<10;i++) | |
rectangle(0+i,0+i,639-i,479-i); | |
} | |
void Welcome() | |
{ | |
delay(2000); | |
for(int i=0;i<639;i++) | |
{ | |
setcolor(RED); | |
line(i,0,i,479); | |
} | |
int j=329; | |
getch(); | |
for(i=309;i!=319;i++) | |
{ | |
setcolor(0); | |
line(i,0,i,479); | |
line(j,0,j,479); | |
delay(50); | |
setcolor(RED); | |
line(i-1,0,i-1,479); | |
line(j+1,0,j+1,479); | |
j--; | |
} | |
i=319; | |
for(j=319;j!=639;j++) | |
{ | |
setcolor(0); | |
line(i,0,i,479); | |
line(j,0,j,479); | |
delay(25); | |
i--; | |
} | |
for( i=10;i<93;i++) | |
{ | |
setcolor(GREEN); | |
line(i,0,i,479); | |
} | |
for( i=547;i<629;i++) | |
{ | |
setcolor(GREEN); | |
line(i,0,i,479); | |
} | |
int z=6,k=0; | |
j=5; | |
setcolor(4); | |
for(i=103;i<537;i++) | |
{ | |
if((i==175)||(i==247)||(i==319)||(i==391)||(i==463)) | |
{ | |
if(j<=6) | |
{ | |
setcolor(j); | |
j++; | |
} | |
else | |
{ | |
setcolor(z); | |
z--; | |
} | |
k=1; | |
} | |
line(i,0,i,479); | |
} | |
setcolor(BLACK); | |
for(int x=170;x<180;x++) | |
line(x,0,x,479); | |
for( x=242;x<252;x++) | |
line(x,0,x,479); | |
for( x=314;x<324;x++) | |
line(x,0,x,479); | |
for( x=386;x<396;x++) | |
line(x,0,x,479); | |
for( x=458;x<468;x++) | |
line(x,0,x,479); | |
for(i=0;i<10;i++) | |
rectangle(103+i,150+i,537-i,329-i); | |
setcolor(YELLOW); | |
for(i=0;i<100;i++) | |
rectangle(113+i,160+i,527-i,319-i); | |
for(i=0;i<5;i++) | |
line(103+i,150,103+i,329); | |
for(i=0;i<5;i++) | |
line(532+i,150,532+i,329); | |
setcolor(BLACK); | |
settextstyle(TRIPLEX_FONT,0,7); | |
outtextxy(160,200,"WEL-COME"); | |
getch(); | |
setcolor(0); | |
j=639,k=479; | |
for(i=0;i<240;i++) | |
{ | |
delay(40); | |
rectangle(i,i,j,k); | |
j--; | |
k--; | |
} | |
} | |
void rku() | |
{ | |
int i,j; | |
setcolor(RED); | |
delay(1000); | |
arc(315,225,45,135,150); | |
for(i=0;i<20;i++) | |
arc(315,225,45,135,150+i); | |
delay(1000); | |
setcolor(WHITE); | |
settextstyle(TRIPLEX_FONT,HORIZ_DIR,13); | |
outtextxy(200,80,"I"); | |
delay(1000); | |
outtextxy(400,80,"I"); | |
setcolor(RED); | |
setcolor(WHITE); | |
delay(500); | |
line(190,206,450,206); | |
delay(500); | |
line(150,209,480,209); | |
delay(500); | |
line(120,212,510,212); | |
settextstyle(TRIPLEX_FONT,HORIZ_DIR,6); | |
delay(500); | |
outtextxy(130,200,"RK.UNIVERSITY"); | |
delay(500); | |
line(120,255,510,255); | |
delay(1000); | |
settextstyle(TRIPLEX_FONT,HORIZ_DIR,2); | |
setcolor(GREEN); | |
outtextxy(130,300,"Project By :"); | |
outtextxy(130,330,"Meet Vaishnani"); | |
outtextxy(130,360,"Dhaval Talpada"); | |
setcolor(0); | |
for(i=0;i<140;i++) | |
{ | |
delay(50); | |
rectangle(100+i,50+i,534-i,260-i); | |
} | |
} | |
int getgamelevel() | |
{ | |
setscreen(); | |
Button b6(319,139,100,1,"Easy\0"); | |
Button b3(319,179,100,1,"Medium\0"); | |
Button b4(319,219,100,1,"Hard\0"); | |
Button b5(319,259,100,1,"Extreme\0"); | |
Button b7(319,299,100,1,"Back\0"); | |
b6.getButton(); | |
b3.getButton(); | |
b4.getButton(); | |
b5.getButton(); | |
b7.getButton(); | |
int x=100,y=100,cl=0; | |
A:newmouse1(x,y,cl); | |
if(b6.limit(x,y)) | |
return 0; | |
else if(b3.limit(x,y)) | |
return 1; | |
else if(b4.limit(x,y)) | |
return 2; | |
else if(b5.limit(x,y)) | |
return 3; | |
else if(b7.limit(x,y)) | |
return 4; | |
else | |
goto A; | |
} | |
int exitconform() | |
{ | |
setscreen(); | |
setcolor(10); | |
for(int i=0;i<100;i++) | |
{ | |
rectangle(318-i-60,239-i+20,318+i+60,239+i-20); | |
} | |
settextstyle(TRIPLEX_FONT,HORIZ_DIR,2); | |
setcolor(12); | |
outtextxy(170,209,"Are you sure want to Exit ??"); | |
Button b1(240,270,30,4,"YES\0"); | |
b1.getButton(); | |
Button b2(400,270,30,4,"NO\0"); | |
b2.getButton(); | |
int x=50,y=50,cl=0; | |
X:newmouse1(x,y,cl); | |
if(b1.limit(x,y)) | |
{ | |
exit(0); | |
} | |
if(b2.limit(x,y)) | |
{ | |
return 1; | |
} | |
goto X; | |
} | |
void printscoreboard() | |
{ | |
setscreen(); | |
ifstream outFile2; | |
outFile2.open("highscore.dat",ios::binary); | |
int i=0,j=10; | |
int obj; | |
outFile2.read((char *) &obj, sizeof(obj)); | |
while(outFile2.read((char *) &name, sizeof(name))) | |
{ | |
// outFile2.read((char *) &name, sizeof(name)); | |
outFile2.read((char *) &gamelevel, sizeof(gamelevel)); | |
outFile2.read((char *) &hour, sizeof(hour)); | |
outFile2.read((char *) &minute, sizeof(minute)); | |
outFile2.read((char *) &second, sizeof(second)); | |
gotoxy(10,j); | |
cout<<name<<" "; | |
if(gamelevel==0) | |
cout<<"easy "<<hour<<":"<<minute<<":"<<second<<"\n"; | |
if(gamelevel==1) | |
cout<<"Medium "<<hour<<":"<<minute<<":"<<second<<"\n"; | |
if(gamelevel==2) | |
cout<<"Hard "<<hour<<":"<<minute<<":"<<second<<"\n"; | |
if(gamelevel==3) | |
cout<<"Extreame "<<hour<<":"<<minute<<":"<<second<<"\n"; | |
i++; | |
j++; | |
} | |
outFile2.close(); | |
getch(); | |
} | |
void printinstruction() | |
{ | |
setscreen(); | |
gotoxy(25,5); | |
cout<<"Instruction"; | |
gotoxy(10,7); | |
cout<<"You have to fill all the cell by filling integer number from 1 to 9"; | |
gotoxy(10,8); | |
cout<<"Every 3X3 box contains 1 to 9 numbers which can not be repeted"; | |
gotoxy(10,9); | |
cout<<"Every row contains 1 to 9 numbers which can not be repeted"; | |
gotoxy(10,10); | |
cout<<"Every column contains 1 to 9 numbers which can not be repeted"; | |
gotoxy(10,12); | |
cout<<"You can move in 3x3 boxes by using arrow key and you have to press "; | |
gotoxy(10,13); | |
cout<<"enter key to move in cell and you can press Esc to move again "; | |
gotoxy(10,14); | |
cout<<"in 3x3 boxes"; | |
gotoxy(10,15); | |
cout<<"you can press tab button to move from one part to other part" ; | |
getch(); | |
} | |
int main() | |
{ | |
int i; | |
int gdriver = DETECT, gmode, errorcode; | |
initgraph(&gdriver, &gmode, "C:\\turboc3\\bgi"); | |
rku(); | |
Welcome(); | |
settextstyle(TRIPLEX_FONT,HORIZ_DIR,2); | |
Y: setscreen(); | |
Button b1(319,219,100,1,"Play Sudoku\0"); | |
Button b2(319,259,100,1,"Solve Sudoku\0"); | |
Button b3(319,299,100,1," Exit\0 "); | |
b1.getButton(); | |
b2.getButton(); | |
b3.getButton(); | |
int x=500,y=200,cl=0; | |
Z: newmouse1(x,y,cl); | |
if(b1.limit(x,y)) | |
{ | |
D: cleardevice(); | |
setscreen(); | |
setcolor(BLUE); | |
Button b6(319,139,100,1,"New Game\0"); | |
Button b3(319,179,100,1,"Load Game\0"); | |
Button b4(319,219,100,1,"Instruction\0"); | |
Button b5(319,259,100,1,"High Score\0"); | |
Button b7(319,299,100,1,"Back\0"); | |
b6.getButton(); | |
b3.getButton(); | |
b4.getButton(); | |
b5.getButton(); | |
b7.getButton(); | |
A: newmouse1(x,y,cl); | |
if(b6.limit(x,y)) | |
{ | |
char name[20]; | |
setscreen(); | |
setcolor(YELLOW); | |
rectangle(220-50,190-20,420+50,290+20); | |
rectangle(221-50,191-20,419+50,289+20); | |
rectangle(222-50,192-20,418+50,288+20); | |
rectangle(223-50,193-20,417+50,287+20); | |
rectangle(224-50,194-20,416+50,286+20); | |
setcolor(GREEN); | |
setfillstyle(SOLID_FILL,LIGHTGREEN); | |
floodfill(320,240,YELLOW); | |
settextstyle(DEFAULT_FONT,0,2); | |
outtextxy(200,200,"ENTER YOUR NAME"); | |
Button q1(230,280,25,1,"OK\0"); | |
Button q2(404,280,55,1,"Cancle\0"); | |
q1.getButton(); | |
q2.getButton(); | |
int x=100,y=100,cl=0; | |
rectangle(200,225,440,255); | |
int i=0; | |
while(1) | |
{ | |
T: int ch=newmouse2(x,y,cl); | |
if((ch>=65 && ch<=90)||(ch>=97 && ch<=122)|| ch==32) | |
{ | |
if(i==0 && (ch>=97 && ch<=122))ch=ch-32; | |
name[i]=(char)ch; | |
i++; | |
} | |
if(ch==8 && i>0) | |
{ | |
setcolor(LIGHTGREEN); | |
outtextxy(210,230,name); | |
i--; | |
name[i]='\0'; | |
setcolor(GREEN); | |
outtextxy(210,230,name); | |
} | |
for(int k=i;k<20;k++) | |
{ | |
name[k]='\0'; | |
} | |
setcolor(2); | |
outtextxy(210,230,name); | |
if(ch==0) | |
{ | |
if(q1.limit(x,y)){mousehide2();break;} | |
else if(q2.limit(x,y)){mousehide2();goto D;} | |
else | |
goto T; | |
} | |
} | |
int gl=getgamelevel(); | |
if(gl==4) | |
{ | |
goto D; | |
} | |
else | |
playgame(name,strlen(name),gl); | |
goto D; | |
} | |
if(b7.limit(x,y)) | |
{ | |
goto Y; | |
} | |
if(b3.limit(x,y)) | |
{ | |
playgame("",0,0,1); | |
goto D; | |
} | |
if(b4.limit(x,y)) | |
{ | |
printinstruction(); | |
goto D; | |
} | |
if(b5.limit(x,y)) | |
{ | |
printscoreboard(); | |
goto D; | |
} | |
goto A; | |
} | |
if(b2.limit(x,y)) | |
{ | |
solvesudoku(); | |
goto Y; | |
} | |
if(b3.limit(x,y)) | |
{ | |
exitconform(); | |
goto Y; | |
} | |
goto Z; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<graphics.h> | |
#include<conio.h> | |
#include<dos.h> | |
#include<time.h> | |
union REGS i, o; | |
int initmouse1() | |
{ | |
i.x.ax = 5; | |
int86(0X33,&i,&o); | |
return ( o.x.ax ); | |
} | |
void showmouseptr1() | |
{ | |
i.x.ax = 1; | |
int86(0X33,&i,&o); | |
} | |
void getmousepos1(int *button, int *x, int *y) | |
{ | |
i.x.ax = 5; | |
int86(0X33,&i,&o); | |
*button = o.x.bx; | |
*x = o.x.cx; | |
*y = o.x.dx; | |
} | |
void newmouse1(int &x,int &y,int &button) | |
{ | |
int status; | |
status = 1;//initmouse(); | |
if ( status == 0 ) {} | |
else | |
{ | |
showmouseptr1(); | |
getmousepos1(&button,&x,&y); | |
button=0; | |
while(button!=1) | |
{ | |
getmousepos1(&button,&x,&y); | |
} | |
} | |
{ | |
i.x.ax=2; | |
int86(51,&i,&o); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream.h> | |
#include<conio.h> | |
#include<graphics.h> | |
#include<stdlib.h> | |
#include<stdio.h> | |
#include<fstream.h> | |
#include "class.h" | |
#include "mou2.h" | |
#include<time.h> | |
#include<dos.h> | |
#include<alloc.h> | |
time_t firstt, secondt; | |
int temp[9][9],copya[9][9],sol[9][9]; | |
char name[20]; | |
int nl=0,gamelevel=0; | |
int setboxx1=285,setboxy1=235; | |
int l=210,save=1; | |
int hour=0,minute=0,second=0,sd1=0,sd2=0,md1=0,md2=0,hd1=0,hd2=0; | |
int pminute=0,nsd2=0,ptime=0,pn=10,soln=0; | |
char ch[9]="\0"; | |
void far *image; | |
void far *image1; | |
void far *image2; | |
void printtime() | |
{ | |
secondt=time(NULL); | |
second=difftime(secondt,firstt+ptime); | |
if(difftime(secondt,firstt+ptime)>=60) | |
{ | |
second=0; | |
minute=minute+1; | |
firstt=firstt+60; | |
} | |
if(minute>=60) | |
{ | |
minute=0; | |
hour=hour+1; | |
} | |
sd1=second%10; | |
sd2=second/10; | |
md1=minute%10; | |
md2=minute/10; | |
hd1=hour%10; | |
hd2=hour/10; | |
ch[0]=hd2+48; | |
ch[1]=hd1+48; | |
ch[2]=':'; | |
ch[3]=md2+48; | |
ch[4]=md1+48; | |
ch[5]=':'; | |
ch[6]=sd2+48; | |
ch[7]=sd1+48; | |
ch[8]='\0'; | |
if(pminute==minute) | |
{ | |
if(nsd2==sd2) | |
{ | |
setcolor(8); | |
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3); | |
putimage(590,120,image2,COPY_PUT); | |
outtextxy(510,125,ch); | |
} | |
else | |
{ | |
setcolor(8); | |
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3); | |
putimage(580,120,image,COPY_PUT); | |
outtextxy(510,125,ch); | |
} | |
} | |
else | |
{ | |
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3); | |
putimage(510,120,image1,COPY_PUT); | |
setcolor(8); | |
outtextxy(510,125,ch); | |
} | |
pminute=minute; nsd2=sd2; | |
} | |
void highlight(int n) | |
{ | |
for(int i=0;i<9;i++) | |
for(int j=0;j<9;j++) | |
if(copya[i][j]==pn) | |
{ | |
char ch[2]; | |
ch[0]=pn+48; | |
ch[1]='\0'; | |
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3); | |
setcolor(10); | |
outtextxy(i*40+120,j*40+60,ch); | |
} | |
for(i=0;i<9;i++) | |
for(j=0;j<9;j++) | |
if(copya[i][j]==n) | |
{ | |
char ch[2]; | |
ch[0]=n+48; | |
ch[1]='\0'; | |
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3); | |
setcolor(4); | |
outtextxy(i*40+120,j*40+60,ch); | |
} | |
pn=n; | |
} | |
int newmouse51(int &x,int &y,int &button) | |
{ | |
int status; | |
int a; | |
status = 1;//initmouse(); | |
if ( status == 0 ) {} | |
else | |
{ | |
showmouseptr5(); | |
getmousepos5(&button,&x,&y); | |
button=0; | |
a=mymain5(); | |
if(a==9) | |
return a; | |
else | |
getmousepos5(&button,&x,&y); | |
} | |
return 0; | |
} | |
int boxlimit1(int i,int j) | |
{ | |
if((i>=165)&&(i<=405)&&(j>=115)&&(j<=355)) | |
return 1; | |
else | |
return 0; | |
} | |
void setbox1(int i,int j) | |
{ | |
setboxx1=i; | |
setboxy1=j; | |
} | |
int smallboxlimit1(int i,int j) | |
{ | |
if((i>=setboxx1-40)&&(i<=setboxx1+40)&&(j>=setboxy1-40)&&(j<=setboxy1+40)) | |
return 1; | |
else | |
return 0; | |
} | |
void bigboxborder1(int x,int y,int z=0) | |
{ | |
if(z==0) | |
setcolor(YELLOW); | |
else | |
setcolor(z); | |
rectangle(x-60,y-60,x+60,y+60); | |
rectangle(x-59,y-59,x+59,y+59); | |
rectangle(x-58,y-58,x+58,y+58); | |
} | |
void smallboxborder1(int x,int y,int z=0) | |
{ | |
if(z==0) | |
setcolor(YELLOW); | |
else | |
setcolor(z); | |
rectangle(x-16,y-16,x+16,y+16); | |
rectangle(x-17,y-17,x+17,y+17); | |
rectangle(x-15,y-15,x+15,y+15); | |
} | |
void smallrect1(int x ,int y,int size,int cl,int no) | |
{ | |
char ch[2]; | |
ch[0]=no+48; | |
ch[1]='\0'; | |
setcolor(cl); | |
rectangle(x-size-2,y-size-2,x+size-2,y+size-2); | |
setfillstyle(SOLID_FILL,cl); | |
floodfill(x,y,cl); | |
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3); | |
setcolor(10); | |
outtextxy(x-5,y-15,ch); | |
setcolor(RED); | |
rectangle(x-size-2,y-size-2,x+size-2,y+size-2); | |
rectangle(x-size-1,y-size-1,x+size-1,y+size-1); | |
rectangle(x-size,y-size,x+size,y+size); | |
setcolor(cl); | |
} | |
void smallrect1(int x ,int y,int size,int cl,char *no) | |
{ | |
setcolor(cl); | |
rectangle(x-size-2,y-size-2,x+size-2,y+size-2); | |
setfillstyle(SOLID_FILL,cl); | |
floodfill(x,y,cl); | |
setcolor(WHITE); | |
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3); | |
outtextxy(x-5,y-15,no); | |
setcolor(RED); | |
rectangle(x-size-2,y-size-2,x+size-2,y+size-2); | |
rectangle(x-size-1,y-size-1,x+size-1,y+size-1); | |
rectangle(x-size,y-size,x+size,y+size); | |
setcolor(cl); | |
} | |
void settempno1(int i,int j,int color,int no) | |
{ | |
if(copya[(i-125)/40][(j-75)/40]==0) | |
{ | |
char ch[2]; | |
ch[0]=no+48; | |
ch[1]='\0'; | |
char oldno[2]; | |
oldno[0]=temp[(i-125)/40][(j-75)/40]+48; | |
oldno[1]='\0'; | |
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3); | |
setcolor(color); | |
outtextxy(i-5,j-15,oldno); | |
if(no!=0) | |
{ | |
setcolor(WHITE); | |
outtextxy(i-5,j-15,ch); | |
} | |
temp[(i-125)/40][(j-75)/40]=no; | |
} | |
} | |
void printothernumbers1() | |
{ | |
for(int i=0;i<9;i++) | |
for(int j=0;j<9;j++) | |
{ | |
if(temp[i][j]!=0) | |
{ | |
char ch[2]; | |
ch[0]=temp[i][j]+48; | |
ch[1]='\0'; | |
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3); | |
setcolor(WHITE); | |
outtextxy(i*40+120,j*40+60,ch); | |
} | |
} | |
} | |
int newgetch1() | |
{ | |
char ch='\0'; | |
int m=5; | |
for(;1;) | |
{ | |
delay(100); | |
if(kbhit()){m=0;} | |
if(m==0) | |
{ | |
x:ch=getche();if(ch==0){goto x;} | |
m=(int)ch; | |
return m; | |
} | |
else | |
{ | |
return 0; | |
} | |
} | |
} | |
int bigboxbordermove1(int &i,int &j) | |
{ | |
int a=0,count=0,oldi,oldj;int colorcounter=0,color; | |
if((i==285&&(j==115||j==355))||((i==165||i==405)&&j==235)) | |
color=5; | |
else | |
color=3; | |
while(1) | |
{ | |
oldi=i; | |
oldj=j; | |
S: a=newgetch1(); | |
printtime(); | |
switch(a) | |
{ | |
case 72:i=i;j=j-120; | |
if(boxlimit1(i,j)) | |
bigboxborder1(i,j); | |
else | |
{ | |
i=i;j=j+120; | |
count++; | |
} | |
break; | |
case 80:i=i;j=j+120; | |
if(boxlimit1(i,j)) | |
bigboxborder1(i,j); | |
else{i=i;j=j-120;count++;} | |
break; | |
case 75:i=i-120;j=j; | |
if(boxlimit1(i,j)) | |
bigboxborder1(i,j); | |
else{ i=i+120;count++;} | |
break; | |
case 77:i=i+120;j=j; | |
if(boxlimit1(i,j)) | |
bigboxborder1(i,j); | |
else {i=i-120;count++;} | |
break; | |
case 13: break; | |
case 27: break; | |
default:goto S; | |
} | |
if(count==0) | |
{ | |
if(color==3) | |
{ | |
if(colorcounter%2==0) | |
bigboxborder1(oldi,oldj,3); | |
else | |
bigboxborder1(oldi,oldj,5); | |
colorcounter++; | |
} | |
else | |
{ | |
if(colorcounter%2==0) | |
bigboxborder1(oldi,oldj,5); | |
else | |
bigboxborder1(oldi,oldj,3); | |
colorcounter++; | |
} | |
} | |
count=0; | |
if(a==13)return 2; | |
if(a==27)return 1; | |
} | |
} | |
int smallboxbordermove1(int i,int j) | |
{ | |
int a=0; | |
int oldi=i,oldj=j; | |
int count=0,color=0; | |
setbox1(i,j); | |
if((i==285&&(j==115||j==355))||((i==165||i==405)&&j==235)) | |
color=5; | |
else | |
color=3; | |
while(1) | |
{ | |
oldi=i; | |
oldj=j; | |
X: a=newgetch1(); | |
printtime(); | |
switch(a) | |
{ | |
case 72:i=i;j=j-40; | |
if(smallboxlimit1(i,j)) | |
smallboxborder1(i,j); | |
else | |
{ | |
i=i;j=j+40; | |
count++; | |
} | |
break; | |
case 80:i=i;j=j+40; | |
if(smallboxlimit1(i,j)) | |
smallboxborder1(i,j); | |
else{i=i;j=j-40;count++;} | |
break; | |
case 75:i=i-40;j=j; | |
if(smallboxlimit1(i,j)) | |
smallboxborder1(i,j); | |
else{ i=i+40;count++;} | |
break; | |
case 77:i=i+40;j=j; | |
if(smallboxlimit1(i,j)) | |
smallboxborder1(i,j); | |
else {i=i-40;count++;} | |
break; | |
case 27:break; | |
case 48:settempno1(i,j,color,0); | |
count++; | |
break; | |
case 49:settempno1(i,j,color,1); | |
count++; | |
break; | |
case 50:settempno1(i,j,color,2); | |
count++; | |
break; | |
case 51:settempno1(i,j,color,3); | |
count++; | |
break; | |
case 52:settempno1(i,j,color,4); | |
count++; | |
break; | |
case 53:settempno1(i,j,color,5); | |
count++; | |
break; | |
case 54:settempno1(i,j,color,6); | |
count++; | |
break; | |
case 55:settempno1(i,j,color,7); | |
count++; | |
break; | |
case 56:settempno1(i,j,color,8); | |
count++; | |
break; | |
case 57:settempno1(i,j,color,9); | |
count++; | |
break; | |
default:goto X; | |
} | |
if(count==0) | |
{ | |
smallboxborder1(oldi,oldj,color); | |
} | |
count=0; | |
if(a==27)return 1; | |
} | |
} | |
void mainmidboxborder1(int cl=0) | |
{ | |
if(cl==0) | |
setcolor(YELLOW); | |
else | |
setcolor(cl); | |
rectangle(85,35,485,435); | |
rectangle(86,36,484,434); | |
rectangle(87,37,483,433); | |
rectangle(88,38,482,432); | |
rectangle(89,39,481,431); | |
} | |
void moveto1(int); | |
void activerightpart1() | |
{ | |
printtime(); | |
int x=550,y=300,cl=0; | |
mainmidboxborder1(6); | |
Button b1(550,280,70,1,"Finish\0"); | |
b1.getButton(); | |
Button b2(550,360,70,1,"Save\0"); | |
b2.getButton(); | |
Button b3(550,400,70,1,"Cancle\0"); | |
b3.getButton(); | |
Button b4(550,320,70,1,"Solve\0"); | |
b4.getButton(); | |
H: int n=0; | |
for(;1;) | |
{ | |
printtime(); | |
n=newmouse51(x,y,cl); | |
if(n==9 || cl!=0)break; | |
} | |
if(n==9) | |
{ | |
mousehide5(); | |
b1.hidebutton(6); | |
b2.hidebutton(6); | |
b3.hidebutton(6); | |
b4.hidebutton(6); | |
moveto1(2); | |
return; | |
} | |
if(cl==1) | |
{ | |
if(b3.limit(x,y)) | |
{ | |
return; | |
} | |
if(b2.limit(x,y)) | |
{ | |
if(save==1) | |
{ | |
ofstream outFile; | |
outFile.open("savegame.dat",ios::binary); | |
outFile.write((char *) ©a, sizeof(copya)); | |
outFile.write((char *) &temp, sizeof(temp)); | |
outFile.write((char *) &sol,sizeof(sol)); | |
outFile.write((char *) &hour,sizeof(hour)); | |
outFile.write((char *) &minute,sizeof(minute)); | |
outFile.write((char *) &second,sizeof(second)); | |
outFile.close(); | |
} | |
goto H; | |
} | |
if(b1.limit(x,y)) | |
{ | |
int c=0; | |
for(int i=0;i<9;i++) | |
for(int j=0;j<9;j++) | |
{ | |
if(copya[i][j]==0) | |
if(temp[i][j]==0) | |
c++; | |
} | |
if(c!=0 && soln==0) | |
{ | |
settextstyle(DEFAULT_FONT,HORIZ_DIR,2); | |
setcolor(4); | |
outtextxy(50,449,"Please first fill all the cell"); | |
Button b(580,449,25,1,"OK\0"); | |
b.getButton(); | |
E: newmouse51(x,y,cl); | |
if(b.limit(x,y)) | |
{ | |
setcolor(6); | |
outtextxy(50,449,"Please first fill all the cell"); | |
mousehide5(); | |
b.hidebutton(6); | |
} | |
else | |
goto E; | |
} | |
c=0; | |
/* for(i=0;i<9;i++) | |
for(j=0;j<9;j++) | |
if(sol[i][j]==temp[i][j] || sol[i][j]==copya[i][j]) {} | |
else | |
c++; */ | |
for(i=0;i<9;i++) | |
for(j=0;j<9;j++) | |
for(int k=j+1;k<9;k++) | |
if(copya[i][j]==0) | |
if(temp[i][j]==temp[i][k])c++; | |
for(i=0;i<9;i++) | |
for(j=0;j<9;j++) | |
for(k=i+1;k<9;k++) | |
if(copya[i][j]==0) | |
if(temp[i][j]==temp[k][j])c++; | |
if(c==0) | |
{ | |
for(int q=0;q<150;q++) | |
{ | |
setcolor(WHITE); | |
delay(10); | |
rectangle(265-q,235-q+50,265+q,235+q-50); | |
} | |
setcolor(BLACK); | |
settextstyle(GOTHIC_FONT,HORIZ_DIR,3); | |
setcolor(GREEN); | |
outtextxy(190,150,"Congratulation"); | |
settextstyle(GOTHIC_FONT,HORIZ_DIR,2); | |
outtextxy(150,190,"You have solved "); | |
outtextxy(150,215," game "); | |
int obj=0; | |
ifstream outFile; | |
outFile.open("highscore.dat",ios::binary); | |
outFile.read((char *) &obj,sizeof(obj)); | |
obj=obj+1; | |
outFile.close(); | |
ofstream outFile1; | |
outFile1.open("highscore.dat",ios::binary); | |
outFile1.write((char *) &obj,sizeof(obj)); | |
outFile1.close(); | |
ofstream outFile2; | |
outFile2.open("highscore.dat",ios::binary|ios::app); | |
outFile2.write((char *) &name, sizeof(name)); | |
outFile2.write((char *) &gamelevel, sizeof(gamelevel)); | |
outFile2.write((char *) &hour, sizeof(hour)); | |
outFile2.write((char *) &minute, sizeof(minute)); | |
outFile2.write((char *) &second, sizeof(second)); | |
outFile2.close(); | |
} | |
goto H; | |
} | |
if(b4.limit(x,y)) | |
{ | |
if(save==1) | |
{ | |
for(int i=0;i<9;i++) | |
for(int j=0;j<9;j++) | |
{ | |
if(copya[i][j]==0) | |
{ | |
char ch[2]; | |
ch[0]=sol[i][j]+48; | |
ch[1]='\0'; | |
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3); | |
setcolor(WHITE); | |
outtextxy(i*40+120,j*40+60,ch); | |
} | |
} | |
save=0;soln=1; | |
} | |
for(int m=0;m<9;m++) | |
for(int n=0;n<9;n++) | |
{ | |
copya[m][n]=0; | |
temp[m][n]=0; | |
sol[m][n]=0; | |
} | |
ofstream outFile; | |
outFile.open("savegame.dat",ios::binary); | |
outFile.write((char *) ©a, sizeof(copya)); | |
outFile.write((char *) &temp, sizeof(temp)); | |
outFile.write((char *) &sol,sizeof(sol)); | |
outFile.write((char *) &name,sizeof(name)); | |
outFile.write((char *) &gamelevel,sizeof(gamelevel)); | |
outFile.close(); | |
goto H; | |
} | |
if(!b1.limit(x,y) && !b2.limit(x,y) && !b3.limit(x,y) && !b4.limit(x,y)) | |
goto H; | |
} | |
} | |
void activeleftpart1() | |
{ | |
static int i=5; | |
while(1) | |
{ | |
printtime(); | |
int n=newgetch1(); | |
if(n==9) | |
{ | |
highlight(i); | |
moveto1(0); | |
return; | |
} | |
smallrect1(45,l,20,5,i); | |
if(n==80) | |
{ | |
if(i<9) | |
{ | |
l=l+35; | |
i++; | |
smallrect1(45,l-35,20,3,i-1); | |
} | |
} | |
if(n==72) | |
{ | |
if(i>1) | |
{ | |
l=l-35; | |
i--; | |
smallrect1(45,l+35,20,3,i+1); | |
} | |
} | |
} | |
} | |
void activemidboxpart1() | |
{ | |
mainmidboxborder1(); | |
int i=285,j=235; | |
X: bigboxborder1(i,j); | |
int a=bigboxbordermove1(i,j); | |
while(1) | |
{ | |
if(a==2) | |
{ | |
smallboxborder1(i,j); | |
int b=smallboxbordermove1(i,j); | |
if(b==1) | |
goto X; | |
} | |
if(a==1) | |
{ | |
// mainmidboxborder(); | |
for(;1;) | |
{ | |
int s=newgetch1(); | |
if(s==9) | |
{ | |
moveto1(1); | |
return; | |
} | |
if(s==13) | |
{ | |
goto X; | |
} | |
printtime(); | |
} | |
} | |
} | |
} | |
void moveto1(int n) | |
{ | |
if(n==1) | |
{ | |
mainmidboxborder1(6); | |
activerightpart1(); | |
return; | |
} | |
else if(n==0) | |
{ | |
activemidboxpart1(); | |
} | |
if(n==2) | |
{ | |
activeleftpart1(); | |
} | |
} | |
void playgame(char n[],int length,int level,int loadgame=0) | |
{ | |
firstt=0; secondt=0;ptime=0;soln=0; | |
gamelevel=level; | |
setboxx1=285;setboxy1=235; | |
l=210,save=1; hour=0;minute=0;second=0;sd1=0;sd2=0;md1=0;md2=0;hd1=0;hd2=0; | |
pminute=0;nsd2=0;ptime=0;pn=10; | |
for(int p=0;p<9;p++) | |
ch[p]='\0'; | |
int i; | |
for(i=0;i<length;i++) | |
name[i]=n[i]; | |
cleardevice(); | |
setbkcolor(6); | |
for(i=0;i<10;i++) | |
rectangle(0+i,0+i,639-i,479-i); | |
setcolor(7); | |
for(i=0;i<10;i++) | |
rectangle(0+i,0+i,639-i,479-i); | |
int copya2[9][9],temp2[9][9],sol2[9][9],hour1,minute1,second1; | |
if(loadgame!=0) | |
{ | |
ifstream inFile; | |
inFile.open("savegame.dat",ios::binary); | |
if(!inFile) | |
{ | |
cout<<"File could not be open !! Press any Key..."; | |
return; | |
} | |
int filecount=0; | |
inFile.read((char *) ©a2, sizeof(copya)); | |
for(int m=0;m<9;m++) | |
for(int n=0;n<9;n++) | |
if(copya2[m][n]!=0)filecount++; | |
inFile.read((char *) &temp2, sizeof(temp)); | |
for(m=0;m<9;m++) | |
for( n=0;n<9;n++) | |
if(temp2[m][n]!=0)filecount++; | |
inFile.read((char *) &sol2, sizeof(sol)); | |
for(m=0;m<9;m++) | |
for( n=0;n<9;n++) | |
if(sol2[m][n]!=0)filecount++; | |
inFile.read((char *) &hour1,sizeof(hour)); | |
hour=hour1; | |
inFile.read((char *) &minute1,sizeof(minute)); | |
minute=minute1; | |
inFile.read((char *) &second1,sizeof(second)); | |
second=second1; | |
inFile.read((char *) &name,sizeof(name)); | |
inFile.read((char *) &level,sizeof(level)); | |
inFile.close(); | |
if(filecount==0) | |
{ | |
for(int q=0;q<150;q++) | |
{ | |
setcolor(WHITE); | |
delay(10); | |
rectangle(265-q,235-q+50,265+q,235+q-50); | |
} | |
setcolor(BLACK); | |
settextstyle(DEFAULT_FONT,HORIZ_DIR,3); | |
setcolor(GREEN); | |
outtextxy(190,150,"Sorry!!!"); | |
settextstyle(DEFAULT_FONT,HORIZ_DIR,2); | |
outtextxy(150,190,"You have Solved "); | |
outtextxy(150,215," game lasttime "); | |
getch(); | |
return; | |
} | |
ptime=hour*3600+minute*60+second; | |
} | |
setcolor(3); | |
i=1; | |
for(int l=75;l<=75+35*8;l=l+35) | |
smallrect1(45,l,20,3,i++); | |
if(loadgame==0) | |
{ | |
Generator hard(level); | |
hard.sudokugenerate(); | |
hard.sudokugenerate(); | |
for(int m=0;m<9;m++) | |
for(int n=0;n<9;n++) | |
{ | |
temp[m][n]=0; | |
copya[m][n]=hard.a[n][m]; | |
sol[m][n]=hard.b[n][m]; | |
} | |
} | |
else | |
{ | |
ifstream inFile; | |
inFile.open("savegame.dat",ios::binary); | |
if(!inFile) | |
{ | |
cout<<"File could not be open !! Press any Key..."; | |
return; | |
} | |
inFile.read((char *) ©a2, sizeof(copya)); | |
for(int m=0;m<9;m++) | |
for(int n=0;n<9;n++) | |
copya[m][n]=copya2[m][n]; | |
inFile.read((char *) &temp2, sizeof(temp)); | |
for(m=0;m<9;m++) | |
for( n=0;n<9;n++) | |
temp[m][n]=temp2[m][n]; | |
inFile.read((char *) &sol2, sizeof(sol)); | |
for(m=0;m<9;m++) | |
for( n=0;n<9;n++) | |
sol[m][n]=sol2[m][n]; | |
inFile.close(); | |
} | |
mainmidboxborder1(); | |
int k=3; | |
for(i=0;i<9;i++) | |
for(int j=0;j<9;j++) | |
{ | |
if(copya[j][i]!=0) | |
smallrect1(125+j*40,75+i*40,20,k,copya[j][i]); | |
else | |
smallrect1(125+j*40,75+i*40,20,k,""); | |
k=3; | |
} | |
Button b1(560,100,60,8," Time\0"); | |
b1.getButton(); | |
for(i=0;i<9;i++) | |
for(j=0;j<9;j++) | |
{ | |
if((j==3||j==4||j==5)&&(i==0||i==1||i==2||i==6||i==7||i==8)) | |
{ | |
k=5; | |
if(copya[j][i]!=0) | |
smallrect1(125+j*40,75+i*40,20,k,copya[j][i]); | |
else | |
smallrect1(125+j*40,75+i*40,20,k,""); | |
} | |
} | |
for(i=0;i<9;i++) | |
for(j=0;j<9;j++) | |
{ | |
if((j==0||j==1||j==2||j==6||j==7||j==8)&&(i==3||i==4||i==5)) | |
{ | |
k=5; | |
if(copya[j][i]!=0) | |
smallrect1(125+j*40,75+i*40,20,k,copya[j][i]); | |
else | |
smallrect1(125+j*40,75+i*40,20,k,""); | |
} | |
} | |
long size=imagesize(580,120,620,150); | |
image= farmalloc(size); | |
getimage(580,120,620,150,image); | |
image1=farmalloc(size*2); | |
getimage(510,120,580,150,image1); | |
size=imagesize(600,120,620,150); | |
image2=farmalloc(size); | |
getimage(600,120,620,150,image2); | |
printothernumbers1(); | |
setcolor(6); | |
rectangle(105,55,465,415); | |
rectangle(106,56,464,414); | |
rectangle(107,57,463,413); | |
rectangle(104,54,466,416); | |
rectangle(103,53,467,417); | |
firstt = time(NULL)-ptime; | |
mainmidboxborder1(); | |
activemidboxpart1(); | |
mousehide5(); | |
delete image; | |
delete image1; | |
delete image2; | |
return; | |
} | |
/* while(1) | |
{ | |
int z=getch(); | |
if(z==13) | |
{ | |
i=295,j=235; | |
int bb=0,aa; | |
bigboxborder(i,j); | |
aa=bigboxbordermove(i,j); | |
/// code for mainbox selection | |
while(1) | |
{ | |
if(aa==2) | |
{ | |
smallboxborder(i,j); | |
bb=smallboxbordermove(i,j); | |
if(bb==1){bigboxborder(i,j); aa=bigboxbordermove(i,j); } | |
} | |
else if(aa==1) | |
{ | |
int temp2[9][9]; | |
for( m=0;m<9;m++) | |
for(n=0;n<9;n++) | |
{ | |
temp2[n][m]=temp[m][n]; | |
} | |
for( m=0;m<9;m++) | |
for(n=0;n<9;n++) | |
{ | |
temp[m][n]=temp2[m][n]; | |
} | |
for( m=0;m<9;m++) | |
for(n=0;n<9;n++) | |
{ | |
if(hard.a[m][n]!=0) | |
temp[m][n]=hard.a[m][n]; | |
} | |
moveto(1); | |
break; | |
} | |
} | |
} | |
else if(z==27){ leftboxborder();exit(0);} | |
} | |
} */ | |
/* int temp2[9][9]; | |
for(int m=0;m<9;m++) | |
for(int n=0;n<9;n++) | |
{ | |
temp2[n][m]=temp[m][n]; | |
} | |
for( m=0;m<9;m++) | |
for(n=0;n<9;n++) | |
{ | |
temp[m][n]=temp2[m][n]; | |
} | |
for( m=0;m<9;m++) | |
for(n=0;n<9;n++) | |
{ | |
if(copya[m][n]!=0) | |
temp[m][n]=copya[m][n]; | |
}*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream.h> | |
#include<conio.h> | |
#include<graphics.h> | |
#include<stdlib.h> | |
#include<stdio.h> | |
#include<dos.h> | |
#include "mou.h" | |
#include<time.h> | |
time_t solendtime,solstarttime; | |
int setboxx=265,setboxy=235,gcount=0; | |
int grid[9][9],grid2[9][9]; | |
static int nsol = 0; | |
int printsol=0,cu=2; | |
int x=300,y=250,cl=0; | |
void print_solution(void) | |
{ | |
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3); | |
int r, c; | |
nsol++; | |
for (r = 0; r < 9; r++) | |
for (c = 0; c < 9; c++) | |
{ | |
char ch[2]; | |
ch[0]=grid[r][c]+48; | |
ch[1]='\0'; | |
setcolor(WHITE); | |
outtextxy(105+r*40-5,c*40+75-15,ch); | |
} | |
} | |
int safe(int row, int col, int n) | |
{ | |
int r, c, br, bc; | |
if (grid[row][col] == n) return 1; | |
if (grid[row][col] != 0) return 0; | |
for (c = 0; c < 9; c++) | |
if (grid[row][c] == n) return 0; | |
for (r = 0; r < 9; r++) | |
if (grid[r][col] == n) return 0; | |
br = row / 3; | |
bc = col / 3; | |
for (r = br * 3; r < (br + 1) * 3; r++) | |
for (c = bc * 3; c < (bc + 1) * 3; c++) | |
if (grid[r][c] == n) return 0; | |
return 1; | |
} | |
int solve(int row, int col) | |
{ | |
int n, t; | |
solendtime=time(NULL); | |
if(difftime(solendtime,solstarttime)>2){gcount++;return 1;} | |
if(nsol==1){ return 0;} | |
if (row == 9) | |
{ | |
printsol=1; | |
print_solution(); | |
return 0; | |
} | |
else | |
for (n = 1; n <= 9; n++) | |
if (safe(row, col, n)) { | |
t = grid[row][col]; | |
grid[row][col] = n; | |
if (col == 8) | |
solve(row + 1, 0); | |
else | |
solve(row, col + 1); | |
grid[row][col] = t; | |
} | |
return 0; | |
} | |
int boxlimit(int i,int j) | |
{ | |
if((i>=145)&&(i<=385)&&(j>=115)&&(j<=355)) | |
return 1; | |
else | |
return 0; | |
} | |
void setbox(int i,int j) | |
{ | |
setboxx=i; | |
setboxy=j; | |
} | |
int smallboxlimit(int i,int j) | |
{ | |
if((i>=setboxx-40)&&(i<=setboxx+40)&&(j>=setboxy-40)&&(j<=setboxy+40)) | |
return 1; | |
else | |
return 0; | |
} | |
void bigboxborder(int x,int y,int z=0) | |
{ | |
if(z==0) | |
setcolor(YELLOW); | |
else | |
setcolor(z); | |
rectangle(x-60,y-60,x+60,y+60); | |
rectangle(x-59,y-59,x+59,y+59); | |
rectangle(x-58,y-58,x+58,y+58); | |
} | |
void smallboxborder(int x,int y,int z=0) | |
{ | |
if(z==0) | |
setcolor(YELLOW); | |
else | |
setcolor(z); | |
rectangle(x-16,y-16,x+16,y+16); | |
rectangle(x-17,y-17,x+17,y+17); | |
rectangle(x-15,y-15,x+15,y+15); | |
} | |
void smallrect(int x ,int y,int size,int cl,int no) | |
{ | |
char ch[2]; | |
ch[0]=no+48; | |
ch[1]='\0'; | |
setcolor(cl); | |
rectangle(x-size-2,y-size-2,x+size-2,y+size-2); | |
setfillstyle(SOLID_FILL,cl); | |
floodfill(x,y,cl); | |
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3); | |
setcolor(10); | |
outtextxy(x-5,y-15,ch); | |
setcolor(RED); | |
rectangle(x-size-2,y-size-2,x+size-2,y+size-2); | |
rectangle(x-size-1,y-size-1,x+size-1,y+size-1); | |
rectangle(x-size,y-size,x+size,y+size); | |
setcolor(cl); | |
} | |
void smallrect(int x ,int y,int size,int cl,char *no) | |
{ | |
setcolor(cl); | |
rectangle(x-size-2,y-size-2,x+size-2,y+size-2); | |
setfillstyle(SOLID_FILL,cl); | |
floodfill(x,y,cl); | |
setcolor(WHITE); | |
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3); | |
outtextxy(x-5,y-15,no); | |
setcolor(RED); | |
rectangle(x-size-2,y-size-2,x+size-2,y+size-2); | |
rectangle(x-size-1,y-size-1,x+size-1,y+size-1); | |
rectangle(x-size,y-size,x+size,y+size); | |
setcolor(cl); | |
} | |
void settempno(int i,int j,int color,int no,int c=0) | |
{ | |
char ch[2]; | |
ch[0]=no+48; | |
ch[1]='\0'; | |
char oldno[2]; | |
if(c==0) | |
oldno[0]=grid[(i-105)/40][(j-75)/40]+48; | |
else | |
oldno[0]=no+48; | |
oldno[1]='\0'; | |
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3); | |
setcolor(color); | |
outtextxy(i-5,j-15,oldno); | |
setcolor(WHITE); | |
if(c==0) | |
{ | |
if(no!=0) | |
outtextxy(i-5,j-15,ch); | |
grid[(i-105)/40][(j-75)/40]=no; | |
} | |
} | |
int bigboxbordermove(int &i,int &j,int a=0) | |
{ | |
int count=0,oldi,oldj;int colorcounter=0,color; | |
if((i==265&&(j==115||j==355))||((i==145||i==385)&&j==235)) | |
color=5; | |
else | |
color=3; | |
oldi=i; | |
oldj=j; | |
switch(a) | |
{ | |
case 72:i=i;j=j-120; | |
if(boxlimit(i,j)) | |
bigboxborder(i,j); | |
else | |
{ | |
i=i;j=j+120; | |
count++; | |
} | |
break; | |
case 80:i=i;j=j+120; | |
if(boxlimit(i,j)) | |
bigboxborder(i,j); | |
else{i=i;j=j-120;count++;} | |
break; | |
case 75:i=i-120;j=j; | |
if(boxlimit(i,j)) | |
bigboxborder(i,j); | |
else{ i=i+120;count++;} | |
break; | |
case 77:i=i+120;j=j; | |
if(boxlimit(i,j)) | |
bigboxborder(i,j); | |
else {i=i-120;count++;} | |
break; | |
case 13: break; | |
case 27: break; | |
default: break; | |
} | |
if(count==0) | |
{ | |
if(color==3) | |
{ | |
if(colorcounter%2==0) | |
bigboxborder(oldi,oldj,3); | |
else | |
bigboxborder(oldi,oldj,5); | |
colorcounter++; | |
} | |
else | |
{ | |
if(colorcounter%2==0) | |
bigboxborder(oldi,oldj,5); | |
else | |
bigboxborder(oldi,oldj,3); | |
colorcounter++; | |
} | |
} | |
count=0; | |
if(a==13){ smallboxborder(i,j);cu=1;return 2; } | |
if(a==27)return 1; | |
return 0; | |
} | |
int smallboxbordermove(int &i,int &j,int newi,int newj,int a=0) | |
{ | |
int oldi=i,oldj=j; | |
int count=0,color=0; | |
setbox(newi,newj); | |
if((newi==265&&(newj==115||newj==355))||((newi==145||newi==385)&&newj==235)) | |
color=5; | |
else | |
color=3; | |
int loopcount=0; | |
oldi=i; | |
oldj=j; | |
if(loopcount==0) | |
{ | |
switch(a) | |
{ | |
case 72:i=i;j=j-40; | |
if(smallboxlimit(i,j)) | |
smallboxborder(i,j); | |
else | |
{ | |
i=i;j=j+40; | |
count++; | |
} | |
break; | |
case 80:i=i;j=j+40; | |
if(smallboxlimit(i,j)) | |
smallboxborder(i,j); | |
else{i=i;j=j-40;count++;} | |
break; | |
case 75:i=i-40;j=j; | |
if(smallboxlimit(i,j)) | |
smallboxborder(i,j); | |
else{ i=i+40;count++;} | |
break; | |
case 77:i=i+40;j=j; | |
if(smallboxlimit(i,j)) | |
smallboxborder(i,j); | |
else {i=i-40;count++;} | |
break; | |
case 27:break; | |
case 48:settempno(i,j,color,0); | |
count++; | |
break; | |
case 49:settempno(i,j,color,1); | |
count++; | |
break; | |
case 50:settempno(i,j,color,2); | |
count++; | |
break; | |
case 51:settempno(i,j,color,3); | |
count++; | |
break; | |
case 52:settempno(i,j,color,4); | |
count++; | |
break; | |
case 53:settempno(i,j,color,5); | |
count++; | |
break; | |
case 54:settempno(i,j,color,6); | |
count++; | |
break; | |
case 55:settempno(i,j,color,7); | |
count++; | |
break; | |
case 56:settempno(i,j,color,8); | |
count++; | |
break; | |
case 57:settempno(i,j,color,9); | |
count++; | |
break; | |
default:break; | |
} | |
if(oldi!=i || oldj!=j) | |
smallboxborder(oldi,oldj,color); | |
count=0; | |
} | |
if(a==27){smallboxborder(oldi,oldj,color);bigboxborder(newi,newj); cu=2;return 1;} | |
return 0; | |
} | |
void mainmidboxborder(int cl=0) | |
{ | |
if(cl==0) | |
setcolor(YELLOW); | |
else | |
setcolor(6); | |
rectangle(65,35,465,435); | |
rectangle(66,36,464,434); | |
rectangle(67,37,463,433); | |
rectangle(68,38,462,432); | |
rectangle(69,39,461,431); | |
} | |
void rightboxborder(int cl=0) | |
{ | |
if(cl==0) | |
setcolor(YELLOW); | |
else | |
setcolor(6); | |
rectangle(470,126,619,294); | |
rectangle(471,127,618,293); | |
rectangle(472,128,617,292); | |
rectangle(473,129,616,291); | |
rectangle(474,130,615,290); | |
} | |
void printbody() | |
{ | |
int k=3; | |
for(int i=0;i<9;i++) | |
for(int j=0;j<9;j++) | |
{ | |
smallrect(105+j*40,75+i*40,20,k,"\0"); | |
k=3; | |
} | |
for( i=0;i<9;i++) | |
for( j=0;j<9;j++) | |
{ | |
if((j==3||j==4||j==5)&&(i==0||i==1||i==2||i==6||i==7||i==8)) | |
{ | |
k=5; | |
smallrect(105+j*40,75+i*40,20,k,"\0"); | |
} | |
} | |
for(i=0;i<9;i++) | |
for(j=0;j<9;j++) | |
{ | |
if((j==0||j==1||j==2||j==6||j==7||j==8)&&(i==3||i==4||i==5)) | |
{ | |
k=5; | |
smallrect(105+j*40,75+i*40,20,k,"\0"); | |
} | |
} | |
} | |
void solvesudoku() | |
{ | |
int i; | |
int gdriver = DETECT, gmode, errorcode; | |
initgraph(&gdriver, &gmode, "C:\\turboc3\\bgi"); | |
setbkcolor(6); | |
cleardevice(); | |
for(i=0;i<10;i++) | |
rectangle(0+i,0+i,639-i,479-i); | |
setcolor(7); | |
for(i=0;i<10;i++) | |
rectangle(0+i,0+i,639-i,479-i); | |
setcolor(3); | |
i=1; | |
printbody(); | |
mainmidboxborder(); | |
setcolor(6); | |
rectangle(85,55,445,415); | |
rectangle(86,56,444,414); | |
rectangle(87,57,443,413); | |
rectangle(84,54,446,416); | |
rectangle(83,53,447,417); | |
Button b1(550,150,60,1,"Solve\0"); | |
b1.getButton(); | |
Button b2(550,190,60,1,"How-To\0"); | |
b2.getButton(); | |
Button b3(550,230,60,1,"Reset\0 "); | |
b3.getButton(); | |
Button b4(550,270,60,1,"Back\0 "); | |
b4.getButton(); | |
H: i=265;int j=235; | |
int newi=i,newj=j; | |
bigboxborder(i,j); | |
while(1) | |
{ | |
int a=newmouse(x,y,cl); | |
if(cl==1) | |
{ | |
if(b1.limit(x,y)) | |
{ | |
int co=0; | |
for(int m=0;m<9;m++) | |
for(int n=0;n<9;n++) | |
{ | |
if(grid[m][n]!=0)co++; | |
} | |
if(co==0) | |
{ | |
settextstyle(DEFAULT_FONT,HORIZ_DIR,2); | |
setcolor(4); | |
outtextxy(50,449,"Please enter elements in the cell"); | |
getch(); | |
setcolor(6); | |
outtextxy(50,449,"Please enter elements in the cell"); | |
goto H; | |
} | |
solstarttime=time(NULL); | |
solve(0,0); | |
if(printsol==0)gcount=1; | |
if(gcount!=0) | |
{ | |
for(int q=0;q<150;q++) | |
{ | |
setcolor(WHITE); | |
delay(10); | |
rectangle(265-q,235-q+50,265+q,235+q-50); | |
} | |
setcolor(BLACK); | |
settextstyle(DEFAULT_FONT,HORIZ_DIR,3); | |
setcolor(GREEN); | |
outtextxy(190,150,"Sorry!!!"); | |
settextstyle(DEFAULT_FONT,HORIZ_DIR,2); | |
outtextxy(150,190,"Solution is not "); | |
outtextxy(150,215," possible "); | |
} | |
} | |
if(b2.limit(x,y)) | |
{ | |
} | |
if(b3.limit(x,y)) | |
{ | |
for(int m=0;m<9;m++) | |
for(int n=0;n<9;n++) | |
{ | |
for(int h=0;h<9;h++) | |
settempno(m*40+105,n*40+75,3,h,1); | |
} | |
for(m=0;m<9;m++) | |
for(n=0;n<9;n++) | |
grid[m][n]=0; | |
cu=2;nsol=0;printsol=0;gcount=0; | |
printbody(); | |
} | |
if(b4.limit(x,y)) | |
{ | |
mousehide(); | |
return; | |
} | |
} | |
else | |
{ | |
if(cu==2) | |
{ | |
bigboxborder(i=newi,j=newj); | |
bigboxbordermove(i=newi,j=newj,a); | |
newi=i; | |
newj=j; | |
} | |
if(cu==1) | |
{ | |
smallboxborder(i,j); | |
smallboxbordermove(i,j,newi,newj,a); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment