Basically I\'m creating a board game in java and have managed to create cells, using arrays, to look like a 10x10 grid. Now I\'ve numbered them they go from left to right t
Ok so I won't write the exact code for you, but I'll show you an example of how to do it with a regular 2D array. I only have a C++ compiler available right now, but it should be clear enough:
So basically you need to cycle through rows from end to start. That's why the first, outer loop you're going from 9 to 0. This will start at bottom row and finish at the top row, thus reversing.
for (int i = 9; i >= 0; i--) {
// now the trick to making a "zig-zag" is to alternate between two ways
// of printing out each row. if i is even, you print out from right to left
if (i % 2)
for (int j = 9; j >= 0; j--)
cout << numbers[i][j] << "\t";
// and if i is odd, you print it out from left to right
else
for (int j = 0; j < 10; j++)
cout << numbers[i][j] << "\t";
cout << endl;
}
Result: