Пример #1
0
void start_game(int nbjoueur,joueur jou[],int tourde)

{
    int i,tour,j,k,testInt,flag[10],nbfixe,place_de_des,lance,x,*combinaison,finale,gameover;
    char arrete,testChar;
    srand((unsigned)time(NULL));
    while(gameover!=1) //pour voir si le jeu est fini
    {
        for (x=tourde; x<=nbjoueur; x++) //voir c'est le tour de qui à jouer(premier si c'est une nouvelle partie, mais sa peut être une autre personne qui débute, si c'est un jeu que l'on a chargé)
        {
            printf("Tour numero %d de %s\n",jou[x-1].tour,jou[x-1].nom);
            for (j= 0; j<5; j++) //initialisation des flag de dé
            {
                flag[j]=0;
            }
            affiche_table(&jou[x-1]); //affiche la table de resultat
            for (lance=1; lance<=3; lance++) //lancement 3 fois
            {

                combinaison=lancer(flag); //on met dans combinaison l'address du tableau qui est retourner de la fonction lancer

                if (lance==3) //si on a fait 3 lancer,on fixe tout les dés qui reste
                {
                    for (i=0; i<nbfixe; i++)
                    {
                        flag[i]=1;
                    }
                    break;
                }
                else //si c'est moins que 3 lancer
                {

                    for(k=0; k>=0; k++)
                    {
                        printf("Combien de dés voulez-vous fixer ? (Entre 0 et 5) : ");
                        testInt=scanf("%d",&nbfixe);
                        if (testInt!=1 || nbfixe<0 || nbfixe>5 ) //verification des données
                        {
                            printf("Erreur, Le nombre doit être compris entre 0 et 5!\nRéessayer\n");
                            while ((testChar = getchar())!= '\n');
                        }

                        else if(nbfixe>=0 && nbfixe<=5) //si on a obtenue un bon nombre on sort de la boucle
                        {
                            break;
                        }

                    }

                    if (nbfixe == 5 || (flag[0]==1 && flag[1]==1 && flag[2]==1 && flag[3]==1 && flag[4]==1)) //si tout les des sont fixe,c'est pas utile de faire un autre lancer
                    {
                        for (i=0; i<nbfixe; i++)
                        {
                            flag[i]=1;
                        }
                        break;

                    }
                    else if (nbfixe == 0) //si il n'y a pas de des fixe,on continue de lancer
                    {
                        continue;
                    }
                    else
                    {

                        printf("Choisi les %d dés que tu veux fixer :\n",nbfixe);
                        for (i=0; i<nbfixe; i++) 
                        {
                            for (k=0; k>=0; k++)
                            {
                                printf("Des %d: ",i+1);
                                testInt=scanf("%d",&place_de_des);
                                if (testInt!=1 || place_de_des<1 || place_de_des>5 ) //verification du nombre
                                {
                                    printf("Erreur ! Le nombre doit etre compris entre 1 et 5 !\nRéessayer!!\n");
                                    while ((testChar = getchar())!= '\n'); //pour ne pas prendre des caracteres inutile
                                }
                                else if(place_de_des >= 1 && place_de_des<=5)
                                {
                                    break;
                                }

                            }


                            if (flag[place_de_des-1]==1) //si le des sont deja fixe,sa ne va pas changer
                            {
                                printf("Des numero %d est deja fixe\n",place_de_des);
                            }
                            else flag[place_de_des-1]=1; //si ce n'est pas fixé,on le fixe
                        }

                        if ((flag[0]==1 && flag[1]==1 && flag[2]==1 && flag[3]==1 && flag[4]==1)) //on verifie si tout les des sont fixé,on va a la fonction decision
                        {
                            break;
                        }

                    }

                }
            }
            printf("\n");
            system("clear");
            printf("Combinaison final : \n"); //affiche le resultat final
            for (finale=0; finale<5; finale++)
            {
                printf("%d\t",combinaison[finale]);
            }
            printf("\n");

            decision(combinaison,&jou[x-1]); //aller a la fonction de decision
            printf("TOTAL = %d\n",jou[x-1].total); //affiche le total de joueurs 
            gameover=gameovercheck(jou,nbjoueur); //voir si le jeu est terminer

            arrete=pause();//demande si il veut arreter
            if (arrete=='p' || arrete=='P')
            {
                call_menu_jeu(jou,nbjoueur); //appelle le menu 
            }
            else
            {
                continue; //aller au tour suivant
            }
        }
    }

    affiche_score(nbjoueur,jou); //apres que le jeu est fini,on affiche qui a gagner,et on etudie si on va placer les score dans le fichier de 10 meilleurs scores
    call_menu(); //on appelle le menu
}
Пример #2
0
bool Morpion()
{
    SDL_Surface *screen = NULL, *texte[3] = {NULL,NULL,NULL};
    SDL_Rect posBlock[9], posFond, posTexte[3];
    SDL_Event event_morpion;
    IMAGE images;

    bool continuer = true, correct = false, rejouer = true, full_case = false,finJeux = true;
    int joueur = 1;
    int blocks[9], i, block_boutton;
    int pointJ[2] = {0}, manche = 1;
    int n = 9;
    const int jeu = MORPION;

    /******************************************************************************/
    screen = SDL_GetVideoSurface();
    verifSetVideo(screen);
    iniPos(&posFond,0,0);

    for(i=0; i<9; i++)
    {
        blocks[i] = RIEN;
        posBlock[i].x = (Sint16)(MIN + ((i%3)*TAILLE));
        posBlock[i].y = (Sint16)(MAX + ((i/3)*TAILLE));
    }

    /* position police */
    for(i=0; i<2; i++)
    {
        posTexte[i].x = 125;
        posTexte[i].y = (Sint16)(555 + (22*i));
    }

    iniPos(&posTexte[2],322,577);

    /******************************************************************************/

    initialiseImagesMorpion(&images);
    verifChargImage(images.fond);
    verifChargImage(images.croix);
    verifChargImage(images.rond);

    /******************************************************************************/

    SDL_WM_SetCaption("Morpion", NULL);

    /******************************************************************************/

    SDL_BlitSurface(images.fond, NULL,screen, &posFond);
    SDL_Flip(screen);


    while(rejouer)
    {
        full_case = false;
        continuer = true;
        while(continuer == true)
        {
            block_boutton = 0;
            if (joueur == 1)
                joueur++;
            else
                joueur--;
            /**********/
            if (joueur == 2) /*IA*/
            {
                i = verifie(blocks);
                if (i != -1)
                {
                    blocks[i] = ROND;
                    if(check(blocks,&full_case))
                        continuer=false;
                }
                else if(continuer)
                {
                    do
                    {
                        i=(rand()%9);
                    }
                    while(blocks[i] != RIEN);
                    blocks[i] = ROND;
                }

                if(check(blocks,&full_case))
                    continuer=false;
            }
            /**********/
            else if (joueur&&continuer)
            {
                do
                {
                    correct = false;
                    SDL_WaitEvent(&event_morpion);
                    switch(event_morpion.type)
                    {
                    case SDL_QUIT:
                        correct = true;
                        continuer = false;
                        rejouer = false;
                        finJeux = false;
                        break;

                    case SDL_KEYDOWN:
                        switch (event_morpion.key.keysym.sym)
                        {
                        case SDLK_ESCAPE:
                            if(afficherMenuJeux(jeu))
                            {
                                correct = true;
                                continuer = false;
                                rejouer = false;
                            }
                            else
                            {
                                initialiseImagesMorpion(&images);
                                SDL_BlitSurface(images.fond,NULL,screen,&posFond);
                                affiche_score(texte, manche,pointJ, posTexte);

                                for(i=0; i<9; i++)
                                {
                                    if(blocks[i]==CROIX)
                                        SDL_BlitSurface(images.croix, NULL,screen, &posBlock[i]);
                                    else if(blocks[i]==ROND)
                                        SDL_BlitSurface(images.rond, NULL,screen, &posBlock[i]);

                                }
                                SDL_Flip(screen);
                            }
                            break;

                        default :
                            break;
                        }
                        break;

                    case SDL_MOUSEBUTTONUP:
                        switch(event_morpion.button.button)
                        {
                        case SDL_BUTTON_LEFT:
                            block_boutton = testPos(posBlock, TAILLE,TAILLE,n,event_morpion);
                            if (block_boutton > -1 && blocks[block_boutton] == RIEN)
                            {
                                blocks[block_boutton] = CROIX;
                                if(check(blocks, &full_case))
                                {
                                    continuer=false;
                                }
                                correct = true;
                            }
                            else if(block_boutton == -2)
                            {
                                if(afficherMenuJeux(jeu))
                                {
                                    correct = true;
                                    continuer = false;
                                    rejouer = false;
                                }
                                else
                                {
                                    initialiseImagesMorpion(&images);
                                    SDL_BlitSurface(images.fond,NULL,screen,&posFond);
                                    affiche_score(texte, manche,pointJ, posTexte);

                                    for(i=0; i<9; i++)
                                    {
                                        if(blocks[i]==CROIX)
                                            SDL_BlitSurface(images.croix, NULL,screen, &posBlock[i]);
                                        else if(blocks[i]==ROND)
                                            SDL_BlitSurface(images.rond, NULL,screen, &posBlock[i]);

                                    }
                                    SDL_Flip(screen);
                                }
                            }
                            break;

                        default :
                            break;
                        }
                        break;

                    default :
                        break;
                    }
                }
                while(!correct);
            }
            SDL_BlitSurface(images.fond, NULL,screen, &posFond);
            for(i=0; i<9; i++)
            {
                if(blocks[i]==CROIX)
                    SDL_BlitSurface(images.croix, NULL,screen, &posBlock[i]);
                else if(blocks[i]==ROND)
                    SDL_BlitSurface(images.rond, NULL,screen, &posBlock[i]);
            }
            affiche_score(texte, manche,pointJ, posTexte);
            SDL_Flip(screen);
        }
        if(rejouer)
        {
            SDL_Delay(1500);
            if(!full_case)
                pointJ[joueur - 1]++;
            manche++;
        }

        for(i=0; i<9; i++)
        {
            blocks[i] = RIEN;
        }

        SDL_BlitSurface(images.fond, NULL,screen, &posFond);
        affiche_score(texte, manche,pointJ, posTexte);
        SDL_Flip(screen);

    }

    /******************************************************************************/

    SDL_FreeSurface(images.fond);
    SDL_FreeSurface(images.croix);
    SDL_FreeSurface(images.rond);
    return finJeux;
}