123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226 |
- #include "gestionnaireNiveaux.h"
- GestionnaireNiveaux::GestionnaireNiveaux(SDL_Surface *screen):
- m_pageActuelle(0),m_estChoisi(false),m_choixJoueur("nothings"),m_screen(screen), m_font(0), m_pagePrecedente(0), m_pageSuivante(0)
- {
-
-
- m_pagePrecedente = new Bouton(SDL_LoadBMP("Images/gauche.bmp"), screen, 300-154, 560);
- m_pageSuivante = new Bouton(SDL_LoadBMP("Images/droite.bmp"), screen, 300, 560);
-
- for (int i(0); i<NB_BOUTONS; i++)
- {
- m_tableauBoutons[i]=0;
- }
- allerALaPage(0);
-
-
-
- }
- GestionnaireNiveaux::~GestionnaireNiveaux()
- {
-
-
- delete(m_pagePrecedente);
- delete(m_pageSuivante);
-
- reinitialiserPage();
- }
- void GestionnaireNiveaux::calculer(int const xSouris, int const ySouris)
- {
- bool selectOk(false);
- for (int i(0); i<NB_BOUTONS; i++)
- {
- if (m_tableauBoutons[i]->calculer(xSouris,ySouris))
- {
- m_font=m_apercu[i];
- selectOk=true;
- }
- }
- if (!selectOk)
- m_font=0;
- }
- void GestionnaireNiveaux::afficher()
- {
-
-
- if (m_font!=0)
- SDL_BlitSurface(m_font,0,m_screen,0);
-
- m_pagePrecedente->afficher();
- m_pageSuivante->afficher();
-
- for (int i(0); i<NB_BOUTONS; i++)
- {
- m_tableauBoutons[i]->afficher();
- }
- }
- void GestionnaireNiveaux::clic(int const xSouris, int const ySouris)
- {
-
-
-
- for (Uint8 i(0); i<NB_BOUTONS; i++)
- {
- if (m_tableauBoutons[i]->estClique(xSouris,ySouris))
- {
- std::cout << "Clic, niveau choisi: " << nomDuFichier(i) << std::endl;
- if (m_apercu[i]!=0)
- {
- m_estChoisi=true;
- m_choixJoueur=nomDuFichier(i);
- }
- else
- std::cout << nomDuFichier(i) << " n'existe pas. Reste au menu. " << std::endl;
- }
- }
-
- if (m_pageSuivante->estClique(xSouris,ySouris))
- allerALaPage(m_pageActuelle+1);
- else if (m_pagePrecedente->estClique(xSouris,ySouris) && m_pageActuelle>0)
- allerALaPage(m_pageActuelle-1);
- }
- bool GestionnaireNiveaux::estChoisi()
- {
- return m_estChoisi;
- }
- std::string GestionnaireNiveaux::getChoix()
- {
- return m_choixJoueur;
- }
- void GestionnaireNiveaux::reinitialiserPage()
- {
- for (int i(0); i<NB_BOUTONS; i++)
- {
-
- if (m_tableauBoutons[i]!=0)
- delete m_tableauBoutons[i];
- m_tableauBoutons[i]=0;
-
- if (m_apercu[i]!=0)
- SDL_FreeSurface(m_apercu[i]);
- m_apercu[i]=0;
- }
- }
- void GestionnaireNiveaux::allerALaPage(Uint32 numeroPage)
- {
-
- if (m_tableauBoutons[0]!=0)
- reinitialiserPage();
-
- m_pageActuelle=numeroPage;
-
- SDL_Surface* apparence[NB_BOUTONS];
- for (int i(0); i<NB_BOUTONS; i++)
- {
- apparence[i]=SDL_LoadBMP("Images/boutonLevel.bmp");
- }
- SDL_Surface* surbrillance[NB_BOUTONS];
- for (int i(0); i<NB_BOUTONS; i++)
- {
- surbrillance[i]=SDL_LoadBMP("Images/boutonLevelB.bmp");
- }
-
- std::string nomNiveau[NB_BOUTONS];
- std::string ajout;
- Niveau maquette;
- for (int i(0); i<NB_BOUTONS; i++)
- {
- if (!maquette.creer(nomDuFichier(i)))
- {
- nomNiveau[i]="NO_LVL";
- m_apercu[i]=0;
- }
- else
- {
- ajout=convertirEntierEnCaracteres(m_pageActuelle*NB_BOUTONS+i+1);
- nomNiveau[i]="Level "+ajout+" "+maquette.getNom();
- m_apercu[i]=SDL_CreateRGBSurface(SDL_HWSURFACE,600,600,16,0,0,0,0);
- maquette.afficher(m_apercu[i]);
- }
- }
-
- SDL_Surface* texte[NB_BOUTONS];
- SDL_Rect position;
- position.x=20;
- position.y=4;
- SDL_Rect positionB;
- positionB.x=position.x+2;
- positionB.y=position.y+1;
- SDL_Color bleu={0,0,200};
- for (int i(0); i<NB_BOUTONS; i++)
- {
- texte[i]=transform(nomNiveau[i],25,bleu);
- SDL_BlitSurface(texte[i], 0, apparence[i], &position);
- SDL_BlitSurface(texte[i], 0, surbrillance[i], &positionB);
- }
-
- int y(80);
- int x(300-276-7);
- for (int i(0); i<NB_BOUTONS; i++)
- {
- if (i==8)
- {
- x=300+7;
- y=80;
- }
- m_tableauBoutons[i]=new Bouton(apparence[i], m_screen, x, y);
- y+=38+16;
- m_tableauBoutons[i]->attribuerImg(surbrillance[i]);
- }
-
- for (int i(0); i<NB_BOUTONS; i++)
- {
- SDL_FreeSurface(texte[i]);
- }
- }
- std::string GestionnaireNiveaux::nomDuFichier(Uint8 IDTab)
- {
-
- int numLvl;
- numLvl=m_pageActuelle*NB_BOUTONS+IDTab+1;
-
- return "level "+convertirEntierEnCaracteres(numLvl)+".txt";
- }
|