0

I am coding a 15-puzzle game for my school assignment. I take three movement parameters. These are x, y coordinates and directon.

But my code does not replace elements an print first table again and again. What is wrong?

This part is function call for movement:

if ((x<Cols && x>=0)&&(y<Rows && y>=0))
{
    switch (move)
    {
    case 0:
        leftOp((int *)arr, Rows, Cols, &Row, &Col, x, y);
        break;
    default:
        printf("error!!1\n");
        break;
    }
}

and this part is movement function:

    void leftOp(int* arr, int Rows, int Cols, int* MomRow, int* MomCol, int x, int y){
    int temp;
    if (y == *MomRow)
    {
        while (x != *MomCol && *MomCol > x)
        {
            temp = arr[*MomRow * Cols + *MomCol];
            arr[*MomRow * Cols + *MomCol] = arr[*MomRow * Cols + *MomCol - 1];
            arr[*MomRow * Cols + *MomCol - 1] = temp;
        }
    }
}
4

0 回答 0