Partage
  • Partager sur Facebook
  • Partager sur Twitter

Problème avec mon jeu tap taupe

Besoin d'aide s'il vous plait novice ^^'

    26 mars 2019 à 20:54:10

    Bonjour a tous je suis un novice en SDL
    Voici mon programme 
    Normalement c'est le jeu du tap taupe , je suis censé change de taupe quand je clique sur une mais malheuresement cela ne marche pas
    Est-ce qu'une âme charitable pourrait m'explique pourquoi et ainsi me permettre de le faire fonctionner 
    Merci d'avance
    #ifdef __cplusplus
        #include <cstdlib>
    #else
        #include <stdlib.h>
    #endif
    
    #include <SDL/SDL.h>
    #include <time.h>
    
    
    
    int taupehasard(int a )
    {
        int nbtaupe=0;
        a=rand()%9;
        nbtaupe=a;
        return nbtaupe;
    
    }
    int main ( int argc, char** argv )
    {
    srand(int (time(NULL)));
    
        int a=0;
        int b=0;
    
    
    
    
    
    
    
    
    
        // initialize SDL video
        if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
        {
            printf( "Unable to init SDL: %s\n", SDL_GetError() );
            return 1;
        }
        SDL_Surface *fond_plaine = NULL, *taupe = NULL,*rectangle=NULL ;
        SDL_Event event;
    rectangle = SDL_CreateRGBSurface(SDL_HWSURFACE, 160, 120, 0, 0, 0, 0, 0);
    SDL_Rect postaupe0,postaupe1,postaupe2,postaupe3,postaupe4,postaupe5,postaupe6,postaupe7,postaupe8,posblanc;
    
    
    
    postaupe0.x=200;
    postaupe0.y=315;
    
    postaupe1.x=200;
    postaupe1.y=425;
    
    postaupe2.x=190;
    postaupe2.y=530;
    
    postaupe3.x=390;
    postaupe3.y=315;
    
    postaupe4.x=390;
    postaupe4.y=425;
    
    postaupe5.x=390;
    postaupe5.y=530;
    
    postaupe6.x=570;
    postaupe6.y=315;
    
    postaupe7.x=580;
    postaupe7.y=415;
    
    postaupe8.x=575;
    postaupe8.y=520;
    
    
    
    
    
    
        // make sure SDL cleans up before exit
        atexit(SDL_Quit);
    
        // create a new window
        SDL_Surface* screen = SDL_SetVideoMode(913, 684, 24,SDL_HWSURFACE|SDL_DOUBLEBUF);
        if ( !screen )
        {
            printf("Unable to set 640x480 video: %s\n", SDL_GetError());
            return 1;
        }
    
        // load an image
        SDL_Surface* bmp = SDL_LoadBMP("fond_plaine.bmp");
        if (!bmp)
        {
            printf("Unable to load bitmap: %s\n", SDL_GetError());
            return 1;
        }
    
        // centre the bitmap on screen
        SDL_Rect dstrect;
        dstrect.x = (screen->w - bmp->w) / 2;
        dstrect.y = (screen->h - bmp->h) / 2;
    
    
    
           taupe = SDL_LoadBMP("taupe.bmp");
           if (!taupe)
        {
            printf("Unable to load bitmap: %s\n", SDL_GetError());
            return 1;
        }
    
    
    
    
    
    
    a=taupehasard(b);
    
        // program main loop
        int continuer=1;
        while (continuer)
        {
    
    
            switch(a)
                {
    case 0:
    posblanc.x=200;
    posblanc.y=315;
    
    break;
    
    case 1:
    posblanc.x=200;
    posblanc.y=425;
    break;
    
    case 2:
    posblanc.x=190;
    posblanc.y=530;
    break;
    
    case 3:
    posblanc.x=390;
    posblanc.y=315;
    break;
    
    case 4:
    posblanc.x=390;
    posblanc.y=425;
    
    case 5:
    posblanc.x=390;
    posblanc.y=530;
    break;
    
    case 6:
    
    posblanc.x=570;
    posblanc.y=315;
    break;
    
    case 7:
    
    posblanc.x=580;
    posblanc.y=440;
    break;
    
    case 8:
    
    posblanc.x=575;
    posblanc.y=520;
    break;
    
                }
            // message processing loop
            SDL_Event event;
            while (SDL_PollEvent(&event))
            {
                // check for messages
                switch (event.type)
                {
                    // exit if the window is closed
                case SDL_QUIT:
                    continuer=0;
                    break;
    
                    // check for keypresses
                case SDL_KEYDOWN:
                    {
                        // exit if ESCAPE is pressed
                        if (event.key.keysym.sym == SDLK_ESCAPE)
                            continuer=1;
                        break;
                    }
                } // end switch
            } // end of message processing
    
            // DRAWING STARTS HERE
    
            // clear screen
            SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0));
    
            // draw bitmap
            SDL_BlitSurface(bmp, 0, screen, &dstrect);
    
    
    
       if(a==0)
        {
    SDL_SetColorKey(taupe, SDL_SRCCOLORKEY, SDL_MapRGB(taupe->format, 255, 255, 255));
    SDL_BlitSurface(taupe, NULL, bmp, &postaupe0);
    SDL_BlitSurface(rectangle, NULL, bmp, &posblanc);
        }
    
        if(a==1)
    
                {
    
    SDL_SetColorKey(taupe, SDL_SRCCOLORKEY, SDL_MapRGB(taupe->format, 255, 255, 255));
    SDL_BlitSurface(taupe, NULL, bmp, &postaupe1);
    SDL_BlitSurface(rectangle, NULL, bmp, &posblanc);
        }
        if(a==2)
    
                {
    
    SDL_SetColorKey(taupe, SDL_SRCCOLORKEY, SDL_MapRGB(taupe->format, 255, 255, 255));
    SDL_BlitSurface(taupe, NULL, bmp, &postaupe2);
    SDL_BlitSurface(rectangle, NULL, bmp, &posblanc);
    
    
    
    
    
        }
        if(a==3)
    
                {
    
    SDL_SetColorKey(taupe, SDL_SRCCOLORKEY, SDL_MapRGB(taupe->format, 255, 255, 255));
    SDL_BlitSurface(taupe, NULL, bmp, &postaupe3);
    SDL_BlitSurface(rectangle, NULL, bmp, &posblanc);
    
    
    
    
    
        }
        if(a==4)
    
                {
    
    SDL_SetColorKey(taupe, SDL_SRCCOLORKEY, SDL_MapRGB(taupe->format, 255, 255, 255));
    SDL_BlitSurface(taupe, NULL, bmp, &postaupe4);
    SDL_BlitSurface(rectangle, NULL, bmp, &posblanc);
    
    
    
    
    
    
        }
        if(a==5)
    
                {
    
    SDL_SetColorKey(taupe, SDL_SRCCOLORKEY, SDL_MapRGB(taupe->format, 255, 255, 255));
    SDL_BlitSurface(taupe, NULL, bmp, &postaupe5);
    SDL_BlitSurface(rectangle, NULL, bmp, &posblanc);
    
    
    
    
    
    
        }
        if(a==6)
    
                {
    
    SDL_SetColorKey(taupe, SDL_SRCCOLORKEY, SDL_MapRGB(taupe->format, 255, 255, 255));
    SDL_BlitSurface(taupe, NULL, bmp, &postaupe6);
    SDL_BlitSurface(rectangle, NULL, bmp, &posblanc);
    
    
    
    
    
    
    
        }
        if(a==7)
    
                {
    
    SDL_SetColorKey(taupe, SDL_SRCCOLORKEY, SDL_MapRGB(taupe->format, 255, 255, 255));
    SDL_BlitSurface(taupe, NULL, bmp, &postaupe7);
    SDL_BlitSurface(rectangle, NULL, bmp, &posblanc);
    
    
    
    
    
    
    
        }
        if(a==8)
    
                {
    
    SDL_SetColorKey(taupe, SDL_SRCCOLORKEY, SDL_MapRGB(taupe->format, 255, 255, 255));
    SDL_BlitSurface(taupe, NULL, bmp, &postaupe8);
    SDL_BlitSurface(rectangle, NULL, bmp, &posblanc);
    
    
    
    
    
    
    
        }
                    // DRAWING ENDS HERE
    
            // finally, update the screen 
            SDL_Flip(screen);
    
        } // end main loop
    
        // free loaded bitmap
        SDL_FreeSurface(bmp);
        SDL_FreeSurface(taupe);
    
        // all is well 
        printf("Exited cleanly\n");
        return 0;
    
    
    
    }
    

    -
    Edité par taupinambour 26 mars 2019 à 22:26:30

    • Partager sur Facebook
    • Partager sur Twitter
      26 mars 2019 à 22:03:25

      Hello,

      stp, indente convenablement ton code et

      Là, c'est illisible.

      • Partager sur Facebook
      • Partager sur Twitter

      On écrit "j'ai tort", pas "tord" qui est le verbe "tordre" à la 3ème personne de l'indicatif présent

        26 mars 2019 à 22:24:55

        voici j'ai modifier merci :) 

        Mon problème est-que quand je mets en waitevent pour que le programme avance pas a pas mais cela m'affiche un écran noir :/

        Or quand j'utilise un pollevent aucun ecran noir mais en revanche aucun changement de place :)

        Merci d'avance

        -
        Edité par taupinambour 26 mars 2019 à 22:28:45

        • Partager sur Facebook
        • Partager sur Twitter
          26 mars 2019 à 23:16:04

          Re,-

          Question indentation, c'est vraiment pas ça, c'est toujours quasiment illisible.

          Pour ton problème: où dans ton ton while(continuer), changes-tu a ? Réponse: nulle part.

          • Partager sur Facebook
          • Partager sur Twitter

          On écrit "j'ai tort", pas "tord" qui est le verbe "tordre" à la 3ème personne de l'indicatif présent

            27 mars 2019 à 2:14:08

            Salut,

            J'ai pas lu tout le code, mais j'espère que tu ne comptes pas rajouter d'autres taupes... Utilise un tableau.

            • Partager sur Facebook
            • Partager sur Twitter
            Tutoriel Ruby - Bon tutoriel C - Tutoriel SDL 2 - Python avancé - Faîtes un zeste, devenez des zesteurs

            Problème avec mon jeu tap taupe

            × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
            × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
            • Editeur
            • Markdown