#include #include #include #include #include "quiz.h" #include "ui.h" static char line[54],answer[ANSWER_SIZE]; static U8 mode,spelling_attempt; /* Named phases make read-only debugger snapshots useful without altering play. */ U8 phase, current_state; static void present(void) { if(!gime_present()) {gime_close();setHighSpeed(FALSE);printf("Graphics timer stopped.\n");exit(1);} } static U8 choose(const char *allowed) { U8 c;release_keys(); do {c=next_key();if(c>='a' && c<='z')c-='a'-'A';}while(!strchr(allowed,c)); return c; } static void credits(void) { phase=5;frame("CREDITS"); text(8,19,"A MAP FOR EVERY STATE",6); text(8,39,"Map (c) Fla-shop.com",7); text(8,51,"https://www.fla-shop.com/svg/usa/",2); text(8,65,"Creative Commons Attribution 4.0",7); text(8,77,"https://creativecommons.org/licenses/by/4.0/",2); text(8,94,"Adapted: rasterized, reduced, recolored;",7); text(8,105,"state masks and enlarged detail views added.",7); text(8,124,"Font: Pierre Sarrazin, public domain.",2); text(8,138,"C / CMOC; VCC Plus GIME and keyboard APIs.",2); text(8,158,"Full sources and notices: assets/CREDITS.md",7); text(8,180,"SPACE: back",6);present();choose(" "); } static U8 title(void) { U8 c; do { phase=0;frame("50 STATES"); text(8,19,"HOW WELL DO YOU KNOW YOUR CAPITALS?",6); show_map(49); /* Right panel is replaced by the mode selector. */ gime_fill_rect(209,32,111,111,0); text(212,40,"CHOOSE A MODE",6); text(212,58,"1 MULTIPLE",7);text(224,69,"CHOICE",7); text(212,89,"2 TYPE THE",7);text(224,100,"CAPITAL",7); text(212,123,"C CREDITS",2);text(212,136,"Q QUIT",2); text(8,149,"Choice: 1-4. Type: letters, spaces, Enter.",7); text(8,160,"Backspace edits. Near spelling: retry/reveal.",2); text(8,171,"50 questions. Release keys between presses.",2); text(8,182,"Choice: auto next. Typed: SPACE to continue.",6); present();c=choose("12CQ");if(c=='C')credits(); }while(c=='C'); return c; } static void question_screen(void) { phase=1;frame(mode==1?"MULTIPLE CHOICE":"TYPE THE CAPITAL"); sprintf(line,"Question %u of 50 Score %u",(unsigned)question+1,(unsigned)score); text(8,19,line,7); show_map(current_state); gime_fill_rect(0,143,320,49,1); sprintf(line,"%s: what is its capital?",states[current_state].name); text(8,145,line,6); } static U8 multiple_choice(void) { U8 i,c; quiz_options(current_state);question_screen(); for(i=0;i<4;++i) { sprintf(line,"%u %s",(unsigned)i+1,states[options[i]].capital); text(8+(i%2)*156,157+(i/2)*12,line,7); } text(8,183,"Press 1, 2, 3 or 4",2);present();c=choose("1234")-'1'; strcpy(answer,states[options[c]].capital); return options[c]==current_state; } static void input_screen(U8 too_long) { gime_fill_rect(0,155,320,37,1);text(8,158,answer,7); text(8+strlen(answer)*6,158,"_",6); text(8,171,too_long?"39 characters maximum. Backspace to edit.":"Enter submits. Backspace edits. Esc reveals.",2); text(8,183,"Case and extra spaces do not matter.",2);present(); } static void input_edit(U8 old_n,U8 new_n) { U8 p,first=old_n