Update main.c

This commit is contained in:
begilbert-sys 2024-01-16 23:17:42 -08:00 committed by GitHub
parent 98b0cee3b5
commit 701b30c7b7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

8
main.c
View file

@ -16,7 +16,7 @@ int board[4][4];
int score = 0; int score = 0;
int won = false; bool won = false;
enum Direction { enum Direction {
UP, UP,
@ -227,8 +227,7 @@ enum MoveType move_tile(int row, int column, enum Direction direction, bool dont
} }
int _tile_index(int row, int column) { int _tile_index(int row, int column) {
/* map a tile's coords to a single index number /* map a tile's coords to a single index number */
used for checking which tiles have been merged */
return (row << 2) | column; return (row << 2) | column;
} }
bool move_board(enum Direction direction) { bool move_board(enum Direction direction) {
@ -271,6 +270,7 @@ bool move_board(enum Direction direction) {
return true; return true;
} }
else if (move_type == MERGE) { else if (move_type == MERGE) {
// blocks the tile from being merged a second time
merged[tile_index] = true; merged[tile_index] = true;
// also blocks off the next tile // also blocks off the next tile
int next_row = i + ((direction == UP || direction == DOWN) ? row_increment * -1 : 0); int next_row = i + ((direction == UP || direction == DOWN) ? row_increment * -1 : 0);
@ -365,4 +365,4 @@ int main() {
printf("You Lost! Final Score: %d\n", score); printf("You Lost! Final Score: %d\n", score);
} }
return 1; return 1;
} }