#include <stdio.h> #include <stdlib.h> #include <time.h> #include "initialisation.h" // TODO bug if input a string static int inputYN() { char tmp; scanf("%c", &tmp); getchar(); return (tmp == 'y' || tmp == 'Y'); } int inputPlayersNum() { int num; printf("Veuillez-vous saisir le nombre des joueurs au debut: "); scanf("%d", &num); while (num > MAX_JOUEURS || (num <= 0)) { printf("Le nombre de joueurs n'est pas valide!"); printf("Veuillez-vous resaisir: "); scanf("%d", &num); } getchar(); return num; } Joueur* saisirJoueur(int numJoueur) { printf("\nVeuillez-vous numeroter selon votre position.\n"); printf("Appuyer sur Enter pour finir la saisie.\n"); printf( "Remarque: La personne a votre gauche correspond a numero suivant.\n"); Joueur *p, *q, *head; for (int i = 1; i < numJoueur + 1; i++) { if (i == 1) { p = (Joueur*) malloc(sizeof(Joueur)); head = p; } else { p->next = (Joueur*) malloc(sizeof(Joueur)); p = p->next; } printf("Le nom du joueur N %d: ", i); fgets(p->nom, 20, stdin); p->nom[strlen(p->nom) - 1] = 0; } p->next = head; return head; } /** * Return an integer number between [1, max] */ int randInt(int max) { return (rand() % max + 1); } Joueur* getPremierJoueur(Joueur* head, int numJoueur) { int num = randInt(numJoueur) - 1; printf("On a choisi par harsard le numero %d comme le permier joueur\n", num + 1); return getJoueur(head, num); } Joueur* getJoueur(Joueur* head, int num) { Joueur *tmp = head; for (int i = 0; i < num; i++) tmp = tmp->next; return tmp; } void distribuerDes(Joueur* p, int numJoueur) { char t; printf("\nNous commencons a distribuer les des.\n"); printf("Le premier joueur \"%s\" doit etre devant l'ecran.\n", p->nom); for (int i = 0; i < numJoueur; i++) { while (1) { printf("\nVeuillez le joueur \"%s\" presenter devant l'ecran!\n", p->nom); printf("Vous etes le joueur \"%s\"? Y/N ", p->nom); if (inputYN()) break; } printf("\nVotre resultat est: "); for (int j = 0; j < 5; j++) { p->des[j] = randInt(6); printf("%d ", p->des[j]); } printf("\n"); while (i < numJoueur - 1) { printf("Passer au joueur suivant? Y/N "); if (inputYN()) break; } p = p->next; // system("clear"); } printf("All players' dices are given.\n"); }