Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gameover bugfix #2

Merged
merged 2 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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