diff --git a/README.md b/README.md index 47685ba..7cef32a 100644 --- a/README.md +++ b/README.md @@ -34,4 +34,4 @@ To run, run: # Usage -You can pass `--help` as an command line argument to print help message. You can force incomplete TUI mode that exist for a demonstration of portability and independence of SDL. This TUI mode is incomplete only because it's missing few UI elements and not because it is not feasible. You can also force other sizes of the game area. \ No newline at end of file +You can pass `--help` as an command line argument to print help message. You can force incomplete TUI mode that exists for a demonstration of portability and independence of SDL. This TUI mode is incomplete only because it's missing few UI elements and not because it is not feasible. You can also force other sizes of the game area. \ No newline at end of file diff --git a/src/2048.c b/src/2048.c index 66686a9..30a82d2 100644 --- a/src/2048.c +++ b/src/2048.c @@ -6,8 +6,8 @@ void game_add_block(Game *game) { bool is_full = true; - for (int i = 0; i < game->field_size_y; i++) { - for (int j = 0; j < game->field_size_x; j++) { + for (int i = 0; i < game->field_size_x; i++) { + for (int j = 0; j < game->field_size_y; j++) { if (game->field[j][i] == 0) { is_full = false; break; @@ -25,8 +25,8 @@ void game_add_block(Game *game) { x = rand() % game->field_size_x; y = rand() % game->field_size_y; value = (rand() % 2) + 1; - } while (game->field[x][y] != 0); - game->field[x][y] = value * 2; + } while (game->field[y][x] != 0); + game->field[y][x] = value * 2; } Game game_init(size_t field_size_x, size_t field_size_y) { @@ -37,8 +37,8 @@ Game game_init(size_t field_size_x, size_t field_size_y) { game.field_size_y = field_size_y; game.score = 0; game.field = malloc(sizeof(uint16_t *) * field_size_y); - for (size_t i = 0; i < field_size_y; i++) { - game.field[i] = calloc(field_size_x, sizeof(uint16_t) * field_size_x); + for (size_t i = 0; i < field_size_x; i++) { + game.field[i] = calloc(field_size_y, sizeof(uint16_t) * field_size_y); } time_t t; @@ -62,10 +62,10 @@ void game_move(Game *game, Direction direction) { } // I have few chained for loops that do a lot of similar stuff so I call them in a for loop for better clarity and readability for (int u = 0; u < 3; u++) { - for (int i = 0; i < game->field_size_y; i++) { + for (int i = 0; i < game->field_size_x; i++) { uint16_t **field = game->field; // move everything on one side - for (int j = 0; j < game->field_size_x - 1; j++) { + for (int j = 0; j < game->field_size_y - 1; j++) { // a, b is the same as i and j. It is just flipped when // it does not go horizontally so I can access stuff vertically int a = i; diff --git a/src/gui.c b/src/gui.c index e340da7..18fadbd 100644 --- a/src/gui.c +++ b/src/gui.c @@ -144,10 +144,10 @@ void gui_loop(Game *game) { if (needs_redraw) { SDL_RenderClear(window_renderer); SDL_Rect tile_rect = tile_size; - for (int i = 0; i < game->field_size_y; i++) { - tile_rect.x = i * (700 / game->field_size_y) + 50; - for (int j = 0; j < game->field_size_x; j++) { - tile_rect.y = j * (700 / game->field_size_x) + 150; + for (int i = 0; i < game->field_size_x; i++) { + tile_rect.x = i * (700 / game->field_size_x) + 50; + for (int j = 0; j < game->field_size_y; j++) { + tile_rect.y = j * (700 / game->field_size_y) + 150; // get texture index from value for (int k = 0; k < 13; k++) {