Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question#include <cstdlib> #include <stdlib.h> #include <SDL/SDL.h> #include <SDL.h> #include using namespace std; bool Initialisation(); void Plateau(int, int); void Pause(); void Affichage(); void Probleme(); void Souris(); void Tours(); int i,j; int const largeur = 600; int const hauteur = 600; int plateau[3][3]; SDL_Surface *fd, *X, *O, *screen; SDL_Event event; SDL_Rect r={0,0,0,0}; int main ( int argc, char** argv ) { SDL_Init( SDL_INIT_VIDEO); int done =0; // initialize SDL video if ( SDL_Init( SDL_INIT_VIDEO ) < 0 ) { cout << "Probleme d initialisation" << SDL_GetError() << endl; Probleme(); } // create a new window screen = SDL_SetVideoMode(largeur,hauteur, 16,SDL_HWSURFACE|SDL_DOUBLEBUF); SDL_WM_SetCaption("Morpion Version 1.0", NULL); Initialisation(); Affichage(); //Boucle generale while(!done) { //Traiter les evenements while(SDL_PollEvent(&event)) { switch(event.type) { case SDL_QUIT: done=1; break; case SDL_KEYUP: if(event.key.keysym.sym==SDLK_a) done=1; break; case SDL_MOUSEBUTTONUP: Plateau(event.button.x,event.button.y); break; default: break; } } // finally, update the screen :) SDL_Flip(screen); } // end main loop // free loaded bitmap SDL_FreeSurface(screen); // all is well ;) printf("Exited cleanly\n"); SDL_Quit(); return 0; } bool Initialisation() { fd = NULL; X = NULL; O = NULL; //pour fd if( (!fd NULL) || (!X NULL) || (!O == NULL) ) { SDL_FreeSurface(fd), fd= NULL; SDL_FreeSurface(X), X= NULL; SDL_FreeSurface(O), O = NULL; cout<< "Probleme d initialisation des images" << endl; Probleme(); } if( (fd NULL) || (X NULL) || (O == NULL) ) { cout<< "Probleme de chargement de fd, x et o" << endl; Probleme(); } X = SDL_LoadBMP("x.bmp"); O = SDL_LoadBMP("o.bmp"); fd = SDL_LoadBMP("fd.bmp"); } void Pause() { int continuer = 1; SDL_Event event; while (continuer) { SDL_WaitEvent(&event); switch(event.type) { case SDL_QUIT: continuer = 0; } } } void Affichage() { SDL_Rect r = {0}; SDL_BlitSurface(fd,NULL,screen,&r); } void Probleme() { char choix; cout<< " Vous avez un probleme\n "<<endl; cout<< " Voules vous quitter? Oui ou Non :\n "<<endl; switch(choix) { case 'oui': EXIT_SUCCESS; break; case 'non': EXIT_FAILURE; break; } } void Plateau(int x, int y ) { int h,l,w,a,b; for(i=0; i<3; i++) for(j=0;j<3;j++) plateau[i][j]=0; //calcul de la case associé: i=x/(largeur/3); j=y/(hauteur/3); if(plateau[i][j]==0) { { //pour les x: if(x<200) { x=0; } else if(x<400) { x=200; } else { x=400; } //pour les y : if(y<200) { y=0; } else if(y<400) { y=200; } else { y=400; } r.x=x; r.y=y; } SDL_BlitSurface(X,NULL,screen,&r); } else if(plateau[i][j]==2) { { //pour les x: if(x<200) { x=0; } else if(x<400) { x=200; } else { x=400; } //pour les y : if(y<200) { y=0; } else if(y<400) { y=200; } else { y=400; } r.x=x; r.y=y; } SDL_BlitSurface(O,NULL,screen,&r); } }