c# - Checking collisions 2D array connect 4 -
c# - Checking collisions 2D array connect 4 -
i'm trying create 2d connect 4 game in c#. know when 4 colors have match. anyway i'm trying collisions work maintain getting error saying "index outside bounds of array" know why is? thanks
private void rules() { int count = 0; if (btn[maxr, maxc].backcolor == color.red) { count = 1; } (int = 0; <= btn.length; i++) { if (btn[maxr, i].backcolor == color.red) { count++; } } if (count >= 4) { lbl2.text = "winner"; }
you used:
i <= btn.length
and causes out of range exception, because index starts 0 , ends in btn.length-1
.
so utilize :
for (int = 0; < btn.length; i++)
p.s: don't know if there logical error.
c# arrays 2d collisions
Comments
Post a Comment