diff --git a/fw/Core/Hitcon/App/TetrisApp.cc b/fw/Core/Hitcon/App/TetrisApp.cc index 9575d17..0a064df 100644 --- a/fw/Core/Hitcon/App/TetrisApp.cc +++ b/fw/Core/Hitcon/App/TetrisApp.cc @@ -36,10 +36,18 @@ TetrisApp::TetrisApp() hitcon::service::sched::scheduler.Queue(&periodic_task, nullptr); } +static void SendAttackEnemyPacket(int n_lines) { + uint8_t data[2] = {PACKET_ATTACK, (uint8_t)n_lines}; + g_xboard_logic.QueueDataForTx(&data[0], 2, TETRIS_RECV_ID); +} + void TetrisApp::OnEntry() { // start a new game game = hitcon::tetris::TetrisGame(tetris_random); display_set_mode_scroll_text("Ready?"); + if (multiplayer) { + game.game_register_attack_enemy_callback(SendAttackEnemyPacket); + } // start the update task hitcon::service::sched::scheduler.EnablePeriodic(&periodic_task); @@ -47,20 +55,12 @@ void TetrisApp::OnEntry() { TETRIS_RECV_ID); } -static void SendAttackEnemyPacket(int n_lines) { - uint8_t data[2] = {PACKET_ATTACK, (uint8_t)n_lines}; - g_xboard_logic.QueueDataForTx(&data[0], 2, TETRIS_RECV_ID); -} - void SetSingleplayer() { tetris_app.SetPlayerCount(SINGLEPLAYER); } void SetMultiplayer() { tetris_app.SetPlayerCount(MULTIPLAYER); } void TetrisApp::SetPlayerCount(unsigned playerCount) { multiplayer = (playerCount == MULTIPLAYER); - if (multiplayer) { - game.game_register_attack_enemy_callback(SendAttackEnemyPacket); - } } void TetrisApp::OnExit() { @@ -145,7 +145,7 @@ void TetrisApp::OnButton(button_t button) { uint8_t code = PACKET_ABORT_GAME; g_xboard_logic.QueueDataForTx(&code, 1, TETRIS_RECV_ID); } - badge_controller.change_app(&main_menu); + badge_controller.OnAppEnd(this); break; case BUTTON_LONG_BACK: @@ -153,7 +153,7 @@ void TetrisApp::OnButton(button_t button) { uint8_t code = PACKET_ABORT_GAME; g_xboard_logic.QueueDataForTx(&code, 1, TETRIS_RECV_ID); } - badge_controller.change_app(&show_name_app); + badge_controller.OnAppEnd(this); break; default: diff --git a/fw/Core/Hitcon/App/TetrisGame.cc b/fw/Core/Hitcon/App/TetrisGame.cc index 2bd9c19..4436e0c 100644 --- a/fw/Core/Hitcon/App/TetrisGame.cc +++ b/fw/Core/Hitcon/App/TetrisGame.cc @@ -27,7 +27,7 @@ void TetrisGame::clear_full_line() { } score += cleared_lines * CLEAR_LINE_SCORE; - if (attack_enemy_callback) { + if (attack_enemy_callback && cleared_lines > 0) { attack_enemy_callback(cleared_lines); } }