char house =
" ______________ "
" |______________| "
" _______________________________________| |_____ "
" ' |____________| ` "
" | | "
" '-----------------------------------------------------------' "
" | 1 2 3 | "
" | +-----------+ +-----------+ +-----------+ | "
" | | | | | | | | "
" | | | | | | | | "
" | | | | | | | | "
" | +-----------+ +-----------+ +-----------+ | "
" | 4 5 6 | "
" | +-----------+ +-----------+ +-----------+ | "
" | | | | | | | | "
" | | | | | | | | "
" _ | | | | | | | | "
" |#|| +-----------+ +-----------+ +-----------+ | "
" |_|| 7 8 9 | "
" `-| +-----------+ +-----------+ +-----------+ | "
" - | | | | | | | "
" ' | | | | | | | "
" ' | | | | | | | "
" o' +-----------+ +-----------+ +-----------+ | "
" ' | "
"____'___________________________________________________________'____";
int state[] = {1, 1, 0,
1, 1, 0,
1, 0, 0};
/* Updates the graphics for the window @ coordinates (x, y) to match the
* `state` array.
*
* This function modifies the `house` array by updating the characters
* inside the window located at the zero indexed coordinates (x, y) to
* match the window's state in the `state` array. If the window's
* state is 1, then the window is filled with the '#' character.
* Likewise, if the window's state is 0 in the `state` array, the
* window is filled with the ' ' character.
*
* Parameters:
* house -- pointer to characters representing the house
*
* state -- pointer to the game state array
*
* x -- the horizontal coordinate of the window for which the
* state will be updated (zero indexed, with 0 being
* the left column and 2 being the right column)
*
* y -- the vertical coordinate of the window for which the
* state will be updated (zero indexed, with 0 being
* the top row and 2 being the bottom row)
*/
void window_update_graphics(char *house, const int *state, int x, int y)
I have been working on this for a few days now and cannot get it to fill all correct windows. The function below calls the function above, window_update_graphics, and this is the function that fills the windows corresponding to the 1's in the state array.
void house_init(char *house, const int *state)
{
int x, y;
for (y = 0; y < 3; y++)
for (x = 0; x < 3; x++)
window_update_graphics(house, state, x, y);
}
This is where I am at:
int idx;
int i;
int j;
idx = HOUSE_WIDTH * 8 + 11;
x = idx % HOUSE_WIDTH;
y = idx / HOUSE_WIDTH;
int windowStartIndex = HOUSE_WIDTH * y + x;
// Fill the window with "#" if the corresponding state is 1, otherwise leave it unchanged
for (i = 0; i < WINDOW_HEIGHT; i++)
{
for (j = 0; j < WINDOW_WIDTH; j++)
{
int currentIdx = windowStartIndex + i * HOUSE_WIDTH + j;
if (state[(3 * i) + j] == 1)
{
house[currentIdx] = '#';
}
// You can add an else statement here if you want to handle other cases
}
}
I would add something to the house.
""(empty string) indicates that the next string is s line with lights.NULLindicates the end of the house'@'- indicates position of the lightIt will be universal and nice.
https://godbolt.org/z/E9xbnTKM9
It will also work with non regular window placements. Example (this time second row is
1,0,1):https://godbolt.org/z/TxoWqfenW