Skip to content
Snippets Groups Projects
Commit 8b7fb30e authored by Liu Yiqun's avatar Liu Yiqun
Browse files

input user names and randomly generate users' dices.

parent e3da282b
No related branches found
No related tags found
No related merge requests found
#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");
}
}
#include <string.h>
#define NombreMaxDes 30
#define NombreMaxJoueurs 6
enum DICE {Paco,deux,trois,quatre,cinq,six};
typedef struct
{
char nom[20];
unsigned int NombreDes;
int Des[5];
struct Joueur *next;
} Joueur,*PJoueur;
typedef struct
{
enum DICE face;
unsigned int value;
struct Annonce *next;
} Annonce;
typedef struct
{
Joueur * first;
Joueur * current;
} ListJoueur;
typedef struct
{
Annonce * first;
Annonce * current;
} ListAnnonce;
PJoueur JoueurSaisie();
void NbJoueurs();
int RandomDes();
PJoueur LePremier();
Joueur CreLink(int n);
PJoueur AvanceListe(PJoueur c,int d);
void DistriDes(PJoueur p);
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "initialisation.h"
int main()
{
PJoueur a,b;
extern int NBjoueur;
printf("Bienvenu! Cher joueur!\n");
NbJoueurs();
//'printf("%d",NBjoueur);
a=JoueurSaisie();
//b=a->next;
//c=b->next;
//printf('''');
/*int i;
for(i=1;i<100;i++){
printf("%d",RandomDes(i));
}*/
b =LePremier(a);
printf("Le premier joueur est joueur: %s",b->nom);
DistriDes(b);
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment