Note that there are some explanatory texts on larger screens.

plurals
  1. POIterating through an Array for .Text values
    primarykey
    data
    text
    <p>I am making a Windows Forms Tic-Tac-Toe program that has a grid size set by a value in the App.config file. So if the value is 9, the grid is the regular 3 x 3, if its 25, its a 5 x 5 etc.</p> <p>I have a Gameboard class that makes the actual buttons for the array:</p> <pre><code>public Gameboard(int numberofButtons) //Constructor method that is referencing the App.config for the dimensions value to make the board { buttonArray = new Button[numberofButtons]; //creating an array the size of numberofButtons which is the dimensions value from App.config Font font = new Font("Times New Roman", 36.0f); //creates an instance of the Font class int sqrtY = (int) Math.Sqrt(numberofButtons); int z = 0; //Counter for array //Create the buttons for the form for (int x = 0; x &lt; sqrtY; x++) { for (int y = 0; y &lt; sqrtY; y++) { buttonArray[z] = new Button(); buttonArray[z].Font = font; buttonArray[z].Size = new System.Drawing.Size(100, 100); buttonArray[z].Location = new System.Drawing.Point(100*y, 100*x); buttonArray[z].Click += new EventHandler(button_click); z++; } } } </code></pre> <p>If i want to check for win patters in the array by simply checking the value of buttonArray.Text for positions in the buttonArray, how can I iterate through that?</p> <p>for example in a 4x4 grid, the winlines for horizontal wins would be </p> <pre><code>0,1,2,3 4,5,6,7 8,9,10,11 12,13,14,15 </code></pre> <p>so</p> <pre><code>x=0, x&lt;sqrt(dimension), x++ buttonArray[x].Text == "X" &lt;-- to test </code></pre> <p>I realize this is really poorly coded and confusing but I am trying to do this with a single dimension array because that is what the teacher asked for. I want to check the values of <code>buttonArray[]</code> for a value, first checking the rows, then the columns, then the diagonals.</p> <p>The Form has no buttons so when the Form loads it populates it with the buttons used for the grid. It is meant to play against the computer so when you click a button, the .Text becomes "X" and then the computer is supposed to put down an "O" and so on. </p>
    singulars
    1. This table or related slice is empty.
    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