Skip to content

Commit

Permalink
add score for snake app
Browse files Browse the repository at this point in the history
  • Loading branch information
Lance798 committed Aug 17, 2024
1 parent a8bc9d9 commit 04fa7da
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 3 additions & 2 deletions fw/Core/Hitcon/App/SnakeApp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ void SnakeApp::InitGame() {
_len = 2;
_body[0] = 36;
_body[1] = 35;
_score = 0;
GenerateFood();
}

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

if (_game_over) {
// TODO: score
show_score_app.SetScore(0);
show_score_app.SetScore(_score);
if (mode == MODE_MULTIPLAYER) {
uint8_t code = PACKET_GAME_OVER;
g_xboard_logic.QueueDataForTx(&code, 1, SNAKE_RECV_ID);
Expand All @@ -206,6 +206,7 @@ void SnakeApp::Routine(void* unused) {
uint8_t code = PACKET_GET_FOOD;
g_xboard_logic.QueueDataForTx(&code, 1, SNAKE_RECV_ID);
}
_score++;
}

// shift snake body
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 @@ -55,6 +55,7 @@ class SnakeApp : public App {
direction_t _last_direction;
int8_t _food_index;
bool _game_over;
uint32_t _score;

void GenerateFood();
void Routine(void* unused);
Expand Down

0 comments on commit 04fa7da

Please sign in to comment.