From e93ad2847791222937e26b57da5fd01a527d38cc Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Wed, 7 Jan 2015 14:12:16 +0100 Subject: Fix use of uninitialized variable in Fmenuchoixpersos Signed-off-by: Olivier Gayot --- menuchoixpersos.c | 47 +++++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 18 deletions(-) (limited to 'menuchoixpersos.c') diff --git a/menuchoixpersos.c b/menuchoixpersos.c index 325eadc..cc217a8 100644 --- a/menuchoixpersos.c +++ b/menuchoixpersos.c @@ -10,9 +10,9 @@ void Fmenuchoixpersos (SURFACES *surfaces, POSITIONS *positions) { TTF_Font *police = NULL; - int Vchoix = 0; + int Vchoix = PALADIN; SDL_Color vert; - unsigned int continuer = 1; + bool continuer = true; PERSONNAGES persos[3]; ENNEMIS ennemis[5]; SDL_Event event; @@ -21,29 +21,40 @@ void Fmenuchoixpersos (SURFACES *surfaces, POSITIONS *positions) vert.r = 39; vert.g = 189; vert.b = 31; - SDL_BlitSurface (surfaces->Pchoixpaladin,NULL,surfaces->Pecran,&positions->Vpositionmenu); + police = TTF_OpenFont ("TIMESI.TTF",36); - while (Vnbperso!=3) - { - continuer = 1; - if (Vnbperso == 0) - surfaces->Ptextechoixmenu = TTF_RenderText_Blended (police,"Choisissez la Classe de votre Premier Personnage",vert); - else if (Vnbperso == 1) - surfaces->Ptextechoixmenu = TTF_RenderText_Blended (police,"Choisissez la Classe de votre Deuxième Personnage",vert); - else if (Vnbperso == 2) - surfaces->Ptextechoixmenu = TTF_RenderText_Blended (police,"Choisissez la Classe de votre Troisième Personnage",vert); - positions->Vpositiontextemenu.x=XWIN/2-surfaces->Ptextechoixmenu->w/2; - if (persos[Vnbperso-1].classe == PALADIN) + + /* loop until we have actually chosen our three characters */ + while (Vnbperso < 3) { + static const char *strings[] = { + "Please choose the class of your first character", + "Please choose the class of your second character", + "Please choose the class of your third character", + }; + + /* display the background with the selected text */ + if (Vchoix == PALADIN) { SDL_BlitSurface (surfaces->Pchoixpaladin,NULL,surfaces->Pecran,&positions->Vpositionmenu); - if (persos[Vnbperso-1].classe == PRETRE) + } else if (Vchoix == PRETRE) { SDL_BlitSurface (surfaces->Pchoixpretre,NULL,surfaces->Pecran,&positions->Vpositionmenu); - if (persos[Vnbperso-1].classe == VOLEUR) + } else if (Vchoix == VOLEUR) { SDL_BlitSurface (surfaces->Pchoixvoleur,NULL,surfaces->Pecran,&positions->Vpositionmenu); + } else { + abort(); + } + + /* display the string associated with the current character number (aka Please choose ...) */ + surfaces->Ptextechoixmenu = TTF_RenderText_Blended (police, strings[Vnbperso], vert); + + positions->Vpositiontextemenu.x=XWIN/2-surfaces->Ptextechoixmenu->w/2; + SDL_BlitSurface (surfaces->Ptextechoixmenu,NULL,surfaces->Pecran,&positions->Vpositiontextemenu); + SDL_BlitSurface (surfaces->Ppretre,NULL,surfaces->Pecran,&positions->Vpositionmenupretre); SDL_BlitSurface (surfaces->Ppaladin,NULL,surfaces->Pecran,&positions->Vpositionmenupaladin); SDL_BlitSurface (surfaces->Pvoleur,NULL,surfaces->Pecran,&positions->Vpositionmenuvoleur); - SDL_BlitSurface (surfaces->Ptextechoixmenu,NULL,surfaces->Pecran,&positions->Vpositiontextemenu); SDL_Flip (surfaces->Pecran); + + continuer = true; while (continuer) { SDL_WaitEvent (&event); @@ -82,7 +93,7 @@ void Fmenuchoixpersos (SURFACES *surfaces, POSITIONS *positions) case SDLK_f: Fremplirpersos (Vchoix,persos,Vnbperso); Vnbperso++; - continuer=0; + continuer = false; break; default: break; -- cgit v1.2.3