


/////////////////////////////////////////////////////////////////////////////
// //
// //
// Programme du jeux su-do-ku REALISER PAR : AHABRI MONSSIF //
// //
/////////////////////////////////////////////////////////////////////////////
#include <graphics.h>
#include<dos.h>
#include<stdio.h>
#include<conio.h>
#include<stdlib.h> // pour utilisez la fonction atoi():::
#include<ctype.h> // utilisez la fonction isdigit():: teste si le caractere est numerique
#include<math.h>
/////////////////////////////////////////////////////////////////////////////////
#define HAUT 0x48 // les code en hexadecimal du curseur en utilisant les fleches du clavier
#define BAS 0x50
#define ECHAP 27
#define GAUCHE 0x4B
#define DROITE 0x4D
#define AVTIVER_AIDE 59
#define DESACTIVER_AIDE 60
#define SOLUTION 61
#define CHANGER_COULEUR 62
#define HELP 63
#define CREATION 64
typedef struct { //utilez dans la fct deplacement du curseur
int xi;
int yi;
} dep;
int t[9][9];
int F[9][9];
//ce tableau utilisez pour les couleurs
//variables global
// les prototype
void curseur(int);
void initialise(int t[9][9] );
int colonnes(int t[9][9],int,int,int);
int ligne(int t[9][9],int,int,int);
int retourdebut(int);
int retourfin(int);
int indicey(int);
int indicex(int);
int verifie(int t[9][9],int ,int ,int);
int valide(int t[9][9],int,int,int);
void grille(int);
void affiche(void);
int calcul(int ,int );
int aff_message_activation_de_l_aide_au_debut(void);
dep deplacement_curseur(int ,dep );
int quitte_le_jeux(int ,int ,int);
void return_a_la_grille(int ,int,int );
void solution(void);
int message_aide_activer(int ,int );
int message_aide_desactiver(int ,int );
int changer_couleur_de_la_grille(void);
void help_sudoku(void);
void creation(void);
void inter(void);
void titre_sudoku(void);
void retour_a_la_case( int m[9][9],int * , int *);
void back(int t[9][9],int *, int * );
void sudo(int t[9][9]);
/////////////////////////////////////////////////////////////////////////////////////////
// //
// PROGRAMME PRINCIPALE
//////////////////////////////////////////////////////////////////////////////////
void main(void)
{
int couleur=0 /* 0: c'est la couleur noir */,active_aide; // pour activer l aide
int indice_d_aide=0,position_de_x=5;
int convertie_en_entier,position_de_y=4;
int i,j,indice=0;
char getch_1,getch_2,mon[2];
dep position;
int tt=10,ff=10;
inter(); // afficher introduction
clrscr();
curseur(0);
textbackground(BLUE);
clrscr();
grille(couleur);
initialise(t);
indice_d_aide=aff_message_activation_de_l_aide_au_debut(); // le premier message activation
textbackground(BLUE);
curseur(1);
clrscr();
grille(couleur);
textcolor(15);
gotoxy(5,4);
position.xi = 5;
position.yi = 4;
do
{
textcolor(15); // couleur du text
textbackground(couleur); // couleur du fond
getch_1 = getch();
if( iscntrl( getch_1) ) // les touche de controle
{
switch(getch_1)
{
case 0:{
getch_2=getch();
if( getch_2 == HAUT || getch_2==BAS || getch_2==GAUCHE || getch_2==DROITE )
{
position = deplacement_curseur(getch_2,position);
position_de_x = position.xi;
position_de_y = position.yi;
}
else
if( getch_2 == AVTIVER_AIDE ) // pour dire que l aide est activer c a d une forme boolean pour test‚
indice_d_aide = message_aide_activer(position_de_x,position_de_y);
else
if(getch_2 == DESACTIVER_AIDE) // L' aide desactive‚
indice_d_aide = message_aide_desactiver(position_de_x,position_de_y);
else
if(getch_2 == SOLUTION) // pour la solution de la grille
{
curseur(0);// desactiver le curseur
if(indice == 0 )
{
solution();
}
else
{
gotoxy(3,23);printf("GRILLE NA PAS DE SOLUTION");}
indice=0;
getch();
titre_sudoku();
getch();
// retour a la grille initiale
textbackground(BLUE);
clrscr();
return_a_la_grille(position_de_x,position_de_y,couleur);
curseur(1);// allumer le curseur
}
else
if(getch_2 == CHANGER_COULEUR)
{
// la trace de la grille
textbackground(RED);
clrscr();
couleur = changer_couleur_de_la_grille();
textbackground(BLUE);
clrscr();
return_a_la_grille(position_de_x,position_de_y,couleur);
}
else
if(getch_2 == HELP)
{
// la trace de la grille
textbackground(RED);
clrscr();
help_sudoku();
getch();
curseur(1);
textbackground(BLUE);
clrscr();
return_a_la_grille(position_de_x,position_de_y,couleur);
}
else
if(getch_2 == CREATION)
{
// la trace de la grille
textbackground(RED);
clrscr();
creation();
getch();
textbackground(BLUE);
clrscr();
return_a_la_grille(position_de_x,position_de_y,couleur);
}
}// end case 0
}// end switch
}// end if iscntrl
else
if (isdigit(getch_1)) // traitement dans le cas que sont des nombre
{ i = indicey(position_de_y);
j = indicex(position_de_x);
mon[0] = getch_1;
mon[1] = '\0';
convertie_en_entier=atoi(mon); // convertir une char a un entier
if(convertie_en_entier == 0) // pour suprimmer un nombre
{ t[i][j] = 0 ;
F[i][j] = 0;
cprintf(" ");
putchar(8);
}
else
if(convertie_en_entier>0 && convertie_en_entier<=9) // le cas que n entre 0 et 9
{
if(indice_d_aide == 1)// si aide est activer en entre dans ce cas
{
if( ( ligne(t,i,j,convertie_en_entier)==0 ) && ( colonnes(t,i,j,convertie_en_entier)==0) && ( verifie(t,convertie_en_entier,i,j)==0 ) )// traitement pour verifier si ce nombre n existe dans la grille
{
t[i][j] = convertie_en_entier ; // partie aide activ‚‚
F[i][j] = convertie_en_entier; // ceci est ajout‚ pour mettre en point les couleur des entr‚
textcolor(YELLOW);
cprintf("%d",convertie_en_entier);// affich‚ dans la grille
putchar(8); // LE RETOUR D UNE CASE EN ARRIRE
}
else
{
}
}
else
{ // partie l'aide d‚sactiver
if((ff==j)&&(tt==i)) indice=0;
if( ( ligne(t,i,j,convertie_en_entier)!=0 ) || ( colonnes(t,i,j,convertie_en_entier)!=0) || ( verifie(t,convertie_en_entier,i,j)!=0 ) )// traitement pour verifier si ce nombre n existe dans la grille
{
indice=1;
tt=i;
ff=j;
}
t[i][j] = convertie_en_entier ;
F[i][j] = convertie_en_entier ;
textcolor(YELLOW);
cprintf("%d",convertie_en_entier);// affiche dans la grille
putchar(8);
}
}//end if de ca convertie_en_entier<9 convertie_en_entier>0
} //end if isdigit
if(getch_1 == ECHAP) {
curseur(0); // c'est ECHAP pour quitt‚ le jeux
getch_1=quitte_le_jeux(position_de_x,position_de_y,couleur);
curseur(1);
}
} //end while
while(getch_1!=ECHAP);
}
///////////////////////////////////////////////////////////////////////////////
//pour afficher curseur -> curseur(1);
//pour desactiver curseur -> curseur(0);
///////////////////////////////////////////////////////////////////////////////
void curseur(int curseur_on)
{
int d,f;
union REGS rin,rout;
if(curseur_on)
{
d=3;f=4;
}
else
{
d=17;f=16;
}
rin.h.ch=d;
rin.h.cl=f;
rin.h.ah=1;
int86(0x10,&rin,&rout);
}
/////////////////////////initialisez la grilles a zero ////////////////////
void initialise(int t[9][9]){
int i ,j;
for(i=0;i<9;i++)
for(j=0;j<9;j++)
t[i][j]=0;
}
////////////////////////////////////////////////////////////////////////////
// //
// traitement colonnes de sudoku fixant le j est parcourant en i //
// //
//////////////////////////////////////////////////////////////////////////
int colonnes(int t[9][9],int i,int j,int element)
{
int k,trouve=0;
for(k=0;k<9;k++)
if(abs(t[k][j])==element && i!=k )
trouve=1; // ELEMENT TROUVE DANS LA COLONNE
return trouve;
}
///////////////////////////////////////////////////////////////////////////
// // //
// Traitement dans LES lignes de sudoku //
// // //
/////////////////////////////////////////////////////////////////////////
int ligne(int t[9][9],int i,int j,int element)
{
int k,trouve=0;
for(k=0;k<9;k++)
if(abs(t[i][k])==element && j!=k )
trouve=1;
return trouve;
}
///////////////////////////////////////////////////////////////////////////////
// //
// DEBUT DE LA REGION //
// //
//////////////////////////////////////////////////////////////////////////////
int retourdebut(int x){
int i;
switch(x){
case 0:
case 1:
case 2:return 0;
case 3:
case 4:
case 5:return 3;
case 6:
case 7:
case 8:return 6;
}
}
///////////////////////////////////////////////////////////////////////////////
// //
// FIN DE LA REGION //
// //
////////////////////////////////////////////////////////////////////////////
int retourfin(int y){
int i;
switch(y){
case 0:
case 1:
case 2:return 2;
case 3:
case 4:
case 5:return 5;
case 6:
case 7:
case 8:return 8;
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////
// /
// Cette fonction nous donne une convertion du gotoxy a indice du tableaux ce qui concerne le i /
// /
//////////////////////////////////////////////////////////////////////////////////////////////////
int indicey(int y)
{
int i;
if (y==4)
{
i=0;
}
if(y>4)
{
i=0;
do{
y=y-2;
i++;
}
while(y!=4);
}
return i;
}
////////////////////////////////////////////////////////////////////////////////////////////////
// /
// cette fonction nous donne une convertion du gotoxy a indice du tableaux ce qui concerne le j /
// /
////////////////////////////////////////////////////////////////////////////////////////////////
int indicex(int x)
{
int j;
if (x==5){
j=0;
}
if (x>5)
{
j=0;
do{
x=x-4;
j++;
}
while(x!=5);
}
return j;
}
///////////////////////////////////////////////////////////////////////////////
// //
// VERIFICATION DANS LES REGION //
// //
////////////////////////////////////////////////////////////////////////////
int verifie(int t[9][9],int element,int i,int j){
int k,f,l=0 ;
int ki,kj,li,lj;
ki=retourdebut(i);
li=retourfin(i); // pour l intervalle i voir sont debut est ca fin
kj=retourdebut(j);
lj=retourfin(j);
for(k=ki;k<=li;k++)
for(f=kj;f<=lj;f++)
if(abs(t[k][f])==element && k!=i && f!=j) {l=1;}
return l;
}
/////////////////////////////////////////////////////////////////////////////
// /
// affichage de la grille /
// /
//////////////////////////////////////////////////////////////////////////////
void grille(int couleur)
{
int i,j;
textbackground(18);
textcolor(BLACK);
textattr(3);
gotoxy(2,1);cprintf(" ECHAP:");
textcolor(15);
gotoxy(10,1);cprintf("Quitter le jeux ");
textcolor(BLACK);
textattr(3);
gotoxy(32,1);cprintf(" F1:");
textcolor(15);
gotoxy(36,1);cprintf(" L'AIDE ACTIVER ");
textcolor(BLACK);
textattr(3);
gotoxy(55,1);cprintf(" F2:");
textcolor(15);
gotoxy(59,1);cprintf(" L'AIDE DESACTIVER");
textcolor(BLACK);
textattr(3);
gotoxy(49,7);cprintf("F3:");
textcolor(15);
gotoxy(52,7);cprintf(" SOLUTION DE LA GRILLE");
textcolor(BLACK);
textattr(3);
gotoxy(49,9);cprintf("F4:");
textcolor(15);
gotoxy(52,9);cprintf(" CHANGER LA COULEUR ");
gotoxy(49,10);cprintf(" DE LA GRILLE ");
textcolor(BLACK);
textattr(3);
gotoxy(49,12);cprintf("F5:");
textcolor(15);
gotoxy(52,12);cprintf(" HELP ");
textcolor(BLACK);
textattr(3);
gotoxy(49,14);cprintf("F6:");
textcolor(15);
gotoxy(52,14);cprintf(" CE JEUX CREE PAR ");
textbackground(0);
textbackground(BLUE);
for(i=0;i<24;i++)
{
gotoxy(43,2+i);cprintf("³");
}
for(i=0;i<80;i++) {
gotoxy(1+i,2);cprintf("Ä");}
for(i=0;i<36;i++) {
gotoxy(44+i,23);cprintf("Ä");}
textbackground(0);
textcolor(15); /* Æ Ï ×=(215) Ð(208) Ò(210) */
textbackground(couleur);
gotoxy(3,3);cprintf("ÚÄÄÄÂÄÄÄÂÄÄÄÒÄÄÄÂÄÄÄÂÄÄÄÒÄÄÄÂÄÄÄÂÄÄÄ¿\n");
gotoxy(3,4);cprintf("³ ³ ³ º ³ ³ º ³ ³ ³\n");
gotoxy(3,5);cprintf("ÃÄÄÄÅÄÄÄÅÄÄÄ×ÄÄÄÅÄÄÄÅÄÄÄ×ÄÄÄÅÄÄÄÅÄÄÄ´\n");
gotoxy(3,6);cprintf("³ ³ ³ º ³ ³ º ³ ³ ³\n");
gotoxy(3,7);cprintf("ÃÄÄÄÅÄÄÄÅÄÄÄ×ÄÄÄÅÄÄÄÅÄÄÄ×ÄÄÄÅÄÄÄÅÄÄÄ´\n");
gotoxy(3,8);cprintf("³ ³ ³ º ³ ³ º ³ ³ ³\n");
gotoxy(3,9);cprintf("ÆÍÍÍØÍÍÍØÍÍÍÎÍÍÍØÍÍÍØÍÍÍÎÍÍÍØÍÍÍØÍÍ͵\n");
gotoxy(3,10);cprintf("³ ³ ³ º ³ ³ º ³ ³ ³\n");
gotoxy(3,11);cprintf("ÃÄÄÄÅÄÄÄÅÄÄÄ×ÄÄÄÅÄÄÄÅÄÄÄ×ÄÄÄÅÄÄÄÅÄÄÄ´\n");
gotoxy(3,12);cprintf("³ ³ ³ º ³ ³ º ³ ³ ³\n");
gotoxy(3,13);cprintf("ÃÄÄÄÅÄÄÄÅÄÄÄ×ÄÄÄÅÄÄÄÅÄÄÄ×ÄÄÄÅÄÄÄÅÄÄÄ´\n");
gotoxy(3,14);cprintf("³ ³ ³ º ³ ³ º ³ ³ ³\n");
gotoxy(3,15);cprintf("ÆÍÍÍØÍÍÍØÍÍÍÎÍÍÍØÍÍÍØÍÍÍÎÍÍÍØÍÍÍØÍÍ͵\n");
gotoxy(3,16);cprintf("³ ³ ³ º ³ ³ º ³ ³ ³\n");
gotoxy(3,17);cprintf("ÃÄÄÄÅÄÄÄÅÄÄÄ×ÄÄÄÅÄÄÄÅÄÄÄ×ÄÄÄÅÄÄÄÅÄÄÄ´\n");
gotoxy(3,18);cprintf("³ ³ ³ º ³ ³ º ³ ³ ³\n");
gotoxy(3,19);cprintf("ÃÄÄÄÅÄÄÄÅÄÄÄ×ÄÄÄÅÄÄÄÅÄÄÄ×ÄÄÄÅÄÄÄÅÄÄÄ´\n");
gotoxy(3,20);cprintf("³ ³ ³ º ³ ³ º ³ ³ ³\n");
gotoxy(3,21);cprintf("ÀÄÄÄÁÄÄÄÁÄÄÄÐÄÄÄÁÄÄÄÁÄÄÄÐÄÄÄÁÄÄÄÁÄÄÄÙ\n");
textbackground(18);
textcolor(BLACK);
textattr(3);
gotoxy(49,5);cprintf(" 0:");
textbackground(0);
textcolor(15);
gotoxy(52,5);cprintf("EFFACER UN NOMBRE ");
}
//////////////////////////////////////////////////////////
int aff_message_activation_de_l_aide_au_debut(void)
{
int w,b,d,active_aide;
textbackground(0);
//POUR METTRE OMBRE VOISINAGE DU MESSAGE QUI APPARAIT
textbackground(BLACK);
gotoxy(32,10);cprintf(" ");
gotoxy(32,11);cprintf(" ");
gotoxy(32,12);cprintf(" ");
gotoxy(32,13);cprintf(" ");
gotoxy(32,14);cprintf(" ");
textbackground(0);
textbackground(CYAN);
textcolor(BROWN);
gotoxy(30,9);cprintf("ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿");
gotoxy(30,10);cprintf("³ Voulez-vous activez l'aide? ³");
gotoxy(30,11);cprintf("³ ³");
gotoxy(30,12);cprintf("³ Oui Non ³");
gotoxy(30,13);cprintf("ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ");
w=33;// sont des coordonne‚ initialiser
b=12;
textbackground(WHITE);gotoxy(w,b);cprintf("Oui");
gotoxy(33,12);
textbackground(0);
do
{
d=getch();
if(d==0x4B || d==0x4D )// deplacement du curseur
{ fflush(stdin);
switch(d)
{
case GAUCHE :{
if(w==33)
{
gotoxy(w,b);textbackground(WHITE);
cprintf("Oui");
textbackground(0);
gotoxy(50,12);
textbackground(CYAN);
cprintf("Non");
textbackground(0);
gotoxy(w,b);break;
}
else
{
w=w-17;gotoxy(w,b);
textbackground(WHITE);
cprintf("Oui");
textbackground(0);
gotoxy(50,12);
textbackground(CYAN);
cprintf("Non");
textbackground(0);
gotoxy(w,b);break;
}
}// end gauche
case DROITE :{
if(w==50)
{
gotoxy(w,b);textbackground(WHITE);cprintf("Non");
textbackground(0);
gotoxy(33,12);
textbackground(CYAN);
cprintf("Oui");
textbackground(0);
gotoxy(w,b);break;
}
else {
w=w+17;gotoxy(w,b);textbackground(WHITE);
cprintf("Non");
textbackground(0);
gotoxy(33,12);
textbackground(CYAN);
cprintf("Oui");
textbackground(0);
gotoxy(w,b);break;
}
}// end case droite
}
}
if(d==13 && w==33)
{
active_aide=1;
}
if(d==13 && w==50)
{
active_aide=0;
}
}while(d!=13);
return active_aide;
}
////////////////////////////////////////////////////////////////////////////////////
dep deplacement_curseur(int c,dep p)
{
switch(c)
{
case HAUT : p.yi=p.yi-2;
if((p.yi<21)&&(p.yi>=4))
{
gotoxy(p.xi,p.yi);
break;
}
else
{
p.yi=20;
gotoxy(p.xi,p.yi);
break;
}
case BAS :
p.yi=p.yi+2;
if((p.yi<21)&&(p.yi>=4))
{
gotoxy(p.xi,p.yi);
break;
}
else
{
p.yi=4;
gotoxy(p.xi,p.yi);
break;
}
case GAUCHE : p.xi=p.xi-4;
if((p.xi<37)&&(p.xi>=5))
{
gotoxy(p.xi,p.yi);
break;
}
else
{
p.xi=37;
gotoxy(p.xi,p.yi);
break;
}
case DROITE:
if((p.xi<37)&&(p.xi>=5))
{
p.xi=p.xi+4;
gotoxy(p.xi,p.yi);
break;
}
else
{
p.xi=5;
gotoxy(p.xi,p.yi);
break;
}
}// end switch()
return p;
}
////////////////////////////////////////////////////////////////////////////
int quitte_le_jeux(int x,int y,int couleur)
{
int w,b,d,g;
textbackground(BLACK);
gotoxy(32,10);cprintf(" ");
gotoxy(32,11);cprintf(" ");
gotoxy(32,12);cprintf(" ");
gotoxy(32,13);cprintf(" ");
gotoxy(32,14);cprintf(" ");
textbackground(0);
textbackground(CYAN);
textcolor(BROWN);
gotoxy(30,9);cprintf("ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿");
gotoxy(30,10);cprintf("³ Voulez-vous quittez le jeux ³");
gotoxy(30,11);cprintf("³ ³");
gotoxy(30,12);cprintf("³ Oui Non ³");
gotoxy(30,13);cprintf("ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ");
w=33;
b=12;
textbackground(WHITE);gotoxy(w,b);cprintf("Oui");
gotoxy(33,12);
textbackground(0);
do
{
curseur(0);
fflush(stdin);
d=getch();
if(d==0x4B || d==0x4D )// deplacement du curseur
{
switch(d)
{
case GAUCHE :{if(w==33)
{
gotoxy(w,b);textbackground(WHITE);cprintf("Oui");textbackground(0);gotoxy(50,12);textbackground(CYAN);cprintf("Non");textbackground(0);gotoxy(w,b);break;}
else
{
w=w-17;gotoxy(w,b);textbackground(WHITE);cprintf("Oui");textbackground(0);textbackground(0);gotoxy(50,12);textbackground(CYAN);cprintf("Non");textbackground(0);gotoxy(w,b);break;}}
case DROITE :{
if(w==50){
gotoxy(w,b);textbackground(WHITE);cprintf("Non");textbackground(0);textbackground(0);gotoxy(33,12);textbackground(CYAN);cprintf("Oui");textbackground(0);gotoxy(w,b);break;}
else {
w=w+17;gotoxy(w,b);textbackground(WHITE);cprintf("Non");textbackground(0);textbackground(0);gotoxy(33,12);textbackground(CYAN);cprintf("Oui");textbackground(0);gotoxy(w,b);break;
}
}
}
}
if(d==13 && w==33)
{
g=27;
}
if(d==13 && w==50)
{
textbackground(BLUE);clrscr();grille(couleur);d=13;g=11;gotoxy(x,y);
}
curseur(1);
}while(d!=13);
return g;
}
//////////////////////////////////////////////////////////////////////////////////////
void return_a_la_grille(int x,int y,int couleur){
initialise(F);
initialise(t);
textbackground(BLUE);
grille(couleur);
textcolor(15);
textbackground(12);
gotoxy(x,y);
}
//////////////////////////////////////////////////////////////////////////////
void solution(void)
{
int v,p,i,j;
sudo(t);
for(v=4;v<21;v=v+2)
for(p=5;p<=37;p=p+4)
{
i=indicex(p);
j=indicey(v);
if(t[j][i]==F[j][i])
{
gotoxy(p,v); textcolor(YELLOW);
cprintf("%d",abs(t[j][i]));
textcolor(15);
}
else
{
gotoxy(p,v); textcolor(RED);
cprintf("%d",abs(t[j][i]));
}
}// end la deuxieme for
}
////////////////////////////////////////////////////////////////////////////////
int message_aide_activer(int x,int y)
{
textbackground(CYAN+BLINK);textattr(4);
gotoxy(32,1);
cprintf(" F1: L'AIDE ACTIVER ");
textbackground(18);
textcolor(WHITE);
textattr(3);
gotoxy(56,1);
cprintf("F2: L'AIDE DESACTIVER");
gotoxy(x,y);textbackground(0);
return 1;
}
///////////////////////////////////////////////////////////////////////////////////////
int message_aide_desactiver(int x,int y)
{
textbackground(18);textattr(3);
gotoxy(32,1);
cprintf(" F1: L'AIDE ACTIVER ");
textbackground(CYAN+BLINK);
textattr(4);
gotoxy(56,1);
cprintf("F2: L'AIDE DESACTIVER");
gotoxy(x,y);
textbackground(0);
return 0;
}
/////////////////////////////////////
int changer_couleur_de_la_grille(void)
{
int n,h;
do
{
clrscr();
textbackground(RED);
gotoxy(20,2);cprintf(" CHANGER LA COULEUR DE LA GRILLE ");
gotoxy(20,4);cprintf(" 0: BLACK ");
gotoxy(20,5);cprintf(" 1: BLUE ");
gotoxy(20,6);cprintf(" 2:GREEN ");
gotoxy(20,7);cprintf(" 3:CYAN ");
gotoxy(20,8);cprintf(" 5:MAGANTA");
gotoxy(20,9);cprintf(" 6:BROWN ");
gotoxy(21,11); cprintf(" CHOISIR UN NUMERO DE VOTRE CHOIX:: ");
n=getch();
if(isdigit(n))
{scanf("%d",&n);}
}
while((n<0)||(n>6));
return n;
}
///////////////////////////////////////////////////////////////////////////
void help_sudoku(void)
{
textbackground(RED);
curseur(0);
gotoxy(10,4); cprintf("ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿");
gotoxy(10,5); cprintf("³ PRINCIPE DU JEUX ³");
gotoxy(10,6); cprintf("³ UTILISEZ LES FLECHE DE VOTRE CLAVIER ³");
gotoxy(10,7); cprintf("³ POUR VOUS DEPLACEZ DANS LA GRILLE ³");
gotoxy(10,8); cprintf("³ SI VOUS VOULEZ ACTIVE L'AIDE APPUYER ³");
gotoxy(10,9); cprintf("³ SUR F1 ³");
gotoxy(10,10);cprintf("³ POUR DESACTIVER APPUYER SUR F2 ³");
gotoxy(10,11);cprintf("³ SOLUTION APPUYER SUR F3 ³");
gotoxy(10,12);cprintf("³ CHANGER LA COULEUR DE LA GRILLE F4 ³");
gotoxy(10,13);cprintf("³ ³");
gotoxy(10,14);cprintf("ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ");
}
//////////////////////////////////////////////////////////////////////////////
void creation(void)
{
int gdriver = DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode, "");
setcolor(14);
settextstyle(2,0,7);
outtextxy(200,150,"AHABRI MONSSIF");
setfillstyle(2,1);
bar(50,100,150,200);
getch();
closegraph();
}
/////////////////////////////////////////////////////////////////////////////////////
void titre_sudoku()
{
int i;
textbackground(BLUE);
gotoxy(1,24);printf(" SU DO KU .... ");
for(i=0;i<5;i++)
{ textcolor(i+1);
gotoxy(25,24);cprintf("S");
textcolor(i+2);
gotoxy(26,24);cprintf("U");
textcolor(i+3);
gotoxy(28,24);cprintf("D");
textcolor(i+4);
gotoxy(29,24);cprintf("O");
textcolor(i+5);
gotoxy(31,24);cprintf("K");
textcolor(i+6);
gotoxy(32,24);cprintf("U");
textcolor(i+7);
gotoxy(34,24);cprintf(".");
textcolor(i+8);
gotoxy(35,24);cprintf(".");
textcolor(i+9);
gotoxy(36,24);cprintf(".");
delay(700);
}
getch();
}
/////////////////////////////////////////////////////////////////////////////
void inter()
{
int gdriver = DETECT,gmode;
initgraph(&gdriver, &gmode,"");
setcolor(CYAN);
setbkcolor(BLUE);
settextstyle(1,HORIZ_DIR,6);
outtextxy(30,200,"PROJET JEUX SUDOKU");
settextstyle(1,HORIZ_DIR,2);
outtextxy(30,350,"REALISE PAR AHABRI MONSSIF");
getch();
closegraph();
}
//////////////////////////////////////////////////////////////////////////////////
void retour_a_la_case_precedente( int t[9][9],int *i , int *j)
{
if(( (*j)==0 ) && ( (*i) > 0 ) )
{
(*j)=8; (*i)--; }
if(( (*j)> 0 ) && ( (*i)>= 0 ) )
{ (*j)--; }
for((*i) ; (*i) >= 0 ;(*i)--)
{
while( (*j)>=0 )
{
if( ( t[*i][*j]<0 ) )
{ return;}
else
(*j)--;
}
if((*j)<0 && (*i) > 0 ) (*j)=8;
}
if((*i)<0 && (*j) >=0)
(*i)=0;
if((*i)<0 && (*j)<0)
{
gotoxy(30,25);
cprintf("GRILLE NA PAS DE SOLUTION...");
getch();
exit(0);
}
}
//************************************************************
void back(int t[9][9],int *i , int *j )
{
int element,incrementation ;
t[*i][*j]=0 ;
retour_a_la_case_precedente(t,i,j);
if (t[*i][*j] > -9 )
{
incrementation = 1 ;
do{
element= t[*i][*j]-incrementation;
incrementation++;
if(!colonnes(t,*i,*j,-element)&&!ligne(t,*i,*j,-element)&&!verifie(t,-element,*i,*j))
{
t[*i][*j] = element;
return;
}
}while(element > -9);
if( element <= -9)
back(t,i,j);
}
else if (t[*i][*j] == (-9) )
{
back(t,i,j);
}
}
//***********************************************************************************
void sudo(int t[9][9])
{
int i ,j;
int element ;
for(i=0;i<9;i++)
for(j=0;j<9;j++)
if(!t[i][j])
{
for(element=1 ; element<=9 ; element++)
{
if(!colonnes(t,i,j,element) && !ligne(t,i,j,element) && !verifie(t,element,i,j) )
{
t[i][j] = -element ;
break;
}
}
if(element>9)
{
back(t,&i,&j);
}
}
}
////////////////////////////////////////////////////////////////////////////