From 1fea50c293f2d914479cdd781582d3f155eea1fa Mon Sep 17 00:00:00 2001 From: Chi-Feng Tsai Date: Sat, 17 Aug 2024 18:41:55 +0800 Subject: [PATCH 1/2] fix tetris score calculation --- fw/Core/Hitcon/App/TetrisGame.cc | 5 +++-- fw/Core/Hitcon/App/test-tetris.cc | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/fw/Core/Hitcon/App/TetrisGame.cc b/fw/Core/Hitcon/App/TetrisGame.cc index bb4b7ad..2bd9c19 100644 --- a/fw/Core/Hitcon/App/TetrisGame.cc +++ b/fw/Core/Hitcon/App/TetrisGame.cc @@ -12,11 +12,12 @@ void TetrisGame::clear_full_line() { int to = BOARD_HEIGHT - 1; int cleared_lines = 0; for (; from >= 0; from--) { - if (board[from] && board[from] != 0b11111111u) { + if (board[from] == 0b11111111u) { + cleared_lines++; + } else { board[to] = board[from]; if (to != from) { board[from] = 0; - cleared_lines++; } to--; } diff --git a/fw/Core/Hitcon/App/test-tetris.cc b/fw/Core/Hitcon/App/test-tetris.cc index a159564..fdfcc55 100644 --- a/fw/Core/Hitcon/App/test-tetris.cc +++ b/fw/Core/Hitcon/App/test-tetris.cc @@ -16,6 +16,8 @@ std::mutex game_mutex; hitcon::tetris::TetrisGame game([]() { return static_cast(rand()); }); void print_buf_90(display_buf_t* buf_) { + printf("Score: %d\n", game.game_get_score()); + // will rotate 90 degree since tetris is portrait uint8_t buf[DISPLAY_WIDTH * DISPLAY_HEIGHT]; display_buf_unpack(buf, buf_); @@ -63,6 +65,7 @@ void gameFunction() { game.game_fall_down_tetromino(); prev_update = now; if (game.game_get_state() == hitcon::tetris::GAME_STATE_GAME_OVER) { + exit(0); break; } } From ad1b11e54c2bfdc386a15a9a3ee80a643eaf834c Mon Sep 17 00:00:00 2001 From: Chi-Feng Tsai Date: Sat, 17 Aug 2024 18:47:56 +0800 Subject: [PATCH 2/2] fix test-tetris.cc --- fw/Core/Hitcon/App/test-tetris.cc | 80 +++++++++++++++---------------- 1 file changed, 39 insertions(+), 41 deletions(-) diff --git a/fw/Core/Hitcon/App/test-tetris.cc b/fw/Core/Hitcon/App/test-tetris.cc index fdfcc55..1087fb4 100644 --- a/fw/Core/Hitcon/App/test-tetris.cc +++ b/fw/Core/Hitcon/App/test-tetris.cc @@ -92,48 +92,46 @@ void ioFunction() { } } - if (std::fgetc(stdin) != EOF) { - char ch = std::fgetc(stdin); - switch (ch) { - case 'a': { - std::lock_guard lock(game_mutex); - game.game_on_input(hitcon::tetris::DIRECTION_LEFT); - break; - } - - case 'd': { - std::lock_guard lock(game_mutex); - game.game_on_input(hitcon::tetris::DIRECTION_RIGHT); - break; - } - - case 's': { - std::lock_guard lock(game_mutex); - game.game_on_input(hitcon::tetris::DIRECTION_DOWN); - break; - } - - case 'w': { - std::lock_guard lock(game_mutex); - game.game_on_input(hitcon::tetris::DIRECTION_UP); - break; - } - - case 't': { - std::lock_guard lock(game_mutex); - game.game_enemy_attack(2); - break; - } - - case 'f': { - std::lock_guard lock(game_mutex); - game.game_on_input(hitcon::tetris::DIRECTION_FAST_DOWN); - break; - } - - default: - break; + char ch = std::fgetc(stdin); + switch (ch) { + case 'a': { + std::lock_guard lock(game_mutex); + game.game_on_input(hitcon::tetris::DIRECTION_LEFT); + break; + } + + case 'd': { + std::lock_guard lock(game_mutex); + game.game_on_input(hitcon::tetris::DIRECTION_RIGHT); + break; + } + + case 's': { + std::lock_guard lock(game_mutex); + game.game_on_input(hitcon::tetris::DIRECTION_DOWN); + break; + } + + case 'w': { + std::lock_guard lock(game_mutex); + game.game_on_input(hitcon::tetris::DIRECTION_UP); + break; } + + case 't': { + std::lock_guard lock(game_mutex); + game.game_enemy_attack(2); + break; + } + + case 'f': { + std::lock_guard lock(game_mutex); + game.game_on_input(hitcon::tetris::DIRECTION_FAST_DOWN); + break; + } + + default: + break; } } }