Skip to content

Commit

Permalink
Merge branch 'main' into alx-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Alx-Lai authored Aug 17, 2024
2 parents 7ac9262 + 91d10a4 commit 480aa57
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
25 changes: 22 additions & 3 deletions fw/Core/Hitcon/App/SnakeApp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ void SnakeApp::OnButton(button_t button) {
break;
case BUTTON_BACK:
case BUTTON_LONG_BACK:
// local leave
if (mode == MODE_MULTIPLAYER) {
uint8_t code = PACKET_GAME_LEAVE;
g_xboard_logic.QueueDataForTx(&code, 1, SNAKE_RECV_ID);
}
// leave action 2
badge_controller.BackToMenu(this);
break;
default:
Expand All @@ -118,8 +124,13 @@ void SnakeApp::OnXBoardRecv(void* arg) {
PacketCallbackArg* packet = reinterpret_cast<PacketCallbackArg*>(arg);
switch (packet->data[0]) {
case PACKET_GAME_OVER:
// remote game over
_game_over = true;
display_set_mode_scroll_text("Game Over");
// game over screen
show_score_app.SetScore(_score);
g_game_score.MarkScore(GameScoreType::GAME_SNAKE, _score);
badge_controller.change_app(&show_score_app);

break;
case PACKET_GET_FOOD:
_len++;
Expand All @@ -130,6 +141,12 @@ void SnakeApp::OnXBoardRecv(void* arg) {
InitGame();
}
break;
case PACKET_GAME_LEAVE:
// remote leave
_game_over = true;
// leave action
badge_controller.change_app(&main_menu);
break;
}
}

Expand Down Expand Up @@ -188,12 +205,14 @@ void SnakeApp::Routine(void* unused) {
if (OnSnake(new_head)) _game_over = true;

if (_game_over) {
show_score_app.SetScore(_score);
g_game_score.MarkScore(GameScoreType::GAME_SNAKE, _score);
// local game over
if (mode == MODE_MULTIPLAYER) {
uint8_t code = PACKET_GAME_OVER;
g_xboard_logic.QueueDataForTx(&code, 1, SNAKE_RECV_ID);
}
// game over screen
show_score_app.SetScore(_score);
g_game_score.MarkScore(GameScoreType::GAME_SNAKE, _score);
badge_controller.change_app(&show_score_app);
return;
}
Expand Down
1 change: 1 addition & 0 deletions fw/Core/Hitcon/App/SnakeApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ enum { // XBOARD
PACKET_GET_FOOD = 1,
PACKET_GAME_START,
PACKET_GAME_OVER,
PACKET_GAME_LEAVE,
};

enum {
Expand Down

0 comments on commit 480aa57

Please sign in to comment.