How to make input in Puzzle-game 15 in C++? [closed]

  c++, sliding-tile-puzzle, visual-studio-2019

I need to make console puzzle-game 15 in C++.
In procces get code like this :

void move() {
    zero = 0;
    inp = _getch();
    switch (inp) {
    case 'w':
        for (int i = 0; i < SIZE; i++)
        {
            for (int j = 0; j < SIZE; j++)
            {
                if (field[i][j] == 0) {
                    swap(field[i][j], field[i - 1][j]);
                    system("cls");
                    if (field[i][j] > 15 || field[i][j] < 0) {
                        field[i][j] = 0;
                    }
                    break;
                }
            }
        }

    case 's':
        zero = _getch();
        for (size_t i = 0; i < SIZE; i++)
        {
            for (size_t j = 0; j < SIZE; j++)
            {
                if (field[i][j] == 0) {
                    swap(field[i][j], field[i + 1][j]);
                    system("cls");
                    if (field[i][j] > 15 || field[i][j] < 0) {
                        field[i][j] = 0;
                    }
                    break;
                }
            }
        }
    case 'a':
        for (size_t i = 0; i < SIZE; i++)
        {
            for (size_t j = 0; j < SIZE; j++)
            {
                if (field[i][j] == 0) {
                    swap(field[i][j], field[i][j - 1]);
                    system("cls");
                    if (field[i][j] > 15 || field[i][j] < 0) {
                        field[i][j] = 0;
                    }
                    break;
                }
            }
        }
    case 'd':
        for (size_t i = 0; i < SIZE; i++)
        {
            for (size_t j = 0; j < SIZE; j++)
            {
                if (field[i][j] == 0) {
                    swap(field[i][j], field[i][j + 1]);
                    system("cls");
                    if (field[i][j] > 15 || field[i][j] < 0) {
                        field[i][j] = 0;
                    }
                    break;
                }
            }
        }
    }
}

This is only one function, not the whole code. With pushing key on keyboard the action(switch 0 with some other number) works incorrect. I’m using conio.h. If it’s no trouble please check this code for mistakes. Thanks for any help.

Source: Windows Questions C++

LEAVE A COMMENT