#include <stdio.h> #include <stdlib.h> #include <time.h> #include "initialisation.h" int numJoueur; // TODO bug if input a string static int inputYN() { char tmp; scanf("%c", &tmp); getchar(); return (tmp == 'y' || tmp == 'Y'); } void presenceJoueur(Joueur* current) { while (1) { printf("\nVeuillez le joueur \"%s\" presenter devant l'ecran!\n", current->nom); printf("Vous etes le joueur \"%s\"? Y/N ", current->nom); if (inputYN()) break; } } void JoueurSuivant() { while (1) { printf("Passer au joueur suivant? Y/N "); if (inputYN()) break; } return; } void inputPlayersNum() { printf("Veuillez-vous saisir le nombre des joueurs au debut: "); scanf("%d", &numJoueur); while (numJoueur > MAX_JOUEURS || (numJoueur <= 1)) { printf("Le nombre de joueurs n'est pas valide!"); printf("Veuillez-vous resaisir: "); scanf("%d", &numJoueur); } getchar(); } Joueur* saisirJoueur() { 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,*head; int i; for (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 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; int i; for (i = 0; i < num; i++) tmp = tmp->next; return tmp; } void distribuerDes(Joueur* p) { printf("\nNous commencons a distribuer les des.\n"); printf("Le premier joueur \"%s\" doit etre devant l'ecran.\n", p->nom); int i; int j; for (i = 0; i < numJoueur; i++) { presenceJoueur(p); printf("\nVotre resultat est: "); for (j = 0; j < 5; j++) { p->des[j] = randInt(6); (p->des[j]==1)?printf("paco "):printf("%d ", p->des[j]); } p->nombreDes=5; printf("\n"); while (i < numJoueur - 1) { JoueurSuivant(); break; } p = p->next; system("clear"); } printf("All players' dices are given.\n"); }