Aide en mode graphique en C
xdev10
Messages postés
8
Date d'inscription
Statut
Membre
Dernière intervention
-
Utilisateur anonyme -
Utilisateur anonyme -
Bonjour,
je debute en c et j'ai developpé le jeu tetravex en mode console ,ma question est si je peux appliquer le mode graphique sur mon code telle qu'il est ou je dois faire des modifications, Merci d'avance de votre réponse.
le code :
#include<stdio.h>
#include<stdlib.h>
#include<windows.h>
typedef struct {
int est,ouest,sud,nord;
}carre;
void remplire (carre t[3][3])
{
int i ,j ,a,b,c,d;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
a=rand() % 9 + 1;
t[i][j].est=a;
b=rand() % 9 + 1;
t[i][j].ouest=b;
c=rand() % 9 + 1;
t[i][j].sud=c;
d=rand() % 9 + 1;
t[i][j].nord=d;
}
}
void affiche(carre t[3][3])
{
int i,j;
int m[9][9];
for(i=0;i<9;i++)
{for(j=0;j<9;j++)
{m[i][j]=0;
}
}
for(i=0;i<3;i++){
for(j=0;j<3;j++)
{
m[i*3][j*3+1]=t[i][j].nord;
m[i*3+1][j*3]=t[i][j].ouest;
m[i*3+1][j*3+2]=t[i][j].est;
m[i*3+2][j*3+1]=t[i][j].sud;
}}
for(i=0;i<9;i++){
for(j=0;j<9;j++){
printf(" %d ",m[i][j]);
}printf("\n");
}
}
void vider(carre c[3][3])
{int i,j;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{c[i][j].est=c[i][j].ouest=c[i][j].nord=c[i][j].sud=0;
}
}
void permutcase(carre m[3][3], carre t[3][3],int k, int h,int i,int j )
{
carre c[3][3];
c[0][0]=t[k][h];
t[k][h]=m[i][j];
m[i][j]=c[0][0];
}
verif(carre t[3][3],carre m[3][3],int i,int j ,int k,int h)
{
if( (k==0) && (h==0) )
{
if((t[0][1].ouest == 0)&&(t[1][0].nord == 0)||(t[0][1].ouest==m[i][j].est)&&(t[1][0].nord == m[i][j].sud) || (t[0][1].ouest==m[i][j].est)&&(t[1][0].nord == 0)||(t[1][0].nord == m[i][j].sud) && (t[0][1].ouest == 0))
return(1);
}
else if ( (k==0) && (h==1) )
{
if( (t[0][2].ouest == 0)&&(t[0][0].est == 0)&&(t[1][1].nord == 0)||(t[0][2].ouest == m[i][j].est)&&(t[0][0].est == m[i][j].ouest)&&(t[1][1].nord == m[i][j].sud)||(t[0][2].ouest == 0)&&(t[0][0].est == m[i][j].ouest)&&(t[1][1].nord == m[i][j].sud)||(t[0][0].est == 0)&&(t[0][2].ouest == m[i][j].est)&&(t[1][1].nord == m[i][j].sud)||(t[1][1].nord == 0)&&(t[0][2].ouest == m[i][j].est)&&(t[0][0].est == m[i][j].ouest)||(t[0][2].ouest == 0)&&(t[0][0].est == 0)&&(t[1][1].nord == m[i][j].sud)||(t[0][2].ouest == 0)&&(t[1][1].nord == 0)&&(t[0][0].est == m[i][j].ouest)||(t[0][0].est == 0)&&(t[1][1].nord == 0)&&(t[0][2].ouest == m[i][j].est) )
return(1);
}
else if ( (k==0) && (h==2) )
{
if( (t[0][1].est == 0 )&&(t[1][2].nord == 0)||(t[0][1].est == m[i][j].ouest)&&(t[1][2].nord == m[i][j].sud)||(t[0][1].est == m[i][j].ouest)&&(t[1][2].nord == 0)||(t[0][1].est == 0 )&&(t[1][2].nord == m[i][j].sud) )
return(1);
}
else if ( (k==1) && (h==0) )
{
if( (t[0][0].sud == 0)&&(t[1][1].ouest == 0)&&(t[2][0].nord == 0)||(t[1][1].ouest == m[i][j].est)&&(t[0][0].sud == m[i][j].nord)&&(t[2][0].nord == m[i][j].sud)||(t[0][0].sud == 0)&&(t[1][1].est == m[i][j].ouest)&&(t[2][0].nord == m[i][j].sud)||(t[0][0].sud == m[i][j].nord)&&(t[1][1].ouest == m[i][j].est)&&(t[2][0].nord == m[i][j].sud)||(t[0][0].sud == m[i][j].nord)&&(t[1][1].ouest == m[i][j].est)&&(t[2][0].est == 0)||(t[0][0].sud == m[i][j].nord)&&(t[1][1].ouest == 0)&&(t[2][0].nord == 0)||(t[0][0].sud == 0)&&(t[2][0].nord == 0)&&(t[1][1].ouest == m[i][j].est)||(t[0][0].sud == 0)&&(t[1][1].ouest == 0)&&(t[2][0].nord == m[i][j].sud) )
return(1);
}
else if ( (k==1) && (h==1) )
{
if( (t[0][1].sud == 0)&&(t[1][0].est == 0)&&(t[2][1].nord == 0)&&(t[1][2].ouest == 0)||(t[0][1].sud == m[i][j].nord)&&(t[1][0].est == m[i][j].ouest)&&(t[2][1].nord == m[i][j].sud)&&(t[1][2].ouest == m[i][j].est)||(t[0][1].sud == m[i][j].nord)&&(t[1][0].est == 0)&&(t[2][1].nord == 0)&&(t[1][2].ouest == 0)||(t[0][1].sud == 0)&&(t[1][0].est == m[i][j].ouest )&&(t[2][1].nord == 0)&&(t[1][2].ouest == 0)||(t[0][1].sud == 0)&&(t[1][0].est == 0)&&(t[2][1].nord == m[i][j].sud )&&(t[1][2].ouest == 0)||(t[0][1].sud == 0)&&(t[1][0].est == 0)&&(t[2][1].nord == 0)&&(t[1][2].ouest == m[i][j].est )||(t[0][1].sud == m[i][j].nord)&&(t[1][0].est == m[i][j].ouest )&&(t[2][1].nord == 0)&&(t[1][2].ouest == 0)||(t[0][1].sud == m[i][j].nord)&&(t[1][0].est == 0)&&(t[2][1].nord == m[i][j].sud )&&(t[1][2].ouest == 0)||(t[0][1].sud == m[i][j].nord)&&(t[1][0].est == 0)&&(t[2][1].nord == 0)&&(t[1][2].ouest == m[i][j].est )||(t[0][1].sud == 0)&&(t[1][0].est == m[i][j].ouest)&&(t[2][1].nord == m[i][j].sud )&&(t[1][2].ouest == 0)|| (t[0][1].sud == 0)&&(t[1][0].est == m[i][j].ouest )&&(t[2][1].nord == 0)&&(t[1][2].ouest == m[i][j].est )||(t[0][1].sud == 0)&&(t[1][0].est == m[i][j].ouest)&&(t[2][1].nord == m[i][j].sud )&&(t[1][2].ouest == m[i][j].est )||(t[0][1].sud == 0)&&(t[1][0].est == m[i][j].ouest )&&(t[2][1].nord == m[i][j].sud )&&(t[1][2].ouest == m[i][j].est )||(t[0][1].sud == m[i][j].nord)&&(t[1][0].est == 0)&&(t[2][1].nord == m[i][j].sud )&&(t[1][2].ouest == m[i][j].est )||(t[0][1].sud == m[i][j].nord )&&(t[1][0].est == m[i][j].ouest )&&(t[2][1].nord == 0)&&(t[1][2].ouest == m[i][j].est )||(t[0][1].sud == m[i][j].nord )&&(t[1][0].est == m[i][j].ouest )&&(t[2][1].nord == m[i][j].sud )&&(t[1][2].ouest == 0) )
return(1);
}
else if ( (k==1) && (h==2) )
{
if( (t[0][2].sud == 0)&&(t[1][1].est == 0)&&(t[2][2].nord == 0)||(t[0][2].ouest == m[i][j].est)&&(t[1][1].est == m[i][j].ouest)&&(t[2][2].nord == m[i][j].sud)||(t[0][2].sud == m[i][j].nord )&&(t[1][1].est == 0)&&(t[2][2].nord == 0)||(t[0][2].sud == 0)&&(t[1][1].est == m[i][j].ouest)&&(t[2][2].nord == 0)||(t[0][2].sud == 0)&&(t[1][1].est == 0)&&(t[2][2].nord == m[i][j].sud)||(t[0][2].sud == m[i][j].nord)&&(t[1][1].est == m[i][j].ouest )&&(t[2][2].nord == 0)||(t[0][2].sud == m[i][j].nord )&&(t[1][1].est == 0)&&(t[2][2].nord == m[i][j].sud)||(t[0][2].sud == 0)&&(t[1][1].est == m[i][j].ouest)&&(t[2][2].nord == m[i][j].sud))
return(1);
}
else if( (k==2) && (h==0) )
{
if((t[1][0].sud == 0)&&(t[2][1].ouest == 0)||(t[1][0].sud==m[i][j].nord)&&(t[2][1].ouest == m[i][j].est) || (t[1][0].sud==m[i][j].nord)&&(t[2][1].ouest == 0)||(t[1][0].sud == 0) && (t[2][1].ouest == m[i][j].est ))
return(1);
}
else if ( (k==2) && (h==1) )
{
if( (t[2][0].est == 0)&&(t[1][1].sud == 0)&&(t[2][2].ouest == 0)||(t[2][0].est == m[i][j].ouest )&&(t[1][1].sud == m[i][j].nord )&&(t[2][2].ouest == m[i][j].est )||(t[2][0].est == m[i][j].ouest )&&(t[1][1].sud == 0)&&(t[2][2].ouest == 0)||(t[2][0].est == 0)&&(t[1][1].sud == m[i][j].nord )&&(t[2][2].ouest == 0)||(t[2][0].est == 0)&&(t[1][1].sud == 0)&&(t[2][2].ouest == m[i][j].est)||(t[2][0].est == m[i][j].ouest )&&(t[1][1].sud == m[i][j].nord )&&(t[2][2].ouest == 0)||(t[2][0].est == m[i][j].ouest )&&(t[1][1].sud == 0)&&(t[2][2].ouest == m[i][j].est )||(t[2][0].est == 0)&&(t[1][1].sud == m[i][j].nord )&&(t[2][2].ouest == m[i][j].est ) )
return(1);
}
else if( (k==2) && (h==0) )
{
if((t[2][1].est == 0)&&(t[1][2].sud == 0)||(t[2][1].est==m[i][j].ouest)&&(t[1][2].sud == m[i][j].nord) || (t[2][1].est== 0)&&(t[1][2].sud == m[i][j].nord )||(t[2][1].est == m[i][j].ouest )&&(t[1][2].sud == 0))
return(1);
}
}
void deplacer ( int choix2,carre t[3][3],carre v[3][3],int i ,int j,carre m[3][3] )
{int k,h;
switch(choix2)
{
case 1 :
{
k=h=0;
if(verif(t,m,i,j,k,h) == 1)
{
permutcase(m,t,k,h,i,j);
}
else printf("error 1");
break;
}
case 2 :
{
k=0;h=1;
if(verif(t,m,i,j,k,h) == 1)
{
permutcase(m,t,k,h,i,j);
}
else printf("error2");
break;
}
case 3 :
{
k=0;h=2;
if(verif(t,m,i,j,k,h) == 1)
{
permutcase(m,t,k,h,i,j);
}
else printf("error3");
break;
}
case 4 :
{
k=1;h=0;
if(verif(t,m,i,j,k,h) == 1)
{
permutcase(m,t,k,h,i,j);
}
else printf("error4");
break;
}
case 5 :
{
k=1;h=1;
if(verif(t,m,i,j,k,h) == 1)
{
permutcase(m,t,k,h,i,j);
}
else printf("error5");
break;
}
case 6 :
{
k=1;h=2;
if(verif(t,m,i,j,k,h) == 1)
{
permutcase(m,t,k,h,i,j);
}
else printf("error6");
break;
}
case 7 :
{
k=2;h=0;
if(verif(t,m,i,j,k,h) == 1)
{
permutcase(m,t,k,h,i,j);
}
else printf("error7");
break;
}
case 8 :
{
k=2;h=1;
if(verif(t,m,i,j,k,h) == 1)
{
permutcase(m,t,k,h,i,j);
}
else printf("error8");
break;
}
case 9 :
{
k=2;h=2;
if(verif(t,m,i,j,k,h) == 1)
{
permutcase(m,t,k,h,i,j);
}
else printf("error9");
break;
}
}
}
void jouer(carre t[3][3] ,carre m[3][3] )
{int i,k,h;
int j,choix,choix2;
carre v[3][3];
printf("M : \n");
affiche(m);
printf("T : \n");
affiche(t);
printf("\n\ndonner le numero du champs a mettre de m a t\n");
scanf("%d",&choix);
switch(choix)
{
case 1 :
{ i=j=0;
vider(v);
printf("donner la position du champs de t a remplie");
scanf("%d",&choix2);
deplacer(choix2,t,v,i,j,m);
break;
}
case 2 :
{ i=0;j=1;
vider(v);
printf("donner la position du champs de t a remplie");
scanf("%d",&choix2);
deplacer(choix2,t,v,i,j,m);
break;
}
case 3 :
{
i=0;j=2;
vider(v);
printf("donner la position du champs de t a remplie");
scanf("%d",&choix2);
deplacer(choix2,t,v,i,j,m);
break;
}
case 4 :
{
i=1;j=0;
vider(v);
printf("donner la position du champs de t a remplie");
scanf("%d",&choix2);
deplacer(choix2,t,v,i,j,m);
break;
}
case 5 :
{
i=1;j=1;
vider(v);
printf("donner la position du champs de t a remplie");
scanf("%d",&choix2);
deplacer(choix2,t,v,i,j,m);
break;
}
case 6 :
{
i=1;j=2;
vider(v);
printf("donner la position du champs de t a remplie");
scanf("%d",&choix2);
deplacer(choix2,t,v,i,j,m);
break;
}
case 7 :
{
i=2;j=0;
vider(v);
printf("donner la position du champs de t a remplie");
scanf("%d",&choix2);
deplacer(choix2,t,v,i,j,m);
break;
}
case 8 :
{
i=2;j=1;
vider(v);
printf("donner la position du champs de t a remplie");
scanf("%d",&choix2);
deplacer(choix2,t,v,i,j,m);
break;
}
case 9 :
{
i=2;j=2;
vider(v);
printf("donner la position du champs de t a remplie");
scanf("%d",&choix2);
deplacer(choix2,t,v,i,j,m);
break;
}
}
printf("m\n");
affiche(m);
printf("t\n");
affiche(t);
}
int main(){
carre t[3][3];
carre m[3][3];
system("color F2");
vider(t);
remplire(m);
jouer(t,m);
jouer(t,m);
jouer(t,m);
return 0;
}
je debute en c et j'ai developpé le jeu tetravex en mode console ,ma question est si je peux appliquer le mode graphique sur mon code telle qu'il est ou je dois faire des modifications, Merci d'avance de votre réponse.
le code :
#include<stdio.h>
#include<stdlib.h>
#include<windows.h>
typedef struct {
int est,ouest,sud,nord;
}carre;
void remplire (carre t[3][3])
{
int i ,j ,a,b,c,d;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
a=rand() % 9 + 1;
t[i][j].est=a;
b=rand() % 9 + 1;
t[i][j].ouest=b;
c=rand() % 9 + 1;
t[i][j].sud=c;
d=rand() % 9 + 1;
t[i][j].nord=d;
}
}
void affiche(carre t[3][3])
{
int i,j;
int m[9][9];
for(i=0;i<9;i++)
{for(j=0;j<9;j++)
{m[i][j]=0;
}
}
for(i=0;i<3;i++){
for(j=0;j<3;j++)
{
m[i*3][j*3+1]=t[i][j].nord;
m[i*3+1][j*3]=t[i][j].ouest;
m[i*3+1][j*3+2]=t[i][j].est;
m[i*3+2][j*3+1]=t[i][j].sud;
}}
for(i=0;i<9;i++){
for(j=0;j<9;j++){
printf(" %d ",m[i][j]);
}printf("\n");
}
}
void vider(carre c[3][3])
{int i,j;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{c[i][j].est=c[i][j].ouest=c[i][j].nord=c[i][j].sud=0;
}
}
void permutcase(carre m[3][3], carre t[3][3],int k, int h,int i,int j )
{
carre c[3][3];
c[0][0]=t[k][h];
t[k][h]=m[i][j];
m[i][j]=c[0][0];
}
verif(carre t[3][3],carre m[3][3],int i,int j ,int k,int h)
{
if( (k==0) && (h==0) )
{
if((t[0][1].ouest == 0)&&(t[1][0].nord == 0)||(t[0][1].ouest==m[i][j].est)&&(t[1][0].nord == m[i][j].sud) || (t[0][1].ouest==m[i][j].est)&&(t[1][0].nord == 0)||(t[1][0].nord == m[i][j].sud) && (t[0][1].ouest == 0))
return(1);
}
else if ( (k==0) && (h==1) )
{
if( (t[0][2].ouest == 0)&&(t[0][0].est == 0)&&(t[1][1].nord == 0)||(t[0][2].ouest == m[i][j].est)&&(t[0][0].est == m[i][j].ouest)&&(t[1][1].nord == m[i][j].sud)||(t[0][2].ouest == 0)&&(t[0][0].est == m[i][j].ouest)&&(t[1][1].nord == m[i][j].sud)||(t[0][0].est == 0)&&(t[0][2].ouest == m[i][j].est)&&(t[1][1].nord == m[i][j].sud)||(t[1][1].nord == 0)&&(t[0][2].ouest == m[i][j].est)&&(t[0][0].est == m[i][j].ouest)||(t[0][2].ouest == 0)&&(t[0][0].est == 0)&&(t[1][1].nord == m[i][j].sud)||(t[0][2].ouest == 0)&&(t[1][1].nord == 0)&&(t[0][0].est == m[i][j].ouest)||(t[0][0].est == 0)&&(t[1][1].nord == 0)&&(t[0][2].ouest == m[i][j].est) )
return(1);
}
else if ( (k==0) && (h==2) )
{
if( (t[0][1].est == 0 )&&(t[1][2].nord == 0)||(t[0][1].est == m[i][j].ouest)&&(t[1][2].nord == m[i][j].sud)||(t[0][1].est == m[i][j].ouest)&&(t[1][2].nord == 0)||(t[0][1].est == 0 )&&(t[1][2].nord == m[i][j].sud) )
return(1);
}
else if ( (k==1) && (h==0) )
{
if( (t[0][0].sud == 0)&&(t[1][1].ouest == 0)&&(t[2][0].nord == 0)||(t[1][1].ouest == m[i][j].est)&&(t[0][0].sud == m[i][j].nord)&&(t[2][0].nord == m[i][j].sud)||(t[0][0].sud == 0)&&(t[1][1].est == m[i][j].ouest)&&(t[2][0].nord == m[i][j].sud)||(t[0][0].sud == m[i][j].nord)&&(t[1][1].ouest == m[i][j].est)&&(t[2][0].nord == m[i][j].sud)||(t[0][0].sud == m[i][j].nord)&&(t[1][1].ouest == m[i][j].est)&&(t[2][0].est == 0)||(t[0][0].sud == m[i][j].nord)&&(t[1][1].ouest == 0)&&(t[2][0].nord == 0)||(t[0][0].sud == 0)&&(t[2][0].nord == 0)&&(t[1][1].ouest == m[i][j].est)||(t[0][0].sud == 0)&&(t[1][1].ouest == 0)&&(t[2][0].nord == m[i][j].sud) )
return(1);
}
else if ( (k==1) && (h==1) )
{
if( (t[0][1].sud == 0)&&(t[1][0].est == 0)&&(t[2][1].nord == 0)&&(t[1][2].ouest == 0)||(t[0][1].sud == m[i][j].nord)&&(t[1][0].est == m[i][j].ouest)&&(t[2][1].nord == m[i][j].sud)&&(t[1][2].ouest == m[i][j].est)||(t[0][1].sud == m[i][j].nord)&&(t[1][0].est == 0)&&(t[2][1].nord == 0)&&(t[1][2].ouest == 0)||(t[0][1].sud == 0)&&(t[1][0].est == m[i][j].ouest )&&(t[2][1].nord == 0)&&(t[1][2].ouest == 0)||(t[0][1].sud == 0)&&(t[1][0].est == 0)&&(t[2][1].nord == m[i][j].sud )&&(t[1][2].ouest == 0)||(t[0][1].sud == 0)&&(t[1][0].est == 0)&&(t[2][1].nord == 0)&&(t[1][2].ouest == m[i][j].est )||(t[0][1].sud == m[i][j].nord)&&(t[1][0].est == m[i][j].ouest )&&(t[2][1].nord == 0)&&(t[1][2].ouest == 0)||(t[0][1].sud == m[i][j].nord)&&(t[1][0].est == 0)&&(t[2][1].nord == m[i][j].sud )&&(t[1][2].ouest == 0)||(t[0][1].sud == m[i][j].nord)&&(t[1][0].est == 0)&&(t[2][1].nord == 0)&&(t[1][2].ouest == m[i][j].est )||(t[0][1].sud == 0)&&(t[1][0].est == m[i][j].ouest)&&(t[2][1].nord == m[i][j].sud )&&(t[1][2].ouest == 0)|| (t[0][1].sud == 0)&&(t[1][0].est == m[i][j].ouest )&&(t[2][1].nord == 0)&&(t[1][2].ouest == m[i][j].est )||(t[0][1].sud == 0)&&(t[1][0].est == m[i][j].ouest)&&(t[2][1].nord == m[i][j].sud )&&(t[1][2].ouest == m[i][j].est )||(t[0][1].sud == 0)&&(t[1][0].est == m[i][j].ouest )&&(t[2][1].nord == m[i][j].sud )&&(t[1][2].ouest == m[i][j].est )||(t[0][1].sud == m[i][j].nord)&&(t[1][0].est == 0)&&(t[2][1].nord == m[i][j].sud )&&(t[1][2].ouest == m[i][j].est )||(t[0][1].sud == m[i][j].nord )&&(t[1][0].est == m[i][j].ouest )&&(t[2][1].nord == 0)&&(t[1][2].ouest == m[i][j].est )||(t[0][1].sud == m[i][j].nord )&&(t[1][0].est == m[i][j].ouest )&&(t[2][1].nord == m[i][j].sud )&&(t[1][2].ouest == 0) )
return(1);
}
else if ( (k==1) && (h==2) )
{
if( (t[0][2].sud == 0)&&(t[1][1].est == 0)&&(t[2][2].nord == 0)||(t[0][2].ouest == m[i][j].est)&&(t[1][1].est == m[i][j].ouest)&&(t[2][2].nord == m[i][j].sud)||(t[0][2].sud == m[i][j].nord )&&(t[1][1].est == 0)&&(t[2][2].nord == 0)||(t[0][2].sud == 0)&&(t[1][1].est == m[i][j].ouest)&&(t[2][2].nord == 0)||(t[0][2].sud == 0)&&(t[1][1].est == 0)&&(t[2][2].nord == m[i][j].sud)||(t[0][2].sud == m[i][j].nord)&&(t[1][1].est == m[i][j].ouest )&&(t[2][2].nord == 0)||(t[0][2].sud == m[i][j].nord )&&(t[1][1].est == 0)&&(t[2][2].nord == m[i][j].sud)||(t[0][2].sud == 0)&&(t[1][1].est == m[i][j].ouest)&&(t[2][2].nord == m[i][j].sud))
return(1);
}
else if( (k==2) && (h==0) )
{
if((t[1][0].sud == 0)&&(t[2][1].ouest == 0)||(t[1][0].sud==m[i][j].nord)&&(t[2][1].ouest == m[i][j].est) || (t[1][0].sud==m[i][j].nord)&&(t[2][1].ouest == 0)||(t[1][0].sud == 0) && (t[2][1].ouest == m[i][j].est ))
return(1);
}
else if ( (k==2) && (h==1) )
{
if( (t[2][0].est == 0)&&(t[1][1].sud == 0)&&(t[2][2].ouest == 0)||(t[2][0].est == m[i][j].ouest )&&(t[1][1].sud == m[i][j].nord )&&(t[2][2].ouest == m[i][j].est )||(t[2][0].est == m[i][j].ouest )&&(t[1][1].sud == 0)&&(t[2][2].ouest == 0)||(t[2][0].est == 0)&&(t[1][1].sud == m[i][j].nord )&&(t[2][2].ouest == 0)||(t[2][0].est == 0)&&(t[1][1].sud == 0)&&(t[2][2].ouest == m[i][j].est)||(t[2][0].est == m[i][j].ouest )&&(t[1][1].sud == m[i][j].nord )&&(t[2][2].ouest == 0)||(t[2][0].est == m[i][j].ouest )&&(t[1][1].sud == 0)&&(t[2][2].ouest == m[i][j].est )||(t[2][0].est == 0)&&(t[1][1].sud == m[i][j].nord )&&(t[2][2].ouest == m[i][j].est ) )
return(1);
}
else if( (k==2) && (h==0) )
{
if((t[2][1].est == 0)&&(t[1][2].sud == 0)||(t[2][1].est==m[i][j].ouest)&&(t[1][2].sud == m[i][j].nord) || (t[2][1].est== 0)&&(t[1][2].sud == m[i][j].nord )||(t[2][1].est == m[i][j].ouest )&&(t[1][2].sud == 0))
return(1);
}
}
void deplacer ( int choix2,carre t[3][3],carre v[3][3],int i ,int j,carre m[3][3] )
{int k,h;
switch(choix2)
{
case 1 :
{
k=h=0;
if(verif(t,m,i,j,k,h) == 1)
{
permutcase(m,t,k,h,i,j);
}
else printf("error 1");
break;
}
case 2 :
{
k=0;h=1;
if(verif(t,m,i,j,k,h) == 1)
{
permutcase(m,t,k,h,i,j);
}
else printf("error2");
break;
}
case 3 :
{
k=0;h=2;
if(verif(t,m,i,j,k,h) == 1)
{
permutcase(m,t,k,h,i,j);
}
else printf("error3");
break;
}
case 4 :
{
k=1;h=0;
if(verif(t,m,i,j,k,h) == 1)
{
permutcase(m,t,k,h,i,j);
}
else printf("error4");
break;
}
case 5 :
{
k=1;h=1;
if(verif(t,m,i,j,k,h) == 1)
{
permutcase(m,t,k,h,i,j);
}
else printf("error5");
break;
}
case 6 :
{
k=1;h=2;
if(verif(t,m,i,j,k,h) == 1)
{
permutcase(m,t,k,h,i,j);
}
else printf("error6");
break;
}
case 7 :
{
k=2;h=0;
if(verif(t,m,i,j,k,h) == 1)
{
permutcase(m,t,k,h,i,j);
}
else printf("error7");
break;
}
case 8 :
{
k=2;h=1;
if(verif(t,m,i,j,k,h) == 1)
{
permutcase(m,t,k,h,i,j);
}
else printf("error8");
break;
}
case 9 :
{
k=2;h=2;
if(verif(t,m,i,j,k,h) == 1)
{
permutcase(m,t,k,h,i,j);
}
else printf("error9");
break;
}
}
}
void jouer(carre t[3][3] ,carre m[3][3] )
{int i,k,h;
int j,choix,choix2;
carre v[3][3];
printf("M : \n");
affiche(m);
printf("T : \n");
affiche(t);
printf("\n\ndonner le numero du champs a mettre de m a t\n");
scanf("%d",&choix);
switch(choix)
{
case 1 :
{ i=j=0;
vider(v);
printf("donner la position du champs de t a remplie");
scanf("%d",&choix2);
deplacer(choix2,t,v,i,j,m);
break;
}
case 2 :
{ i=0;j=1;
vider(v);
printf("donner la position du champs de t a remplie");
scanf("%d",&choix2);
deplacer(choix2,t,v,i,j,m);
break;
}
case 3 :
{
i=0;j=2;
vider(v);
printf("donner la position du champs de t a remplie");
scanf("%d",&choix2);
deplacer(choix2,t,v,i,j,m);
break;
}
case 4 :
{
i=1;j=0;
vider(v);
printf("donner la position du champs de t a remplie");
scanf("%d",&choix2);
deplacer(choix2,t,v,i,j,m);
break;
}
case 5 :
{
i=1;j=1;
vider(v);
printf("donner la position du champs de t a remplie");
scanf("%d",&choix2);
deplacer(choix2,t,v,i,j,m);
break;
}
case 6 :
{
i=1;j=2;
vider(v);
printf("donner la position du champs de t a remplie");
scanf("%d",&choix2);
deplacer(choix2,t,v,i,j,m);
break;
}
case 7 :
{
i=2;j=0;
vider(v);
printf("donner la position du champs de t a remplie");
scanf("%d",&choix2);
deplacer(choix2,t,v,i,j,m);
break;
}
case 8 :
{
i=2;j=1;
vider(v);
printf("donner la position du champs de t a remplie");
scanf("%d",&choix2);
deplacer(choix2,t,v,i,j,m);
break;
}
case 9 :
{
i=2;j=2;
vider(v);
printf("donner la position du champs de t a remplie");
scanf("%d",&choix2);
deplacer(choix2,t,v,i,j,m);
break;
}
}
printf("m\n");
affiche(m);
printf("t\n");
affiche(t);
}
int main(){
carre t[3][3];
carre m[3][3];
system("color F2");
vider(t);
remplire(m);
jouer(t,m);
jouer(t,m);
jouer(t,m);
return 0;
}
A voir également:
- Aide en mode graphique en C
- Mode avion - Guide
- Mode sécurisé samsung - Guide
- God mode - Guide
- Mode d'emploi - Guide
- Changer carte graphique - Guide
1 réponse
Salut, et bien logiquement tu ne touche que la partie affichage (printf) et pas la partie méchanique de ton jeux.
Après pour la partie graphique, tu peut adopter ma propre méthode que je trouve est beaucoup plus simple que les algo généraux pour faire du graphique avec la WinAPI.
Alors en premier tu link les lib obligatoire: kernel32.lib;user32.lib;gdi32.lib, puis tu suit cette algo:
PS: utilise les balises
(\___/)
(='.'=)
(")_(")
This is Bunny. Copy and paste bunny into...
...your signature to help him gain world domination
Après pour la partie graphique, tu peut adopter ma propre méthode que je trouve est beaucoup plus simple que les algo généraux pour faire du graphique avec la WinAPI.
Alors en premier tu link les lib obligatoire: kernel32.lib;user32.lib;gdi32.lib, puis tu suit cette algo:
#include <windows.h>
#include <stdio.h>
#define BPP 4
#define LENGTH 1920 // x
#define WIDTH 1080 // y
#define WHITE 0x00FFFFFF
#define BLACK 0x00000000
#define RED 0x00FF0000
#define GREEN 0x0000FF00
#define BLUE 0x000000FF
// Indice for array
#define _x 0
#define _y 1
int screen[LENGTH*WIDTH] = { 0 };
int screen_info[2];
HINSTANCE instance;
HBITMAP texture;
PAINTSTRUCT paint_struct;
HDC device_context_screen;
HDC device_context_texture;
WNDCLASS windows_class;
HWND windows_handle;
MSG event;
LRESULT anwser;
HICON icon_program;
void clear_screen(void)
{
int loop = 0;
while (loop < screen_info[_x] * screen_info[_y])
screen[loop++] = BLACK;
}
LRESULT windows_procedure(HWND windows_handle, UINT message, WPARAM w_param_msg, LPARAM l_param_msg)
{
switch (message)
{
case WM_SIZE:
screen_info[_x] = LOWORD(l_param_msg);
screen_info[_y] = HIWORD(l_param_msg);
texture = CreateCompatibleBitmap(device_context_screen, screen_info[_x], screen_info[_y]);
device_context_texture = CreateCompatibleDC(device_context_screen);
SelectObject(device_context_texture, texture);
break;
}
// Switch first or 2nd instruction for get windowed or full screen
return DefWindowProc(windows_handle, message, w_param_msg, l_param_msg);;
//return 1;
}
void upload_screen()
{
SetBitmapBits(texture, screen_info[_x] * screen_info[_y] * BPP, screen);
BitBlt(device_context_screen, 0, 0, screen_info[_x], screen_info[_y], device_context_texture, 0, 0, SRCCOPY);
}
void init_video(void)
{
windows_class.cbClsExtra = 0;
windows_class.cbWndExtra = 0;
windows_class.hbrBackground = 0;
windows_class.hCursor = 0;
windows_class.hIcon = 0;
windows_class.hInstance = instance;
windows_class.lpfnWndProc = windows_procedure;
windows_class.lpszClassName = "Classe 1";
windows_class.lpszMenuName = NULL;
windows_class.style = CS_HREDRAW | CS_VREDRAW;
RegisterClass(&windows_class);
windows_handle = CreateWindow("Classe 1",
"Window",
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
CW_USEDEFAULT, CW_USEDEFAULT, screen_info[_x], screen_info[_y],
NULL,
NULL,
instance,
NULL
);
device_context_screen = GetDC(windows_handle);
texture = CreateCompatibleBitmap(device_context_screen, screen_info[_x], screen_info[_y]);
device_context_texture = CreateCompatibleDC(device_context_screen);
SelectObject(device_context_texture, texture);
}
int main(HINSTANCE _instance, HINSTANCE _previous_instance, LPSTR cmd_line, int cmd_show)
{
int a;
instance = _instance;
screen_info[_x] = LENGTH;
screen_info[_y] = WIDTH;
init_video();
while (1)
{
PeekMessage(&event, windows_handle, 0, 0, PM_REMOVE);
windows_procedure(windows_handle, event.message, event.wParam, event.lParam);
// Modify the screen
a = 250000;
while (a--)
screen[a] = BLUE;
upload_screen();
clear_screen();
}
}
PS: utilise les balises
etstp
(\___/)
(='.'=)
(")_(")
This is Bunny. Copy and paste bunny into...
...your signature to help him gain world domination
Utilisateur anonyme
les balises codes*