Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to examine an Array for .Text values
    primarykey
    data
    text
    <p>This is for a tic tac toe game where the grid can be sized to any number (3x3 4x4 8x8 etc)</p> <p>When the form loads, a method reads the grid size and populates the form with that many buttons in a 1 dimensional Button Array. The Array is called buttonArray.</p> <p>With just using the 1-dimensional buttonArray and without using LINQ, how can i compare the .Text values of buttons in buttonArray to see if they are either "X" or "O" for a CheckWinner() function. </p> <p>After the button grid is created, I have an event handler for button clicks :</p> <pre><code>private void button_click(object sender, EventArgs e) { Button b = (Button)sender; b.Text = "X"; b.Enabled = false; CheckWinner(buttonArray); } </code></pre> <p>I am then calling my CheckWinner function and passing in the array buttonArray.</p> <p>Again, I am just looking for a primitive way to check/compare values without using LINQ. If I know the length of each side of the grid, I can say that for Horizontal win lines, I am looking for that many buttons in a row with "X" as their .Text property.</p> <p>So if I have a grid of 5x5, and I have 25 buttons in buttonArray, how can i check every 5 starting at the 0 index of the grid for their .Text values being "X" and then print a message if 5 in a row are the same, or "X" in this case.</p> <pre><code>for (int z = 0; z &lt; root; z++) //increments the column to start on { vCount = 0; //Starts the win counter at zero when moving to the next column for (int i = z; i &lt; arrLength; i=i+root) //starts at the first column and increments it by root to test the next button in the column { string bText = buttonArray[i].Text; if (bText == "X") vCount++; if (vCount == root) { MessageBox.Show("Vertical row winner found !"); break; } } }//end of vertical column test </code></pre> <p>I did the vertical test like that? But I think combining them into one would def be better.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload