Skip to content

Commit

Permalink
Merge pull request #2 from 0xjmux/gameover_bugfix
Browse files Browse the repository at this point in the history
Gameover bugfix
  • Loading branch information
0xjmux committed Mar 21, 2024
2 parents d4d3991 + 0c33305 commit b0c2bc8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,8 @@ This project has several goals.


This game is my first attempt at writing a component of medium complexity, and one of my primary goals is bettering my understanding of development best practices to accelerate my work on future projects.


#### Some of what I've learned
mostly for myself to not forget
* CI build options in CMake, so that CI can build a different version depending on paths and such
9 changes: 0 additions & 9 deletions src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,6 @@ bool restore_game_state(TetrisGame *tg, const char* filename, FILE *gamelog) {
}
fprintf(gamelog, "Config loaded from %s!\n", filename);

/*
fprintf(gamelog, "active_piece: ptype = %d, loc_row = %d, loc_col = %d, orientation = %d, falling = %d\n", \
tg->active_piece.ptype, tg->active_piece.loc.row, tg->active_piece.loc.col, \
tg->active_piece.orientation, tg->active_piece.falling);
print_board_state(tg->active_board, gamelog);
*/

return true;

}
Expand Down Expand Up @@ -152,7 +144,6 @@ void reconstruct_board_from_str_row(TetrisBoard *tb, const char *name, const cha
}
}


}


Expand Down
2 changes: 2 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ IF(TETRIS_UNIT_TEST_MACRO)
target_compile_definitions(test_tetris PUBLIC TETRIS_UNIT_TEST_DEF=1)
ENDIF(TETRIS_UNIT_TEST_MACRO)

# CI builds run from {PROJ_ROOT}/build, whereas I usually run the binary from
# ${PROJ_ROOT} itself
OPTION(TETRIS_UNIT_TEST_CI "CI-specific path options" OFF) # disabled by default
IF(TETRIS_UNIT_TEST_CI)
target_compile_definitions(test_tetris PUBLIC TETRIS_UNIT_TEST_CI=1)
Expand Down
12 changes: 10 additions & 2 deletions tetris/tetris.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ void tg_update_score(TetrisGame *tg, uint8_t lines_cleared) {
tg->score += tg->level * points_per_level_cleared[lines_cleared];

// update current highest cell
tg->board.highest_occupied_cell -= lines_cleared;
// tg->board.highest_occupied_cell -= lines_cleared;

// every 10 lines, the level increases
static uint8_t lines_cleared_since_last_level;
Expand Down Expand Up @@ -512,7 +512,9 @@ uint8_t check_and_clear_rows(TetrisGame *tg, tetris_location *tp_cells) {
row_with_offset = (uint8_t) tp_cells[i].row;

assert(row_with_offset < TETRIS_ROWS && row_with_offset > -1 && "global row out of bounds");
#ifdef DEBUG_T
fprintf(gamelog, "check_and_clear: checking row %d\n", row_with_offset);
#endif

// if row is full, add it to list of rows to clear
if(check_filled_row(tg, row_with_offset)) {
Expand All @@ -529,8 +531,14 @@ uint8_t check_and_clear_rows(TetrisGame *tg, tetris_location *tp_cells) {
// update highest occupied cell based on this piece
assert(piece_max_row > -1 && piece_max_row < TETRIS_ROWS && "new tallest cell out of bounds");

if (piece_max_row < tg->board.highest_occupied_cell)
// if this piece contains the new tallest cell on the board, update highest_occupied_cell accordingly
if (piece_max_row < tg->board.highest_occupied_cell) {
tg->board.highest_occupied_cell = piece_max_row;
#ifdef DEBUG_T
fprintf(gamelog, "piece max is new highest row; row=%d\n", piece_max_row);
#endif

}

// if we have rows to clear:
if (rows_idx > 0) {
Expand Down

0 comments on commit b0c2bc8

Please sign in to comment.