mirror of
https://github.com/begilbert-sys/2048-in-C
synced 2024-12-25 21:58:33 +01:00
Update main.c
This commit is contained in:
parent
98b0cee3b5
commit
701b30c7b7
1 changed files with 4 additions and 4 deletions
8
main.c
8
main.c
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue