Skip to content
Snippets Groups Projects
initialisation.c 2.22 KiB
Newer Older
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "initialisation.h"
int NBjoueur;
void NbJoueurs()
{
    printf("Veuillez-vous saisir le nombre des joueurs au debut:");
    scanf("%d",&NBjoueur);
    while (!(NBjoueur<=NombreMaxJoueurs)&&(NBjoueur>0))
    {
        printf("Le nombre de joueurs n'est pas valide! Veuillez-vous resaisir:");
        scanf("%d",&NBjoueur);
    }
    return;
}
PJoueur JoueurSaisie()
{
    int i;
    printf("Veuillez-vous numeroter selon votre position.\n Appuyer sur Enter pour finir la saisie \n Remarque: La personne a votre gauche correspond a numero suivant.\n");
    PJoueur p,q,head;
    head=(PJoueur)malloc(sizeof(Joueur));
    printf("Le nom du joueur N 0:");
    getchar();
    fgets(head->nom,20,stdin);
    p=head;
    printf("[DEBUG] Player's name: %s", p->nom);
    for(i=1; i<NBjoueur; i++)
    {
        q=(PJoueur)malloc(sizeof(Joueur));
        printf("Le nom du joueur N %d:",i);
        fgets(q->nom,20,stdin);
        p->next=q;
        p=q;
    }
    p->next=head;
    return head;
}

int RandomDes(int a,int NbFace)
{
    srand ((unsigned int)time(NULL)+a);
    return (rand()%NbFace+1);

}



PJoueur LePremier(PJoueur b)
{
    int num=RandomDes(0,NBjoueur)-1;
    printf("On a choisi par harsard le numero %d comme le permier joueur\n",num);
    return AvanceListe(b,num);
}

PJoueur AvanceListe(PJoueur c,int d)
{
    for(int i=0; i<d; i++) c=c->next;
    return c;
}

void DistriDes(PJoueur p)
{
    char t,u;
    int k,n=1;
    printf("Nous commencons a distribuer les des. Le premier joueur doit etre devant l'ecran.\n");
    for (int i=0; i<NBjoueur; i++)
    {

        while(1)
        {
            printf("Veuillez le joueur %s \rpresenter devant l'ecran! Vous etes le joueur %s? Y/N\n",p->nom,p->nom);

            scanf(" %c",&t);
            if(t=='y'||t=='Y')break;
        }
        printf("Votre resultat est:\n");
        for (int j=0; j<5; j++)
        {
            p->Des[j]=RandomDes(j*n,6);
            printf("%d ",p->Des[j]);
            n++;
        }


        while(1)
        {
            printf("Passer au joueur suivant? Y/N");

            scanf(" %c",&u);
            if(u=='y'||u=='Y')break;
        }
        p=p->next;
        system("clear");



    }
}