From e816f16a5007798968f4c9003b3159a45485e88f Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Sun, 26 Oct 2014 18:20:28 +0000 Subject: game: remove useless checks it is safe to pass a null pointer to SDL_FreeSurface() BTW: change the format of the files from dos to unix Signed-off-by: Olivier Gayot --- menuchoixpersos.c | 308 +++++++++++++++++++++++++++--------------------------- 1 file changed, 154 insertions(+), 154 deletions(-) (limited to 'menuchoixpersos.c') diff --git a/menuchoixpersos.c b/menuchoixpersos.c index 8db15df..6c5f9b7 100644 --- a/menuchoixpersos.c +++ b/menuchoixpersos.c @@ -1,154 +1,154 @@ -#include -#include -#include -#include "structures.h" -#include "constantes.h" -#include "prototypes.h" -#include -#include - -void Fmenuchoixpersos (SURFACES *surfaces, POSITIONS *positions) -{ - - int nbpersos = 0; - TTF_Font *police = NULL; - int Vchoix = 0; - SDL_Color vert; - unsigned int continuer = 1; - PERSONNAGES persos[3]; - ENNEMIS ennemis[5]; - SDL_Event event; - int Vnbperso = 0; - - vert.r = 39; - vert.g = 189; - vert.b = 31; - SDL_BlitSurface (surfaces->Pchoixpaladin,NULL,surfaces->Pecran,&positions->Vpositionmenu); - police = TTF_OpenFont ("C://WINDOWS//Fonts//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) - SDL_BlitSurface (surfaces->Pchoixpaladin,NULL,surfaces->Pecran,&positions->Vpositionmenu); - if (persos[Vnbperso-1].classe == PRETRE) - SDL_BlitSurface (surfaces->Pchoixpretre,NULL,surfaces->Pecran,&positions->Vpositionmenu); - if (persos[Vnbperso-1].classe == VOLEUR) - SDL_BlitSurface (surfaces->Pchoixvoleur,NULL,surfaces->Pecran,&positions->Vpositionmenu); - 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); - while (continuer) - { - SDL_WaitEvent (&event); - switch (event.type) - { - case SDL_KEYDOWN: - switch (event.key.keysym.sym) - { - case SDLK_LEFT: - if(Vchoix>PALADIN) - { - Vchoix--; - Fchangersurlignage2 (Vchoix,surfaces,positions); - } - else - { - Vchoix=VOLEUR; - Fchangersurlignage2 (Vchoix,surfaces,positions); - } - break; - case SDLK_RIGHT: - if (VchoixPecran); - Fremplirpersos2 (surfaces,persos); - Fmap(surfaces,positions,persos,ennemis); -} - -void Fchangersurlignage2 (int Vchoix, SURFACES *surfaces, POSITIONS *positions) -{ - if (Vchoix==PALADIN) - SDL_BlitSurface (surfaces->Pchoixpaladin,NULL,surfaces->Pecran,&positions->Vpositionmenu); - else if (Vchoix==PRETRE) - SDL_BlitSurface (surfaces->Pchoixpretre,NULL,surfaces->Pecran,&positions->Vpositionmenu); - else if (Vchoix==VOLEUR) - SDL_BlitSurface (surfaces->Pchoixvoleur,NULL,surfaces->Pecran,&positions->Vpositionmenu); - 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); -} - -void Fremplirpersos (int Vchoix, PERSONNAGES persos[],int Vnbpersos) -{ - if (Vchoix==PALADIN) - persos[Vnbpersos].classe=PALADIN; - else if (Vchoix==PRETRE) - persos[Vnbpersos].classe=PRETRE; - else if (Vchoix==VOLEUR) - persos[Vnbpersos].classe=VOLEUR; -} - -void Fremplirpersos2 (SURFACES *surfaces, PERSONNAGES persos[]) -{ - - int i; - for (i=0;i<3;i++) - { - if (persos[i].classe==PALADIN) - surfaces->Tperso[i]=IMG_Load("images/paladin.bmp"); - else if (persos[i].classe==PRETRE) - surfaces->Tperso[i]=IMG_Load("images/prêtre.bmp"); - else if (persos[i].classe==VOLEUR) - surfaces->Tperso[i]=IMG_Load("images/voleur.bmp"); - } -} - -void Fremplirennemis (SURFACES *surfaces,int Vnbennemis,ENNEMIS ennemis[]) -{ - - int i; - for (i=0;i<=Vnbennemis;i++) - { - if (ennemis[i].classe==GUERRIER_GOBELIN) - surfaces->Tennemi[i]=surfaces->Pgobelin; - } -} - -int Fcalculernbennemis () -{ - int nb; - nb=(rand()%(4-0+1))+0; - return nb; -} - +#include +#include +#include +#include "structures.h" +#include "constantes.h" +#include "prototypes.h" +#include +#include + +void Fmenuchoixpersos (SURFACES *surfaces, POSITIONS *positions) +{ + + int nbpersos = 0; + TTF_Font *police = NULL; + int Vchoix = 0; + SDL_Color vert; + unsigned int continuer = 1; + PERSONNAGES persos[3]; + ENNEMIS ennemis[5]; + SDL_Event event; + int Vnbperso = 0; + + vert.r = 39; + vert.g = 189; + vert.b = 31; + SDL_BlitSurface (surfaces->Pchoixpaladin,NULL,surfaces->Pecran,&positions->Vpositionmenu); + police = TTF_OpenFont ("C://WINDOWS//Fonts//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) + SDL_BlitSurface (surfaces->Pchoixpaladin,NULL,surfaces->Pecran,&positions->Vpositionmenu); + if (persos[Vnbperso-1].classe == PRETRE) + SDL_BlitSurface (surfaces->Pchoixpretre,NULL,surfaces->Pecran,&positions->Vpositionmenu); + if (persos[Vnbperso-1].classe == VOLEUR) + SDL_BlitSurface (surfaces->Pchoixvoleur,NULL,surfaces->Pecran,&positions->Vpositionmenu); + 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); + while (continuer) + { + SDL_WaitEvent (&event); + switch (event.type) + { + case SDL_KEYDOWN: + switch (event.key.keysym.sym) + { + case SDLK_LEFT: + if(Vchoix>PALADIN) + { + Vchoix--; + Fchangersurlignage2 (Vchoix,surfaces,positions); + } + else + { + Vchoix=VOLEUR; + Fchangersurlignage2 (Vchoix,surfaces,positions); + } + break; + case SDLK_RIGHT: + if (VchoixPecran); + Fremplirpersos2 (surfaces,persos); + Fmap(surfaces,positions,persos,ennemis); +} + +void Fchangersurlignage2 (int Vchoix, SURFACES *surfaces, POSITIONS *positions) +{ + if (Vchoix==PALADIN) + SDL_BlitSurface (surfaces->Pchoixpaladin,NULL,surfaces->Pecran,&positions->Vpositionmenu); + else if (Vchoix==PRETRE) + SDL_BlitSurface (surfaces->Pchoixpretre,NULL,surfaces->Pecran,&positions->Vpositionmenu); + else if (Vchoix==VOLEUR) + SDL_BlitSurface (surfaces->Pchoixvoleur,NULL,surfaces->Pecran,&positions->Vpositionmenu); + 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); +} + +void Fremplirpersos (int Vchoix, PERSONNAGES persos[],int Vnbpersos) +{ + if (Vchoix==PALADIN) + persos[Vnbpersos].classe=PALADIN; + else if (Vchoix==PRETRE) + persos[Vnbpersos].classe=PRETRE; + else if (Vchoix==VOLEUR) + persos[Vnbpersos].classe=VOLEUR; +} + +void Fremplirpersos2 (SURFACES *surfaces, PERSONNAGES persos[]) +{ + + int i; + for (i=0;i<3;i++) + { + if (persos[i].classe==PALADIN) + surfaces->Tperso[i]=IMG_Load("images/paladin.bmp"); + else if (persos[i].classe==PRETRE) + surfaces->Tperso[i]=IMG_Load("images/prêtre.bmp"); + else if (persos[i].classe==VOLEUR) + surfaces->Tperso[i]=IMG_Load("images/voleur.bmp"); + } +} + +void Fremplirennemis (SURFACES *surfaces,int Vnbennemis,ENNEMIS ennemis[]) +{ + + int i; + for (i=0;i<=Vnbennemis;i++) + { + if (ennemis[i].classe==GUERRIER_GOBELIN) + surfaces->Tennemi[i]=surfaces->Pgobelin; + } +} + +int Fcalculernbennemis () +{ + int nb; + nb=(rand()%(4-0+1))+0; + return nb; +} + -- cgit v1.2.3