From f7243b3481920264b93d1f01ec057eba88643e77 Mon Sep 17 00:00:00 2001
From: Henri Montjoie <henri.montjoie@insa-rennes.fr>
Date: Mon, 9 May 2016 00:07:20 +0200
Subject: [PATCH] le personnage selectionne apparait a l'ecran

---
 src/SDL_bis.c    | 47 +++++++++++++++++++++++++++++++++++++++++------
 src/controleur.c | 14 ++++++++------
 2 files changed, 49 insertions(+), 12 deletions(-)

diff --git a/src/SDL_bis.c b/src/SDL_bis.c
index 6448f5b..e98fc72 100644
--- a/src/SDL_bis.c
+++ b/src/SDL_bis.c
@@ -98,7 +98,6 @@ char* afficherListe(char** nomsClasses, char** skinsClasses, int nbChoix, TTF_Fo
         SDL_Flip(fenetre);
     }
     SDL_FreeSurface(fenetre);
-    printf("la classe choisie est %s",classeChoisie);
     return classeChoisie;
 }
 
@@ -255,13 +254,20 @@ int SDL_bis()
 
     char src[50], dest[50];
 
-    for(i=0;i<6;i++)
+    for(i=0;i<3;i++)
     {
         strcpy(dest,  "personnage ");
         strcpy(src, castIntToChar(i+1));
         textes[i]= *TTF_RenderText_Shaded(police, strcat(dest, src), couleurBlanche,couleurNoire);
     }
 
+    for(i=3;i<6;i++)
+    {
+        strcpy(dest,  "personnage ");
+        strcpy(src, castIntToChar(i-2));
+        textes[i]= *TTF_RenderText_Shaded(police, strcat(dest, src), couleurBlanche,couleurNoire);
+    }
+
     for(i=0;i<3;i++)
     {
         posTextes[i].x=ecran->w/4-textes[i].w/2;
@@ -277,10 +283,26 @@ int SDL_bis()
     }
     SDL_Flip(ecran);
 
-    int j,p;
+    char** path_images=obtenirSkinsClasses();
+    SDL_Surface* images_classes[nbClasses()];
+    SDL_Surface* images_persos[3][2]={{NULL}};
+    SDL_Rect positions_images[3][2];
+    int numClassePerso[3][2]={{-1,-1},{-1,-1},{-1,-1}};
+    int j,p,k;
     j=0;
     p=0;
     char *classeChoisie;
+    for(i=0;i<nbClasses();i++)
+    {
+        images_classes[i]=SDL_LoadBMP(path_images[i]);
+        if (!images_classes[i])
+        {
+            printf("Unable to load bitmap: %s\n", SDL_GetError());
+            return 1;
+        }
+        SDL_SetColorKey(images_classes[i], SDL_SRCCOLORKEY, SDL_MapRGB(images_classes[i]->format, 0, 0, 255));
+    }
+    int num_classe=-1;
     while(etat==CONFIGURATION)
     {
         SDL_WaitEvent(&event);
@@ -300,23 +322,36 @@ int SDL_bis()
                 }
                 if(j!=0&&p!=0){
                     classeChoisie=afficherListe(obtenirNomsClasses(), obtenirSkinsClasses(), nbClasses(), police, couleurBlanche);
-                    ajouterPersonnage(classeChoisie, p, j);
+                    numClassePerso[p-1][j-1]=ajouterPersonnage(classeChoisie, p-1, j);
                     ecran = SDL_SetVideoMode(LARGEUR_CARTE*(LARGEUR_CASE+1), HAUTEUR_CARTE*(HAUTEUR_CASE+2), 32, SDL_HWSURFACE|SDL_DOUBLEBUF);
                 }
-                j=0;
-                p=0;
                 break;
             default:
                 break;
         }
+
         for(i=0;i<6;i++){
             SDL_BlitSurface(&textes[i],NULL,ecran,&(posTextes[i]));
         }
+        for(i=0;i<3;i++){
+            for(k=0;k<2;k++){
+                positions_images[i][k].y=posTextes[i].y+textes[i].h;
+                positions_images[i][k].x=posTextes[3*k].x+(textes[3*k].w-images_classes[0]->w)/2;
+                images_persos[i][k]=images_classes[numClassePerso[i][k]];
+                if(numClassePerso[i][k]!=-1)
+                {
+                    SDL_BlitSurface(images_persos[i][k],NULL,ecran,&positions_images[i][k]);
+                }
+            }
+        }
         SDL_BlitSurface(texte,NULL,ecran,&pos_texte);
         SDL_BlitSurface(texte2,NULL,ecran,&pos_texte2);
         SDL_BlitSurface(texte3,NULL,ecran,&pos_texte3);
         SDL_BlitSurface(texte3,NULL,ecran,&pos_texte3_bis);
         SDL_Flip(ecran);
+        p=0;
+        j=0;
+        num_classe=-1;
     }
 
     return 0;
diff --git a/src/controleur.c b/src/controleur.c
index 454022d..4e5ffff 100644
--- a/src/controleur.c
+++ b/src/controleur.c
@@ -211,7 +211,7 @@ Case * trouverCase(Carte_Jeu * c, int x, int y){
  *
  * \param le nom de la classe dont dépend le Personnage, numTab un entier représentant l'indice auquel ajouter le Personnage dans le table de personnages,
  *        numJoueur est un entier représentant le premier ou le second Joueur de la Partie.
- * \return 1 si le Personnage a été correctement ajouté, 0 sinon.
+ * \return L'indice de la classe du personnage si le Personnage a été correctement ajouté, -1 sinon.
  */
 int ajouterPersonnage(char * nomClasse, int numTab, int numJoueur){
     int i;
@@ -220,13 +220,15 @@ int ajouterPersonnage(char * nomClasse, int numTab, int numJoueur){
     while(strcmp(nomClasse,getNomClasse(&packGlobal.Classes_Package[i]))!=0&&i<nbClasses()){
         i++;
     }
-    if(i>nbClasses()){
-        return 0;
+    if(i>=nbClasses()){
+        return -1;
     }
 
     //Création du personnage
     Personnage * p = default_personnage(i,packGlobal);
 
+    printf("La classe du personnage %d du joueur %d est %s\n", numTab+1, numJoueur, getClasse(p));
+
     //Ajout du Personnage à l'équipe du Joueur
     switch (numJoueur){
     case 1:
@@ -237,16 +239,16 @@ int ajouterPersonnage(char * nomClasse, int numTab, int numJoueur){
         nextJoueur(partieGlobale->participants);
         break;
     default:
-        return 0;
+        return -1;
     }
 
     if((numTab<TAILLE_MAX_GROUPE)&&(numTab>=0)){
         setNumero(p,numTab);
         addPersonnage(getCurrentJoueur(partieGlobale->participants),p,numTab);
-        return 1;
+        return i;
     }
     else{
-        return 0;
+        return -1;
     }
 }
 
-- 
GitLab