Bonjour !

Avec des amies, nous travaillons sur le jeu du Puissance 4 qui nous a été imposé. Nous aimerions faire quelques améliorations, mais rencontrons quelques problèmes. Notre code est vraiment fait de façon basique, le plus "simple" pour nous, mais surement le plus compliqué..!
Nous aimerions : Rajouter des couleurs pour les pions, c'est à dire les X & 0 (rouge et jaune), mais pas sur toute la commande.

2 problèmes se posent :
  • Quand un joueur gagne, la partie ne s'arrête pas
  • Le joueur 1 est appelé par son prénom mais le 2ème n'est pas appelé par son prénom mais pas un espace vide.


Merci d'avance à ceux qui pourrons nous aider à résoudre ces problèmes!

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
#include <stdlib.h>
#include <stdio.h>
#include <time.h> 
#include <windows.h>
#include <stdbool.h>
 
	boolean isFull(int tab[6][7])
	{
		int i, j;
		for(i = 0; i < 6; i++)
		for(j = 0; j < 7; j++)
        if(tab[i][j] == 0) 
		return false;
		return true;
	}
 
int main ()
{
	int m = 0; // Entrée du menu
	int var = 0;
	srand(time(NULL));
	system("cls");
	printf("PUISSANCE 4 :\n");
 
	char nom1 [100], nom2 [101], deb;
	printf ("Joueur 1 - Entrez votre nom : ");
	scanf ("%s", &nom1); // Initialise le nom du joueur 1
	printf ("Vous avez les X. \n \n");
	printf ("Joueur 2 - Entrez votre nom : ");
	scanf ("%s", &nom2); // Initialise le nom du joueur 2
	printf ("Vous avez les O. \n \n");
	printf ("%s vous commencez.\nPour debuter la partie appuyez sur une touche.\n \n", nom1);
	scanf ("%s", &deb); 
 
	int n=0;
	srand(time(NULL));
	system("cls"); // Sortie du menu
 
	int L, C, tab[6][7]; // Tableau vide
	for (L = 0; L < 6; L++)
	{
		for (C = 0; C < 7; C++)
		{
			tab[L][C] = 0;
		}
	}
	printf("----- Puissance 4 -----\n"); // Affichage du tableau
	for (L = 0; L < 6; L++)
	{
		printf("|");
		for (C = 0; C < 7; C++)
		{
			if (tab[L][C] == 0)
			{
				printf (" _ ");
			}
			if (tab[L][C] == 1)
			{
				printf (" X ");
			}
			if (tab[L][C] == 2)
			{
				printf (" O ");
			}
		}
		printf("|\n");
	}	
	printf("-----------------------\n");
	printf("  1  2  3  4  5  6  7  \n");
 
	while (var == 0)
	{
		int col, lig, X;
		printf ("%s : Entrez un numero de colonne. \n", nom1); // Joueur 1
		scanf ("%d", &col);
		while (col < 1 || col > 7 || tab[0][col-1]!=0)
		{
			printf ("Erreur, choisissez une nouvelle colonne\n");
			scanf ("%d", &col);
		}
		col = col - 1;
		lig = 5;
		while (tab[lig][col] != 0)
		{
			lig = lig - 1;
		}
		tab[lig][col]= 1;
 
		for ( lig=0; lig < 6; lig++) // Voir si joueur 1 gagne en ligne
		{ 
			for ( col=0; col < 7; col++)
			{
				if (tab[lig][col] == tab[lig][col+1] && tab[lig][col] == tab[lig][col+2] && tab[lig][col] == tab[lig][col+3] && tab[lig][col] == 1 && col < 4)
				{
					printf ("%s gagne la partie !! \n", nom1);
					var = 1;
				}
			}
		}
		for ( lig=0; lig < 6; lig++) // Voir si joueur 1 gagne en colonne
		{ 
			for ( col=0; col < 7; col++)
			{
				if (tab[lig][col] == tab[lig+1][col] && tab[lig][col] == tab[lig+2][col] && tab[lig][col] == tab[lig+3][col] && tab[lig][col] == 1 && lig < 3) 
				{
					printf ("%s gagne la partie !! \n", nom1);
					var = 1;
				}
			}
		}
 
		for ( lig=0; lig < 6; lig++) // Voir si joueur 1 gagne en diagonal vers la droite
		{ 
			for ( col=0; col < 7; col++)
			{
				if (tab[lig][col] == tab[lig+1][col+1] && tab[lig][col] == tab[lig+2][col+2] && tab[lig][col] == tab[lig+3][col+3] && tab[lig][col] == 1 && lig < 3 && col < 4) 			
				{
					printf ("%s gagne la partie !! \n", nom1);
					var = 1;
				}
			}
		}
 
		for ( lig=0; lig < 6; lig++) // Voir si joueur 1 gagne en diagonal vers la gauche
		{ 
			for ( col=0; col < 7; col++)
			{
				if (tab[lig][col] == tab[lig-1][col-1] && tab[lig][col] == tab[lig-2][col-2] && tab[lig][col] == tab[lig-3][col-3] && tab[lig][col] == 1 && lig > 2 && col > 3) 
				{
					printf ("%s gagne la partie !! \n", nom1);
					var = 1;
				}
			}
		}
 
		printf("----- Puissance 4 -----\n"); // Affichage du tableau
		for (L = 0; L < 6; L++)
		{
			printf("|");
			for (C = 0; C < 7; C++)
			{
				if (tab[L][C] == 0)
				{
					printf (" _ ");
				}
				if (tab[L][C] == 1)
				{
					printf (" X ");
				}
				if (tab[L][C] == 2)
				{
					printf (" O ");
				}
			}
		printf("|\n");
		}
		printf("-----------------------\n");
		printf("  1  2  3  4  5  6  7  \n");
 
		printf ("%s : Entrez un numero de colonne. \n", nom2); // Joueur 2
		scanf ("%d", &col);
		while (col < 1 &&col > 7)
		{
			printf ("Erreur, choisissez une nouvelle colonne\n");
			scanf ("%d", &col);
		}
 
		col = col - 1;
		lig = 5;
 
		while ( tab[lig][col] != 0)
		{
			lig = lig - 1;
		}
 
		tab[lig][col]= 2;
 
		for ( lig=0; lig < 6; lig++) // Voir si joueur 2 gagne en ligne
		{ 
			for ( col=0; col < 7; col++)
			{
				if (tab[lig][col] == tab[lig][col+1] && tab[lig][col] == tab[lig][col+2] && tab[lig][col] == tab[lig][col+3] && tab[lig][col] == 2 && col < 4)
				{
				printf ("%s gagne la partie !! \n", nom2);
				var = 2;
				}
			}
		}
 
		for ( lig=0; lig < 6; lig++) // Voir si joueur 2 gagne en colonne
		{ 
			for ( col=0; col < 7; col++)
			{
				if (tab[lig][col] == tab[lig+1][col] && tab[lig][col] == tab[lig+2][col] && tab[lig][col] == tab[lig+3][col] && tab[lig][col] == 2 && lig < 3)
				{
				printf ("%s gagne la partie !! \n", nom2);
				var = 2;
				}
			}
		}
 
		for ( lig=0; lig < 6; lig++) // Voir si joueur 2 gagne en diagonal vers la droite
		{ 
			for ( col=0; col < 7; col++)
			{
				if (tab[lig][col] == tab[lig+1][col+1] && tab[lig][col] == tab[lig+2][col+2] && tab[lig][col] == tab[lig+3][col+3] && tab[lig][col] == 2 && lig < 2 && col < 3) 
				{
				printf ("%s gagne la partie !! \n", nom2);
				var = 2;
				}
			}
		}
 
		for ( lig=0; lig < 6; lig++) // Voir si joueur 2 gagne en diagonal vers la gauche
		{ 
			for ( col=0; col < 7; col++)
			{
				if (tab[lig][col] == tab[lig-1][col-1] && tab[lig][col] == tab[lig-2][col-2] && tab[lig][col] == tab[lig-3][col-3] && tab[lig][col] == 2 && lig > 2 && col > 3) 
				{
				printf ("%s gagne la partie !! \n", nom2);
				var = 2;
				}
			}
		}
 
		printf("----- Puissance 4 -----\n"); // Affichage du tableau
		for (L = 0; L < 6; L++)
		{
			printf("|");
			for (C = 0; C < 7; C++)
			{
				if (tab[L][C] == 0)
				{
					printf (" _ ");
				}
				if (tab[L][C] == 1)
				{
					printf (" X ");
				}
				if (tab[L][C] == 2)
				{
					printf (" O ");
				}
			}
			printf("|\n");
		}
		printf("-----------------------\n");
		printf("  1  2  3  4  5  6  7  \n");
 
		if(isFull(tab))
		printf ("Match nul !! \n");
	}
		return 0;
}