salut, je suis lancé dans la programmation du jeu motus en C en utilisaant SDL comme biblio graphique je trouve probléme dans la gestion du touche SDLK_RETURN du clavier quand je veux entrer les mots la fenetre disparait tous d'un coup j'ai pas compris la faute le code me parrait correcte si vous trouver certains fautes pouvez vous me signaler
ce jeu c'est mon projet de programmation et il ne reste pas assez de temps pour le rendre aidez-moi merci d'avance
voila mon code mais cé juste celle de fenetre de jeu
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include <SDL/SDL_ttf.h>
#include "methodes.h"
char *choixMot(int nblettres);
char boutton_presse(SDLKey key);
void initialiser(part *x);
int test ( Uint16 x,Uint16 y, SDL_Rect pos ,int leng ,int larg);
int verif_exist(char *mot_saisi,int nb_lettre);
void gestion_lettres(char *mot_choisi,char *mot_saisi ,int tentative,int nb_lettres,part *p);
int fenetre_jouer(SDL_Surface *ecran,int nblettres,joueur j1)
{
SDL_Event event;
SDL_Rect pos1,posFond,poscarreau,postxt,poslettre,posid,posessai,posscore,possolution,poscadre;
/*def des variables locales*/
char tab_mots[10][10];
int i=0,j=0;
int s,t,k;
int iterative=1,quit;
int score_courant=0;
int continuer;
int fermer_fenetre=0;
int b1=0;
int affichesolution = 0;
part x;
/*init*/
SDL_Surface *bouton1a
NULL, *bouton1b NULL,*txt=NULL,*imageDeFond = NULL, *carreau = NULL, *texte = NULL, *erreur, *rouge = NULL, *vert = NULL, *cadre_solution = NULL, *solution = NULL;
TTF_Font *police1 = TTF_OpenFont("font.ttf", 17);
TTF_Font *police2 = TTF_OpenFont("font.ttf", 25);
SDL_Color couleur1 = {0,0,255};
SDL_Color couleur2 = {0,0,0};
pos1.x=0;
pos1.y=530;
posFond.x=0;
posFond.y=0;
posscore.x=750;
posscore.y=470;
posessai.x=535;
posessai.y=470;
poscadre.x=0;
poscadre.y=264;
possolution.x=345;
possolution.y=280;
switch(nblettres){
case 6: {
imageDeFond = IMG_Load("images\\grille6.jpg");
poscarreau.x=120;
poscarreau.y=107;
poslettre.x=130;
poslettre.y=107;
possolution.x=345;
break;
}
case 7: {
imageDeFond = IMG_Load("images\\grille7.jpg");
poscarreau.x=86;
poscarreau.y=107;
poslettre.x=98;
poslettre.y=107;
possolution.x=340;
break;
}
case 8: {
imageDeFond = IMG_Load("images\\grille8.jpg");
poscarreau.x=74;
poscarreau.y=107;
poslettre.x=85;
poslettre.y=107;
possolution.x=330;
break;
}
}
bouton1a = IMG_Load("images\\home1.png");
bouton1b = IMG_Load("images\\home0.png");
carreau = IMG_Load("images\\carreau1.png");
rouge = IMG_Load("images\\rouge.png");
vert = IMG_Load("images\\vert.png");
erreur = IMG_Load("images\\erreur.png");
//cadre_solution = IMG_Load("images\\solution.png");
SDL_SetColorKey(bouton1a, SDL_SRCCOLORKEY, SDL_MapRGB(bouton1a->format, 0, 0, 0));
SDL_SetColorKey(bouton1b, SDL_SRCCOLORKEY, SDL_MapRGB(bouton1b->format, 0, 0, 0));
SDL_SetColorKey(carreau, SDL_SRCCOLORKEY, SDL_MapRGB(carreau->format, 0, 0, 0));
SDL_BlitSurface(imageDeFond, NULL, ecran, &posFond);
SDL_BlitSurface(bouton1b, NULL, ecran, &pos1);
SDL_BlitSurface(carreau, NULL, ecran, &poscarreau);
SDL_Flip(ecran);
/*fin initialisation*/
do{
continuer=1;
k=0;
initialiser(&x);
for(s=0;s<10;s++)
for(t=0;t<10;t++)
tab_mots[s][t]=' ';
char* mot_recherche = malloc(10*sizeof(char));
mot_recherche=choixMot(nblettres);
tab_mots[0][0]=mot_recherche[0];
while (continuer){
char essai[5]="0/5";
char points[10];
essai[0]=iterative+'0';
//if (affichesolution){
//SDL_BlitSurface(cadre_solution, NULL, ecran, &poscadre);
//SDL_BlitSurface(solution, NULL, ecran, &possolution);
//SDL_FreeSurface(solution);
//SDL_Flip(ecran);
//SDL_Delay(2000);
//SDL_EventState(SDL_KEYUP,SDL_IGNORE);
//SDL_EventState(SDL_KEYUP,SDL_ENABLE);
// solution = NULL;
// affichesolution=0;
// }
SDL_BlitSurface(imageDeFond, NULL, ecran, &posFond);
b1=test(event.motion.x,event.motion.y,pos1,61,61);
if (b1) SDL_BlitSurface(bouton1a, NULL, ecran, &pos1);
else SDL_BlitSurface(bouton1b, NULL, ecran, &pos1);
SDL_BlitSurface(carreau, NULL, ecran, &poscarreau);
texte = TTF_RenderText_Blended(police1, itoa(score_courant,points,17) ,couleur1);
SDL_BlitSurface(texte, NULL, ecran, &posscore);
SDL_FreeSurface(texte);
texte = TTF_RenderText_Blended(police1, essai ,couleur1);
SDL_BlitSurface(texte, NULL, ecran, &posessai);
SDL_FreeSurface(texte);
for(s=0;s<6;s++)
for(t=0;t<nblettres;t++){
char* ch;
ch = malloc(10*sizeof(char));
//ch[1]='\0';
ch[0]=toupper(tab_mots[s][t]);
texte = TTF_RenderText_Blended(police2, ch ,couleur2);
free(ch);
postxt.x=t*37+poslettre.x;
postxt.y=s*37+poslettre.y;
posid.x=t*37+(poslettre.x-8);
posid.y=s*37+(poslettre.y+2);
if (x.flag[s][t]==1)
SDL_BlitSurface(vert, NULL, ecran, &posid);
else if (x.flag[s][t]==2)
SDL_BlitSurface(rouge, NULL, ecran, &posid);
else if (x.flag[s][t]==0)
SDL_BlitSurface(erreur, NULL, ecran, &posid);
SDL_BlitSurface(texte, NULL, ecran, &postxt);
SDL_FreeSurface(texte);
}
SDL_Flip(ecran);
SDL_WaitEvent(&event);
switch(event.type){
case SDL_QUIT:{
fermer_fenetre = 1;
continuer=0;
iterative=10;
break;
}
case SDL_MOUSEBUTTONUP:{
b1=test(event.motion.x,event.motion.y,pos1,55,55);
if (b1) {continuer=0;
iterative=10;
return 0;
}
break;
}
case SDL_KEYUP:{
if (event.key.keysym.sym==SDLK_RETURN)
//**/
{ if (i<6) {
tab_mots[i][nblettres]='\0';
if (verif_exist(tab_mots[i],nblettres))
gestion_lettres(mot_recherche,tab_mots[i],i,nblettres,&x);
else {
for(s=0;s<nblettres;s++)
x.flag[i][s]=0;
}
//**/
if (x.gagne) {
score_courant+=100-10*i;
i=-1;
j=0;
iterative++;
continuer=0;
for(s=0;s<6;s++)
for(t=0;t<nblettres;t++){
char* ch;
ch = malloc(10*sizeof(char));
ch[1]='\0';
ch[0]=toupper(tab_mots[s][t]);
texte = TTF_RenderText_Blended(police2, ch,couleur2);
free(ch);
postxt.x=t*37+poslettre.x;
postxt.y=s*37+poslettre.y;
posid.x=t*37+(poslettre.x-8);
posid.y=s*37+(poslettre.y+2);
if (x.flag[s][t]==1)
SDL_BlitSurface(vert, NULL, ecran, &posid);
else if (x.flag[s][t]==2)
SDL_BlitSurface(rouge, NULL, ecran, &posid);
else if (x.flag[s][t]==0)
SDL_BlitSurface(erreur, NULL, ecran, &posid);
SDL_BlitSurface(texte, NULL, ecran, &postxt);
SDL_FreeSurface(texte);
}
SDL_Flip(ecran);
SDL_Delay(1000);
SDL_EventState(SDL_KEYUP,SDL_IGNORE);
SDL_EventState(SDL_KEYUP,SDL_ENABLE);
}
//**/
if (i<5){
for(s=0;s<nblettres;s++)
if (x.flag[i][s]==2)
tab_mots[i+1][s]=tab_mots[i][s];
}
i++;
j=0;
poscarreau.y=107+37*i;}
else if (i==6){
solution = TTF_RenderText_Blended(police2, mot_recherche, couleur2);
affichesolution=1;
iterative++;
i=0;
continuer=0;
}
break;
}
else if(event.key.keysym.sym==SDLK_LEFT){
if (j>0) {j--;}
break;}
else if(event.key.keysym.sym==SDLK_RIGHT){
if (j<nblettres-1) {j++;}
break;}
else if ((boutton_presse(event.key.keysym.sym)>='a') &&(boutton_presse(event.key.keysym.sym)<='z') ){
//if ((boutton_presse(event.key.keysym.sym)!=' ')&(event.key.keysym.sym!=SDLK_LEFT)&(event.key.keysym.sym!=SDLK_RIGHT)&(event.key.keysym.sym!=SDLK_RETURN)){
tab_mots[i][j]=boutton_presse(event.key.keysym.sym);
if (j<nblettres-1) j++;
}
break;
}
}
if (nblettres==6)
poscarreau.x=120+37*j;
else if (nblettres==7)
poscarreau.x=86+37*j;
else poscarreau.x=74+37*j;
}
}while(iterative<6);
j1.score=score_courant;
/*Dessinner la derniere solution*/
if (!x.gagne){
SDL_BlitSurface(cadre_solution, NULL, ecran, &poscadre);
SDL_BlitSurface(solution, NULL, ecran, &possolution);
SDL_FreeSurface(solution);
SDL_Flip(ecran);
SDL_Delay(2000);
SDL_EventState(SDL_KEYUP,SDL_IGNORE);
SDL_EventState(SDL_KEYUP,SDL_ENABLE);
solution = NULL;
}
/**/
//FSOUND_Stream_Stop(musique);
//FSOUND_Stream_Close(musique);
SDL_FreeSurface(bouton1a);
SDL_FreeSurface(bouton1b);
SDL_FreeSurface(carreau);
SDL_FreeSurface(rouge);
SDL_FreeSurface(vert);
SDL_FreeSurface(imageDeFond);
SDL_FreeSurface(cadre_solution);
SDL_FreeSurface(erreur);
TTF_CloseFont(police1);
TTF_CloseFont(police2);
if (iterative==6){
joueur tab[10];
best_five(j1,tab);
}
return quit;
}
void initialiser(part *x){
int s,t;
for(s=0;s<10;s++)
for(t=0;t<10;t++){
(*x).flag[s][t] =-1;
(*x).place[t] = 0;
}
(*x).gagne = 0;
}
Afficher la suite