JQbeCoding / ECU

1 stars 0 forks source link

Move Canvas Function #4

Closed JQbeCoding closed 3 weeks ago

JQbeCoding commented 3 weeks ago

void moveCanvas(char canvas[][MAXCOLS], int rowValue, int colValue) { // TODO: write code for the function char tempCanvas[MAXROWS][MAXCOLS];

// Copy the original canvas to a temporary canvas
copyCanvas(tempCanvas, canvas);
initCanvas(canvas);

// Shift rows
for (int row = 0; row < MAXROWS; ++row) {
    int newRow = row + rowValue;

    // Check if the new row index is within bounds
    if (newRow >= 0 && newRow < MAXROWS) {
        // Shift columns
        for (int col = 0; col < MAXCOLS; ++col) {
            int newCol = col + colValue;

            // Check if the new column index is within bounds
            if (newCol >= 0 && newCol < MAXCOLS) {
                canvas[newRow][newCol] = tempCanvas[row][col];
            }
        }
    }
}

}