Bonjour, pour parfaire mon projet, je voulais créer un panel qui affiche le nombre de 0 et 1 dans les lignes et colonnes. j`ai écris un code pour ça mais le problème il affiche que le nombre de 0 et 1 initialement.
// #### Ajuster les annotations
// On parcours la grille case par case, ligne par ligne et colonne par colonne et on fait la somme des '0' et des '1'
{ for (int j = 0; j < 8; j++) { string val = (grille[j, 0].Text); if (val == "0") { total_0 += 1; } if (val == "1") { total_1 += 1; }}
label1.Text = $"{total_0} / {total_1} ";total_0 = total_1 = 0;
for (int j = 0; j < 8; j++) { string val = (grille[j, 1].Text); if (val == "0") { total_0 += 1; } if (val == "1") { total_1 += 1; } }
label2.Text = $"{total_0} / {total_1} "; total_0 = total_1 = 0;
for (int j = 0; j < 8; j++) { string val = (grille[j, 2].Text); if (val == "0") { total_0 += 1; } if (val == "1") { total_1 += 1; } }
label3.Text = $"{total_0} / {total_1} "; total_0 = total_1 = 0;
for (int j = 0; j < 8; j++) { string val = (grille[j, 3].Text); if (val == "0") { total_0 += 1; } if (val == "1") { total_1 += 1; } }
label4.Text = $"{total_0} / {total_1} "; total_0 = total_1 = 0;
for (int j = 0; j < 8; j++) { string val = (grille[j, 4].Text); if (val == "0") { total_0 += 1; } if (val == "1") { total_1 += 1; } }
label5.Text = $"{total_0} / {total_1} "; total_0 = total_1 = 0;
for (int j = 0; j < 8; j++) { string val = (grille[j, 5].Text); if (val == "0") { total_0 += 1; } if (val == "1") { total_1 += 1; } }
label6.Text = $"{total_0} / {total_1} "; total_0 = total_1 = 0;
for (int j = 0; j < 8; j++) { string val = (grille[j, 6].Text); if (val == "0") { total_0 += 1; } if (val == "1") { total_1 += 1; } }
label7.Text = $"{total_0} / {total_1} "; total_0 = total_1 = 0;
for (int j = 0; j < 8; j++) { string val = (grille[j, 7].Text); if (val == "0") { total_0 += 1; } if (val == "1") { total_1 += 1; } }
label8.Text = $"{total_0} / {total_1} ";
for (int j = 0; j < 8; j++) { string val = (grille[0, j].Text); if (val == "0") { total_0 += 1; } if (val == "1") { total_1 += 1; } }
label9.Text = $"{total_0} / {total_1} "; total_0 = total_1 = 0;
for (int j = 0; j < 8; j++) { string val = (grille[1, j].Text); if (val == "0") { total_0 += 1; } if (val == "1") { total_1 += 1; } }
label10.Text = $"{total_0} / {total_1} "; total_0 = total_1 = 0;
for (int j = 0; j < 8; j++) { string val = (grille[2, j].Text); if (val == "0") { total_0 += 1; } if (val == "1") { total_1 += 1; } }
label11.Text = $"{total_0} / {total_1} "; total_0 = total_1 = 0;
for (int j = 0; j < 8; j++) { string val = (grille[3, j].Text); if (val == "0") { total_0 += 1; } if (val == "1") { total_1 += 1; } }
label12.Text = $"{total_0} / {total_1} "; total_0 = total_1 = 0;
for (int j = 0; j < 8; j++) { string val = (grille[4, j].Text); if (val == "0") { total_0 += 1; } if (val == "1") { total_1 += 1; } }
label13.Text = $"{total_0} / {total_1} "; total_0 = total_1 = 0;
for (int j = 0; j < 8; j++) { string val = (grille[5, j].Text); if (val == "0") { total_0 += 1; } if (val == "1") { total_1 += 1; } }
label14.Text = $"{total_0} / {total_1} "; total_0 = total_1 = 0;
for (int j = 0; j < 8; j++) { string val = (grille[6, j].Text); if (val == "0") { total_0 += 1; } if (val == "1") { total_1 += 1; } }
label15.Text = $"{total_0} / {total_1} "; total_0 = total_1 = 0;
for (int j = 0; j < 8; j++) { string val = (grille[7, j].Text); if (val == "0") { total_0 += 1; } if (val == "1") { total_1 += 1; } }
label16.Text = $"{total_0} / {total_1} ";
etat = Etat.Initial;
}
A voir également:
Implémentez les annotations des lignes et colonnes
Bonsoir
Quand Whismeril que je salue parlait d'instructions il parlait du code et non de ce le projet devait faire
Maintenant ton code est vraiment illisible .
Et sans aucun commentaire dedans difficile de s'y retrouver
De plus je vois 16 boucles For qui ont des ressemblances évidentes : il y a de l'optimisation à faire
je me suis permis de transformer ton commentaire en réponse afin de ne pas ajouté de confusion.
Il est clairement écrit dans ses instructions que la mise à jour au fil de l'eau doit être déclenchée ailleurs.
Il n'a pas présenté la partie du code à modifier pour que cette mise à jour ait lieu.
Pas de nouvelles de sa part, pas d'aide supplémentaire possible.
Et si le code est aussi mal présenté, je ne le lirai pas plus que celui déjà montré.
Merci, pour votre suggestion.
Je veux annoter le nombre de 0 et 1 dans les lignes et ainsi dans les colonnes.
Le problème est que quand j utilise cette méthode il affiche seulement le nombre de 0 et 1 qu on a dans les lignes et colonnes au départ. Ça ne modifie pas si on entre un 0 ou 1
Vous n’avez pas trouvé la réponse que vous recherchez ?
/*Implémentez les annotations des lignes et colonnes un peu comme sur l’image
du jeu fournie au tout début en exemple.
Il vous faut donc implémenter la classe Annotation que nous n’avons fait que
déclarer jusqu’à maintenant. N’oubliez pas d’ajuster le code du Binero afin que
vos annotations se tiennent à jour au fur et à mesure d’une partie.
La classe Annotation hérite de Panel. Cela vous laisse toute latitude pour y
placer des composantes.
HINT : Ma version utilise des composantes de la classe Label, mais on pourrait
aussi y arriver autrement.*/