/* The Menu Authored by abakh To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty. You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see . */ #include #include #include #include #include #include #include #include #include #include #include "config.h" #include "common.h" #define LEN 24 #define HLEN LEN/2 #define WID 100 #define HWID WID/2 #ifndef NB #define NB #endif #ifdef Plan9 int usleep(long usec) { int second = usec/1000000; long nano = usec*1000 - second*1000000; struct timespec sleepy = {0}; sleepy.tv_sec = second; sleepy.tv_nsec = nano; nanosleep(&sleepy, (struct timespec *) NULL); return 0; } #endif // 12 lines of water // 80 columns chtype colors[4]={A_NORMAL,A_STANDOUT}; char main_menu[]={ "See High Scores\n" NB"jewels\n" NB"sudoku\n" NB"mines\n" NB"reversi\n" NB"checkers\n" NB"battleship\n" NB"rabbithole\n" NB"sos\n" NB"pipes\n" NB"fifteen\n" NB"memoblocks\n" NB"fisher\n" NB"muncher\n" NB"miketron\n" NB"redsquare\n" NB"darrt\n" NB"snakeduel\n" NB"tugow\n" NB"revenge\n" NB"sjump\n" NB"trsr\n" }; char ascii_art[]={ " ###### ###### " " #################################### " " ###################################### " " ########################################" " ########################################" " ###################################### " " ###################################### " " ######## #### #### ######## " " ######### #########" " ######## ########" " ###### ######" }; char scores_menu[]={ "pipes_scores\n" "jewels_scores\n" "miketron_scores\n" "muncher_scores\n" "fisher_scores\n" "darrt_scores\n" "tugow_scores\n" "revenge_scores\n" "sjump_scores\n" }; char choice_str[100]={0}; char name[100]={0}; void fancy_background(){ int y,x; int lines=LINES,cols=COLS; #define ABS(x) (((x)<0)?-(x):(x)) for(y=0;y first_entry+(lines-3)){ first_entry=chosen-(lines-3); } if(chosen=1){ name[index-1]='\0'; --index; } } if(('a'<=input && input<='z') || ('0'<=input && input<='9')){ if(index<25){ name[index]=input; index++; } } } setenv("NB_PLAYER",name,1); } void scores(){ int choice; char address[1000]={0}; FILE* score_file; while(1){ switch(choice=menu(scores_menu,"High Scores")){ case -1: erase(); return; break; default: get_entry(scores_menu,choice,choice_str); snprintf(address,999,"%s/%s",SCORES_DIR,choice_str); if((score_file=fopen(address,"r"))){ show_scores(score_file); } snprintf(address,999,"%s/.%s",getenv("HOME"),choice_str); if((score_file=fopen(address,"r"))){ show_scores(score_file); } break; } } } int main(int argc,char** argv){ printf("\x1b]2;%s\x07","NBSDGAMES!");//change the title printf("\x1b]0;%s\x07","NBSDGAMES!"); if(argc>1){ printf("This game doesn't take arguments"); } char path[1000]; snprintf(path,999,"%s:.",path);//include current dir at the end signal(SIGINT,sigint_handler); initscr(); noecho(); cbreak(); keypad(stdscr,1); srand(time(NULL)%UINT_MAX); if(has_colors()){ start_color(); init_pair(1,COLOR_RED,COLOR_BLACK); init_pair(2,COLOR_MAGENTA,COLOR_BLACK); init_pair(3,COLOR_YELLOW,COLOR_BLACK); init_pair(4,COLOR_GREEN,COLOR_BLACK); for(int b=0;b<4;++b){ colors[b]=COLOR_PAIR(b+1); } } int n; Start: curs_set(0); enter_name(); int choice; while(1){ switch(choice=menu(main_menu,"Main Menu")){ case -1: sigint_handler(EXIT_SUCCESS); break; case 0: scores(); break; default: def_prog_mode(); endwin(); get_entry(main_menu,choice,choice_str); system(choice_str); reset_prog_mode(); break; } } curs_set(1); //show_scores(save_score()); endwin(); return 0; }