X-Git-Url: https://git.rohieb.name/hackover2013-badge-firmware.git/blobdiff_plain/c63dbfcb347e10f9406053545eaf44dd4d9d9bdb..5337261a68ea89b88624ca6fd7319cadd662e057:/mock/badge_main_loop.c?ds=sidebyside diff --git a/mock/badge_main_loop.c b/mock/badge_main_loop.c index 3a1c3d2..f2a366e 100644 --- a/mock/badge_main_loop.c +++ b/mock/badge_main_loop.c @@ -11,37 +11,35 @@ #include #include +#define MAX_LEVELS 1024 + +#define PATH_PREFIX "../badge/jumpnrun/levels/" + void badge_main_loop(void) { - char const *const menu[] = { - "smb", - "skynet", - "wrongturn", - "lubiXOXO", - "lubilove", - "gnobbel", - "foo", - "mean", - "xyzzy", - "abc", - "nonsense" - }; - - size_t choice = badge_menu(menu, ARRAY_SIZE(menu), 0, 0); - - printf("%zu\n", choice); + char menu_buf[MAX_LEVELS][32]; + FILE *fd = fopen("levels.txt", "r"); + + int i; + + for(i = 0; i < MAX_LEVELS && fgets(menu_buf[i], sizeof(menu_buf[i]), fd); ++i) { + menu_buf[i][strlen(menu_buf[i]) - 1] = '\0'; + } + + fclose(fd); + + char const *menu[i]; + for(int j = 0; j < i; ++j) { + menu[j] = menu_buf[j]; + } + + size_t choice = 0; + size_t first_visible = 0; for(;;) { - FILE *fd = fopen("../badge/jumpnrun/levels.txt", "r"); - char buf[12]; - - while(fgets(buf, sizeof(buf), fd)) { - buf[strlen(buf) - 1] = '\0'; - char lvname[256]; - sprintf(lvname, "../badge/jumpnrun/%s.lvl", buf); - while(jumpnrun_play(lvname) != JUMPNRUN_WON) - ; - } - - fclose(fd); + choice = badge_menu(menu, ARRAY_SIZE(menu), &first_visible, choice); + char lvname[256]; + sprintf(lvname, PATH_PREFIX "%s.lvl", menu[choice]); + + jumpnrun_play_level(lvname); } }