I am trying to make a Tic Tac Toe game using objects, classes, etc. However, the user can input an option so that he/she can set the size of the board. At the moment, it can only do square shapes (3×3, 4×4, etc).
I have a diagram drawn out on a white board to explain what I will talk about next (ignore the right side about orders and raw axis, that’s for something else. Also all that really needs to be focused on is the table and for code): http://d.pr/i/5CY8
The width and height of the game board is set by the size the user imports (number by number). I then have two for loops to create a pointer to a new Square each time. An array list will hold our squares. However due to the location of the array list (it is in a header), I cannot assign the size of the two-dimensional array when it is created. Therefore, I need to dynamically allocate the size so I can set the size of the array so that the array list holding the squares when the size is inputted. However, I cannot figure out how to do this.
I have the code both in Pastebin and in Visual Studio 2012. I believe it would be easier to view the Visual Studio files, since there will be many Pastebin links.
List of links to Visual Studio files/code on Pastebin (sorry, I hit my link limit!): http://pastebin.com/spH3JaHP
It looks like you’re using a 10×10 array (different from an arraylist/vector) to store your board state. The proper way to declare a 2-d array during runtime would be the
new[]operator. For example:You can then use boardArray as any old 2D array.