Vous êtes sur la page 1sur 4

1: #include<stdio.

h>
2: #include<string.h>
3: #include<stdlib.h>
4: #include<time.h>
5: #define MAX 100
6:
7: int jet_des();
8: void affiche (int de[]);
9: void yatzee ();
10: void rejouer(int de[]);
11: void occurence (int de[],int tab_occurence[]);
12: void affiche_scores( int points[]);
13: void init_scores(int points[]);
14: void tab_scores1 ( int tab_occurence[],int numero,int de[],int tab_scores[]);
15:
16: void tab_scores1 ( int tab_occurence[],int numero,int de[],int tab_scores[])
17: {
18: int i,a,b;
19: switch(numero)
20: {
21: case 1: tab_scores[1]=tab_occurence[1]*1; break;
22: case 2: tab_scores[2]=tab_occurence[2]*2; break;
23: case 3: tab_scores[3]=tab_occurence[3]*3; break;
24: case 4: tab_scores[4]=tab_occurence[4]*4; break;
25: case 5: tab_scores[5]=tab_occurence[5]*5; break;
26: case 6: tab_scores[6]=tab_occurence[6]*6; break;
27: case 7:for(i=0;i<=5;i++)
28: {
29: if(tab_occurence[i]==3)
30: {
31: tab_scores[7]=3*(i+1);
32: }
33: }
34: ;break;
35:
36: case 8:for(i=0;i<=5;i++)
37: {
38: if(tab_occurence[i]==3)
39: {
40: a=3*(1+i);
41: }
42: if(tab_occurence[i]==2)
43: {
44: b=2*(1+i);
45: }
46: }
47: tab_scores[10]=a+b;
48: ;break;
49: case 9:for(i=0;i<=5;i++)
50: {
51: if(tab_occurence[i]==4)
52: {
53: tab_scores[8]=4*(1+i);
54: }
55: }
56: ; break;
57: case 10:for(i=0;i<=5;i++)
58: {
59: if(tab_occurence[i]==5)
60: {
61: tab_scores[10]=5*(i+1);
62: }
63: }
64: ; break;
65:
66: }
67: }
68:
69:
70:
71: void init_scores(int points[])
72: {
73: int i;
74: for(i=0;i<=10;i++)
75: {
76: points[i]=-1;
77: }
78: }
79:
80: void affiche_scores( int points[])
81: {
82: int i=-1;
83: printf("1 : Un ==>");printf("%d \n",points[1]);
84: printf("2 : Deux ==>");printf("%d \n",points[2]);
85: printf("3 : Trois ==>");printf("%d \n",points[3]);
86: printf("4 : Quatre ==>");printf("%d \n",points[4]);
87: printf("5 : Cinq ==>");printf("%d \n",points[5]);
88: printf("6 : Six ==>");printf("%d \n",points[6]);
89: printf("7 : Brelan ==>");printf("%d \n",points[7]);
90: printf("8 : Full ==>");printf("%d \n",points[8]);
91: printf("9 : Carre ==>");printf("%d \n",points[9]);
92: printf("10 : Yatzee ==>");printf("%d \n",points[10]);
93: printf("===============================================");
94: printf("\n");
95:
96: }
97:
98: void occurence (int de[],int tab_occurence[])
99: {
100: int i;
101: for (i=0;i<=6;i++)
102: {
103: tab_occurence[i]=0;
104: }
105:
106: for (i=0;i<=6;i++)
107: {
108: switch(de[i])
109: {
110: case 1: tab_occurence [1]++;break;
111: case 2: tab_occurence [2]++;break;
112: case 3: tab_occurence [3]++;break;
113: case 4: tab_occurence [4]++;break;
114: case 5: tab_occurence [5]++;break;
115: case 6: tab_occurence [6]++;break;
116: }
117: }
118:
119: }
120:
121: int jet_des()
122: {
123: return (rand()%6)+1;
124: }
125:
126:
127: void affiche (int de[])
128: {
129: int i;
130:
131: printf ("Resultats du lancer\n\n");
132: printf("a\tb\tc\td\te\t\n");
133: for(i=0;i<=4;i++)
134: { printf("%d\t",de[i]);}
135: printf("\n");
136: }
137:
138: void rejouer(int de[])
139: {
140: int i;
141: char a,b,c,d,e;
142: char choix[MAX];
143: fflush(stdin);
144: printf("\n Quels des voulez vous rejouer a b c d e ou [-] pour tout garder
:\n");
145: scanf("%s",choix);
146: for (i=0;i<strlen(choix);i++)
147: {
148: switch(choix[i])
149: {
150: case 'a' : de[0]=jet_des(); break;
151: case 'b' : de[1]=jet_des(); break;
152: case 'c' : de[2]=jet_des(); break;
153: case 'd' : de[3]=jet_des(); break;
154: case 'e' : de[4]=jet_des(); break;
155: case '-' : break;
156: }
157: }
158: }
159:
160: void yatzee ()
161: {
162: int j,i,de[MAX],tab_occurence[MAX],points[MAX],numero;
163: init_scores(points);
164: j=0;
165: do
166: {
167:
168: affiche_scores(points);
169: for (i=0;i<=4;i++)
170: {de[i]=jet_des();}
171: affiche (de);
172: for (i=0;i<=1;i++)
173: {
174: rejouer(de);
175: affiche(de);
176: }
177: occurence(de,tab_occurence);
178: printf("Entrer le numero de votre choix:\n");
179: scanf("%d",&numero);
180: tab_scores1(tab_occurence,numero,de,points);
181:
182: j=j+1;
183: }
184: while (j<=10);
185: }
186:
187: int main (void)
188: {
189: printf("Bienvenue au jeu du YATZEE:\n\n");
190: srand((unsigned)time(NULL));
191: yatzee();
192: system("pause");
193: return 0;
194: }
195: