Hi,
I am just learning C, so I am sorry if my questions are trivial. I'm basically programming the "15-puzzle" which looks like this: File:15-puzzle.svg - Wikipedia, the free encyclopedia
So I'm basically writing a function init_tiles() which initializes all 16 tiles to have a color and number, and then calls initialize_tile. I know that my steps are correct, but my for loop is incorrect. The board itself is comprised of 4 rows and 4 columns, so it's length is 16. Below is my code..if someone could help me fix my for loop, I'd appreciate it greatly! I basically have to loop through each tile in my global array title_data[16][21*21] which is basically a global 2 dimensional array that holds the colors for all the pixels for all of the tiles. Row = tile #, column = pixel color.
Code:
void init_tiles(){
int col, row;
int color;
int tile_index, digit1, digit2;
for(int col = 0; col < col.length; ++col) {
for (int row = 0; row < row.length; ++row) {
// calculate the background color for each tile
if (((col + row) / 2) == 0) {
color = WHITE;
}
else {
color = RED;
}
// calculate the 2 digits placed on each tile
tile_index = col + row * 4;
digit1 = (title_index + 1) / 10;
digit2 = (title_index + 1) % 10;
initialize_tile(tile_index, digit1, digit2, color, BLACK);
}
}
// for the blank tile, set all of the pixels to BLACK
// **TO DO: FOR each pixel in the tile,
// tile_data[15][pixel] = BLACK;
for () {
tile_data[15][pixel];
}
}