Skip to content

Commit

Permalink
Add app to show score history
Browse files Browse the repository at this point in the history
  • Loading branch information
john0312 committed Aug 17, 2024
1 parent afe551c commit b9d0747
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
2 changes: 2 additions & 0 deletions fw/Core/Hitcon/App/MainMenuApp.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <App/BadUsbApp.h>
#include <App/DinoApp.h>
#include <App/ScoreHistApp.h>
#include <App/ShowNameApp.h>
#include <App/SnakeApp.h>
#include <App/TetrisApp.h>
Expand All @@ -19,6 +20,7 @@ constexpr menu_entry_t main_menu_entries[] = {
{"Snake", &snake_app, &hitcon::app::snake::SetSingleplayer},
{"Dino", &dino_app, nullptr},
{"Tetris", &tetris_app, &hitcon::app::tetris::SetSingleplayer},
{"Show Scores", &score_hist::g_score_hist, nullptr},
};

constexpr int main_menu_entries_len =
Expand Down
34 changes: 34 additions & 0 deletions fw/Core/Hitcon/App/ScoreHistApp.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <App/ScoreHistApp.h>
#include <Logic/GameScore.h>
#include <Util/uint_to_str.h>

namespace hitcon {
namespace score_hist {

char dino_score_str[15] = "Dino ";
char snake_score_str[15] = "Snake ";
char tetris_score_str[15] = "Tetris ";

ScoreHistApp g_score_hist;

void ScoreHistApp::SetScores() {
int dino_score = g_game_score.GetScore(GameScoreType::GAME_DINO);
int snake_score = g_game_score.GetScore(GameScoreType::GAME_SNAKE);
int tetris_score = g_game_score.GetScore(GameScoreType::GAME_TETRIS);

if (dino_score > 9999999) dino_score = 9999999;
if (snake_score > 9999999) snake_score = 9999999;
if (tetris_score > 9999999) tetris_score = 9999999;

uint_to_chr(&dino_score_str[5], 8, dino_score);
uint_to_chr(&tetris_score_str[7], 8, tetris_score);
uint_to_chr(&snake_score_str[6], 8, snake_score);
}

void ScoreHistApp::OnEntry() {
SetScores();
MenuApp::OnEntry();
}

} // namespace score_hist
} // namespace hitcon
43 changes: 43 additions & 0 deletions fw/Core/Hitcon/App/ScoreHistApp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#ifndef APP_SCORE_HIST_APP
#define APP_SCORE_HIST_APP

#include <Logic/BadgeController.h>

#include "MenuApp.h"

namespace hitcon {
namespace score_hist {

extern char dino_score_str[15];
extern char snake_score_str[15];
extern char tetris_score_str[15];

constexpr menu_entry_t score_hist_app_entries[] = {
{dino_score_str, nullptr, nullptr},
{tetris_score_str, nullptr, nullptr},
{snake_score_str, nullptr, nullptr}};

constexpr size_t score_hist_app_entries_len =
sizeof(score_hist_app_entries) / sizeof(score_hist_app_entries[0]);

class ScoreHistApp : public MenuApp {
public:
ScoreHistApp()
: MenuApp(score_hist_app_entries, score_hist_app_entries_len) {}

void OnEntry() override;

void OnButtonMode() override {}
void OnButtonBack() override { badge_controller.BackToMenu(this); }
void OnButtonLongBack() override { badge_controller.BackToMenu(this); }

private:
void SetScores();
};

extern ScoreHistApp g_score_hist;

} // namespace score_hist
} // namespace hitcon

#endif // APP_SCORE_HIST_APP

0 comments on commit b9d0747

Please sign in to comment.