int init_quiz() { int i, k=0; char ans[4]; load_board(); while (1) { clear(); move(2,20); setfcolor(WHITE,0); prints("开心词典测试中心("); setfcolor(RED,1); prints("HAPPYQUIZ"); setfcolor(WHITE,0); prints(")测试版0.1"); move(3,40); prints("作者: "); setfcolor(RED,0); prints("*****@*****.**"); move(5,28); setfcolor(WHITE,1); prints("===排行榜(%d--%d)===", k*10+1, k*10+10); move(6,22); setfcolor(RED,1); prints("╭──────────────╮"); for (i=0;i<10;i++) { move(7+i, 22); setfcolor(RED,1); prints("│"); if (i+k*10>=topn) { move(7+i, 34); setfcolor(GREEN,1); prints("--空--"); } else { char p[100]; move(7+i, 24); setfcolor(GREEN,1); sprintf(p, "%3d %-12s %4d", i+1+k*10, topid[i+k*10], topscore[i+k*10]); prints("%s", p); } move(7+i, 52); setfcolor(RED,1); prints("│"); } move(17,22); setfcolor(RED,1); prints("╰──────────────╯"); resetcolor(); getdata(19, 22, "开始游戏(Y-开始,N-退出)", ans, 3, 1, NULL, 1); if (toupper(ans[0])=='Y') return 1; if (toupper(ans[0])=='N') return 0; k++; if (k>=10) k=0; } }
void deb_init(void) { semid = semget(KEY,0,IPC_PRIVATE); if (semid < 0) { umask(0); semid = semget(KEY,1,IPC_CREAT|IPC_EXCL|PERM); if (semid < 0) { fprintf(stderr,"deb: cannot create semaphore\n"); resetcolor(); exit(-1); } semctl(semid,0,SETVAL,1); } deb_fprintf(stderr,"deb: created semaphore %d\n",semid); }
int quiz_again() { int rank; char ans[4]; rank = check_top(score); move(t_lines-3, 0); if (rank==1) { setfcolor(RED, 1); prints("恭喜你,你上排行榜啦!!!"); save_board(); } resetcolor(); getdata(t_lines-2, 0, "重新玩吗?", ans, 3, 1, NULL, 1); return toupper(ans[0])=='Y'; }
void cprint(termcolor col,gint verbosity, GlyrQuery * s, const char * fmt, ...) { if((s && verbosity <= s->verbosity) || verbosity == -1) { if(col != DEFAULT && global_enable_color) printcol(GLYR_OUTPUT,col); va_list param; va_start(param,fmt); g_logv("Glyrc",G_LOG_LEVEL_INFO,fmt,param); va_end(param); if(col != DEFAULT && global_enable_color) resetcolor(GLYR_OUTPUT); } }
void color( int attr, int fg, FILE * out, char *fmt, ... ) { #define COLOR_CONDITION ( ( out == stdout || out == stderr ) && flags.color ) va_list list; if( COLOR_CONDITION ) textcolor ( out, attr, fg, GREEN ); va_start ( list, fmt ); vfprintf ( out, fmt, list ); va_end ( list ); if( COLOR_CONDITION ) resetcolor(out); }
void msg( int v, int attr, int fg, char *fmt, ... ) { va_list list; if( flags.verbosity < v ) return; if( flags.color ) textcolor ( stdout, attr, fg, GREEN ); va_start ( list, fmt ); vfprintf ( stdout, fmt, list ); va_end ( list ); if( flags.color ) resetcolor( stdout ); fprintf( stdout, "\n" ); }
void window(int left, int top, int right, int bottom) { /*Check passed parms*/ if (left < 1 || top < 1 || right > max_cols || bottom > max_rows) { left = top = 1; right = 80; bottom = 24; } cur_x = 1; cur_y = 1; win.win_left = left; win.win_top = top; win.win_right = right; win.win_bottom = bottom; win.win_horizon = right - left + 1; win.win_vertal = bottom - top + 1; cnt_mode = ATTR_DEFAULT; fnt_color = F_BLACK; bak_color = B_WHITE; resetcolor(); resetcntmode(); }
/* * ret: -1: user cancel input */ int getdata(int line, int col, char *prompt, char *buf, int len, int echo, void *nouse, int clearlabel) { int ch, clen = 0, curr = 0, x, y; bool init=true; char tmp[STRLEN],save[STRLEN]; extern int scr_cols; extern int RMSG; if (clearlabel == true) { buf[0] = 0; } if (scrint) move(line, col); if (prompt) prints("%s", prompt); if (scrint) getyx(&y, &x); clen = strlen(buf); if (clen>=len) clen = len - 1; curr = clen; buf[curr] = '\0'; strncpy(save, buf, STRLEN); save[STRLEN-1]=0; if (!scrint) { prints("%s", buf); while ((ch = igetkey()) != '\r') { /* * TODO: add KEY_REFRESH support */ if (ch == '\n') break; if (ch == '\177' || ch == Ctrl('H')) { if (clen == 0) continue; clen--; ochar(Ctrl('H')); ochar(' '); ochar(Ctrl('H')); oflush(); continue; } if (!isprint2(ch)) continue; if (clen >= len - 1) continue; buf[clen++] = ch; if (echo) ochar(ch); else ochar('*'); } buf[clen] = '\0'; prints("\n"); oflush(); return clen; } ingetdata = true; clrtoeol(); while (1) { int i; move(y, x); if (init) prints("\x1b[4m"); for (i=0; i<clen; i++) if (!echo||buf[i]==KEY_ESC||!isprint2(buf[i])) outc('*'); else outc(buf[i]); resetcolor(); clrtoeol(); move(y, x+curr); ch = igetkey(); if (kicked) { ingetdata = false; return 0; } if (true == RMSG && (KEY_UP == ch || KEY_DOWN == ch)) { ingetdata = false; return -ch; /* Leeward 98.07.30 supporting msgX */ } if ((uinfo.mode == KILLER && (!buf[0]) && (ch==KEY_UP||ch==KEY_DOWN||ch==KEY_PGUP||ch==KEY_PGDN))||(ch>=Ctrl('S')&&ch<=Ctrl('W'))) { ingetdata = false; return -ch; } #if 0 //#ifdef NINE_BUILD if (true == RMSG && ch == Ctrl('Z') && clen == 0) break; #endif if (ch == '\n' || ch == '\r') break; #ifdef CHINESE_CHARACTER if (ch == Ctrl('R')) { SET_CHANGEDEFINE(getCurrentUser(), DEF_CHCHAR); init=false; continue; } #endif if (ch == '\177' || ch == Ctrl('H')) { if (init) { init=false; buf[0]=0; curr=0; clen=0; } if (curr == 0) { continue; } strcpy(tmp, &buf[curr]); buf[--curr] = '\0'; #ifdef CHINESE_CHARACTER if (DEFINE(getCurrentUser(), DEF_CHCHAR)) { int i,j=0; for (i=0; i<curr; i++) if (j) j=0; else if (buf[i]<0) j=1; if (j) { buf[--curr] = '\0'; clen--; } } #endif (void) strcat(buf, tmp); clen--; continue; } if (ch == KEY_ESC&&!enableESC) { strncpy(buf, save, Min(len,STRLEN)); buf[Min(len,STRLEN-1)]=0; curr = strlen(buf); clen = curr; init=true; continue; } if (ch == Ctrl('C')) { buf[0]='\0'; outc('\n'); ingetdata = false; return -1; } if (ch == KEY_DEL) { if (init) { init=false; buf[0]=0; curr=0; clen=0; } if (curr >= clen) { curr = clen; continue; } strcpy(tmp, &buf[curr + 1]); #ifdef CHINESE_CHARACTER if (DEFINE(getCurrentUser(), DEF_CHCHAR)) { int i,j=0; for (i=0; i<curr+1; i++) if (j) j=0; else if (buf[i]<0) j=1; if (j) { strcpy(tmp, &buf[curr + 2]); clen--; } } #endif buf[curr] = '\0'; (void) strcat(buf, tmp); clen--; continue; } if (ch == KEY_LEFT) { init=false; if (curr == 0) { continue; } curr--; #ifdef CHINESE_CHARACTER if (DEFINE(getCurrentUser(), DEF_CHCHAR)) { int i,j=0; for (i=0; i<curr; i++) if (j) j=0; else if (buf[i]<0) j=1; if (j) curr--; } #endif move(y, x + curr); continue; } if (ch == Ctrl('E') || ch == KEY_END) { init=false; curr = clen; move(y, x + curr); continue; } if (ch == Ctrl('A') || ch == KEY_HOME) { init=false; curr = 0; move(y, x + curr); continue; } if (ch == KEY_RIGHT) { init=false; if (curr >= clen) { curr = clen; continue; } curr++; #ifdef CHINESE_CHARACTER if (DEFINE(getCurrentUser(), DEF_CHCHAR)) { int i,j=0; for (i=0; i<curr; i++) if (j) j=0; else if (buf[i]<0) j=1; if (j) curr++; } #endif move(y, x + curr); continue; } if (!isprint2(ch)&&(ch!=KEY_ESC||!enableESC)) { init=false; continue; } if (x + clen >= scr_cols || clen >= len - 1) { if (!init) continue; } if (init) { init=false; buf[0]=0; curr=0; clen=0; } if (!buf[curr]) { buf[curr + 1] = '\0'; buf[curr] = ch; } else { int i; for (i = len - 2; i >= curr; i--) buf[i + 1] = buf[i]; buf[curr] = ch; } curr++; clen++; } buf[clen] = '\0'; outc('\n'); ingetdata = false; return clen; }
int multi_getdata(int line, int col, int maxcol, char *prompt, char *buf, int len, int maxline, int clearlabel, int textmode) { int ch, x, y, startx, starty, now, i, j, k, i0, chk, cursorx, cursory; char savebuffer[25][LINELEN*3]; bool init=true; char tmp[1024]; extern int RMSG; /*************stiger************ * textmode 0 : ctrl+q换行,enter发表 * textmode 1 : enter换行,ctrl+w发送 *********************************/ if (uinfo.mode!=MSGING && uinfo.mode != POSTTMPL) ingetdata = true; if (clearlabel == true) { buf[0] = 0; } move(line, col); if (prompt) prints("%s", prompt); getyx(&starty, &startx); now = strlen(buf); for (i=0; i<=24; i++) saveline(i, 0, savebuffer[i]); strncpy(tmp, buf, 1024); tmp[1023]=0; cursory = starty; cursorx = startx; while (1) { y = starty; x = startx; move(y, x); chk = 0; if (now==0) { cursory = y; cursorx = x; } for (i=0; i<strlen(buf); i++) { if (chk) chk=0; else if (buf[i]<0) chk=1; if (chk&&x>=maxcol) x++; if (buf[i]!=13&&buf[i]!=10) { if (x>maxcol) { clrtoeol(); x = 0; y++; if (y>=scr_lns) { scroll(); starty--; cursory--; y--; } move(y, x); } if (init) prints("\x1b[4m"); prints("%c", buf[i]); resetcolor(); x++; } else { clrtoeol(); x = 0; y++; if (y>=scr_lns) { scroll(); starty--; cursory--; y--; } move(y, x); } if (i==now-1) { cursory = y; cursorx = x; } } clrtoeol(); move(cursory, cursorx); ch = igetkey(); if (textmode == 0) { if ((ch == '\n' || ch == '\r')) break; } else { if (ch == Ctrl('W')) break; } for (i=starty; i<=y; i++) saveline(i, 1, savebuffer[i]); if (true == RMSG && (KEY_UP == ch || KEY_DOWN == ch) && (!buf[0])) { ingetdata = false; return -ch; } if (true == UPDOWN && (KEY_UP == ch || KEY_DOWN == ch)) { ingetdata = false; return -ch; } #if 0 //#ifdef NINE_BUILD if (RMSG && (ch == Ctrl('Z')) && (!buf[0])) { ingetdata = false; return -ch; } #endif #ifdef CHINESE_CHARACTER if (ch == Ctrl('R')) { init=false; SET_CHANGEDEFINE(getCurrentUser(), DEF_CHCHAR); continue; } #endif switch (ch) { case KEY_ESC: init=true; strncpy(buf, tmp, Min(len,STRLEN)); buf[Min(len,1024-1)]=0; now=strlen(buf); break; case Ctrl('W'): case Ctrl('Q'): case '\n': case '\r': if (init) { init=false; buf[0]=0; now=0; } if (UPDOWN) break; if (y-starty+1<maxline) { for (i=strlen(buf)+1; i>now; i--) buf[i]=buf[i-1]; buf[now++]='\n'; } break; case KEY_UP: init=false; if (cursory>starty) { y = starty; x = startx; chk = 0; if (y==cursory-1&&x<=cursorx) now=0; for (i=0; i<strlen(buf); i++) { if (chk) chk=0; else if (buf[i]<0) chk=1; if (chk&&x>=maxcol) x++; if (buf[i]!=13&&buf[i]!=10) { if (x>maxcol) { x = col; y++; } x++; } else { x = col; y++; } #ifdef CHINESE_CHARACTER if (!DEFINE(getCurrentUser(), DEF_CHCHAR)||!chk) #endif if (y==cursory-1&&x<=cursorx) now=i+1; } } break; case KEY_DOWN: init=false; if (cursory<y) { y = starty; x = startx; chk = 0; if (y==cursory+1&&x<=cursorx) now=0; for (i=0; i<strlen(buf); i++) { if (chk) chk=0; else if (buf[i]<0) chk=1; if (chk&&x>=maxcol) x++; if (buf[i]!=13&&buf[i]!=10) { if (x>maxcol) { x = col; y++; } x++; } else { x = col; y++; } #ifdef CHINESE_CHARACTER if (!DEFINE(getCurrentUser(), DEF_CHCHAR)||!chk) #endif if (y==cursory+1&&x<=cursorx) now=i+1; } } break; case '\177': case Ctrl('H'): if (init) { init=false; buf[0]=0; now=0; } if (now>0) { for (i=now-1; i<strlen(buf); i++) buf[i]=buf[i+1]; now--; #ifdef CHINESE_CHARACTER if (DEFINE(getCurrentUser(), DEF_CHCHAR)) { chk = 0; for (i=0; i<now; i++) { if (chk) chk=0; else if (buf[i]<0) chk=1; } if (chk) { for (i=now-1; i<strlen(buf); i++) buf[i]=buf[i+1]; now--; } } #endif } break; case KEY_DEL: if (init) { init=false; buf[0]=0; now=0; } if (now<strlen(buf)) { #ifdef CHINESE_CHARACTER if (DEFINE(getCurrentUser(), DEF_CHCHAR)) { chk = 0; for (i=0; i<now+1; i++) { if (chk) chk=0; else if (buf[i]<0) chk=1; } if (chk) for (i=now; i<strlen(buf); i++) buf[i]=buf[i+1]; } #endif for (i=now; i<strlen(buf); i++) buf[i]=buf[i+1]; } break; case KEY_LEFT: init=false; if (now>0) { now--; #ifdef CHINESE_CHARACTER if (DEFINE(getCurrentUser(), DEF_CHCHAR)) { chk = 0; for (i=0; i<now; i++) { if (chk) chk=0; else if (buf[i]<0) chk=1; } if (chk) now--; } #endif } break; case KEY_RIGHT: init=false; if (now<strlen(buf)) { now++; #ifdef CHINESE_CHARACTER if (DEFINE(getCurrentUser(), DEF_CHCHAR)) { chk = 0; for (i=0; i<now; i++) { if (chk) chk=0; else if (buf[i]<0) chk=1; } if (chk) now++; } #endif } break; case KEY_HOME: case Ctrl('A'): init=false; now--; while (now>=0&&buf[now]!='\n'&&buf[now]!='\r') now--; now++; break; case KEY_END: case Ctrl('E'): init=false; while (now<strlen(buf)&&buf[now]!='\n'&&buf[now]!='\r') now++; break; case KEY_PGUP: init=false; now=0; break; case KEY_PGDN: init=false; now = strlen(buf); break; case Ctrl('Y'): if (init) { init=false; buf[0]=0; now=0; } i0 = strlen(buf); i=now-1; while (i>=0&&buf[i]!='\n'&&buf[i]!='\r') i--; i++; if (!buf[i]) break; j=now; while (j<i0-1&&buf[j]!='\n'&&buf[j]!='\r') j++; if (j>=i0-1) j=i0-1; j=j-i+1; if (j<0) j=0; for (k=0; k<i0-i-j+1; k++) buf[i+k]=buf[i+j+k]; y = starty; x = startx; chk = 0; if (y==cursory&&x<=cursorx) now=0; for (i=0; i<strlen(buf); i++) { if (chk) chk=0; else if (buf[i]<0) chk=1; if (chk&&x>=maxcol) x++; if (buf[i]!=13&&buf[i]!=10) { if (x>maxcol) { x = col; y++; } x++; } else { x = col; y++; } #ifdef CHINESE_CHARACTER if (!DEFINE(getCurrentUser(), DEF_CHCHAR)||!chk) #endif if (y==cursory&&x<=cursorx) now=i+1; } if (now>strlen(buf)) now=strlen(buf); break; default: if (isprint2(ch)&&strlen(buf)<len-1) { if (init) { init=false; buf[0]=0; now=0; } for (i=strlen(buf)+1; i>now; i--) buf[i]=buf[i-1]; buf[now++]=ch; y = starty; x = startx; chk = 0; for (i=0; i<strlen(buf); i++) { if (chk) chk=0; else if (buf[i]<0) chk=1; if (chk&&x>=maxcol) x++; if (buf[i]!=13&&buf[i]!=10) { if (x>maxcol) { x = col; y++; } x++; } else { x = col; y++; } } if (y-starty+1>maxline) { for (i=now-1; i<strlen(buf); i++) buf[i]=buf[i+1]; now--; } } init=false; break; } } ingetdata = false; return y-starty+1; }
int quiz_test() { int i=0,j,k,stat_fast=0; time_t t1,t2,t3; char sql[100]; score = 0; t1 = time(0); while (1) { int level, style, anscount, order[100], order2[100], tout=0; char question[200], ans[6][200], answer[100], now[100], input[6]; t2 = time(0); set_alarm(30, 0, ktimeout, NULL); do { j=rand()%10000+1; sprintf(sql, "SELECT * FROM quiz WHERE id=%d", j); mysql_real_query(&s, sql, strlen(sql)); res = mysql_store_result(&s); row = mysql_fetch_row(res); } while (row==NULL); level = atoi(row[1]); style = atoi(row[2]); strcpy(question, row[3]); anscount = atoi(row[4]); for (j=0;j<anscount;j++) order2[j]=0; for (j=0;j<anscount;j++) { do { k=rand()%anscount; } while (order2[k]==1); order2[k]=1; order[j]=k; } for (j=0;j<anscount;j++) { strcpy(ans[j], row[5+order[j]]); } answer[6]=0; for (j=0;j<6;j++) answer[j]='0'; for (j=0;j<anscount;j++) answer[j]=row[11][order[j]]; mysql_free_result(res); clear(); move(0,0); setfcolor(YELLOW, 1); setbcolor(BLUE); prints(" 开心词典测试(\x1b[31mHAPPYQUIZ\x1b[33m) 测试人:%s 目前得分:\x1b[31m%d\x1b[33m 题号:%d 分值:%d 类型:%s", getCurrentUser()->userid, score, i+1, level, (style==1)?"单选":"多选"); clrtoeol(); for (j=0;j<6;j++) now[j]='0'; now[6]=0; while (1) { char bb[100]; resetcolor(); move(2,0); if (strlen(question)<70) prints("%s", question); else { char q2[100]; strcpy(q2,question+70); question[70]=0; prints("%s\n%s", question, q2); } for (j=0;j<anscount;j++) { move(4+j,0); clrtoeol(); prints("%c. %s %s", 'A'+j, ans[j], (now[j]=='1')?"*":""); } sprintf(bb, "请选择:(A-%c,回车结束)", anscount+'A'-1); getdata(anscount+6, 0, bb, input, 3, 1, NULL, 1); if (kicked) break; input[0] = toupper(input[0]); if (input[0]>='A'&&input[0]<anscount+'A') { if (now[input[0]-'A']=='1') now[input[0]-'A']='0'; else now[input[0]-'A']='1'; if (style==1) break; } else if (input[0]==0&&style==2) break; else { getdata(anscount+7, 0, "退出测试:(Y/N)", input, 3, 1, NULL, 1); if (toupper(input[0])=='Y') { set_alarm(0, 0, NULL, NULL); kicked = 0; return 0; } } } if (kicked) tout=1; set_alarm(0, 0, NULL, NULL); kicked = 0; t3 = time(0); if (t3-t2<=10) stat_fast++; else stat_fast=0; if (strcmp(now, answer)||stat_fast>=10||t3-t1>=7200) { move(anscount+8, 0); setfcolor(RED, 1); if (tout) prints("你超时了\n"); else prints("你答错啦\n"); setfcolor(BLUE, 1); prints(" ,\n"); prints(" (╰╮╮\n"); prints("∞╭⌒ヽ ..\n"); prints("╰( (_Q\n"); prints(" ∨~∨∨\n"); break; } else { move(anscount+8, 0); setfcolor(RED, 1); prints("正确!"); refresh(); sleep(1); i++; score+=level; } } set_alarm(0, 0, NULL, NULL); return 0; }