/* $Id: RPG.c,v 2.4 2007/08/24 05:43:57 bbs Exp $ */ #include "bbs.h" static int RPG_num; static int RPG_face; static int RPG_stage; static int RPG_temp; static int RPG_cap[200]; static int RPG_sum; static void indigestion(int i) { fprintf(stderr, "嚴重內傷 %d\n", i); } static void RPG_write_header(FILE * fp) { char *ptr; struct { char author[IDLEN + 1]; char board[IDLEN + 1]; char title[66]; time_t date; /* last post's date */ int number; /* post number */ } postlog; fprintf(fp, "%s %s (%s)\n", str_author1, cuser->userid, cuser->username); memset(&postlog, 0, sizeof(postlog)); strlcpy(postlog.author, cuser->userid, sizeof(postlog.author)); strlcpy(postlog.board, currboard, sizeof(postlog.board)); { snprintf(save_title, sizeof(save_title), "[擲骰] %dd%d : %d", RPG_num, RPG_face, RPG_sum ); } ptr = save_title; strncpy(postlog.title, ptr, 65); postlog.date = now; postlog.number = 1; append_record(".post", (fileheader_t *) & postlog, sizeof(postlog)); save_title[72] = '\0'; fprintf(fp, "標題: %s\n時間: %s\n", save_title, ctime(&now)); } static int RPG_write_file(char *fpath, int *islocal) { FILE *fp = NULL; int aborted = 0; int i; int i2; int j; int k; int log; int go_start; char temp[100]; RPG_sum = 0; // roll for (i=0; iuserid); strcpy(fpath, tempnam(fpath, "ve_")); } if ((fp = fopen(fpath, "w")) == NULL) { indigestion(5); abort_bbs(0); } RPG_write_header(fp); fprintf(fp ,"\n所擲的數子: %dd%d\n\n", RPG_num, RPG_face); for (i=0; ifrom); fclose(fp); return aborted; } static void RPG_drawline(int line) { int i, i2, log, k; int go_start; move(line, 0); clrtoeol(); prints(" "); if (line == 0) { prints("\033[33;44m 擲骰器 \033[0m"); } if (line == 2) { prints(" "); for (i=0; i<36; i++) { prints("=="); } prints(" "); } if (line == 5) { if (RPG_stage == 0) { prints(" 擲骰數量: \033[1;32m"); prints("%d", RPG_temp); prints("\033[0m"); } else prints(" 擲骰數量: \033[1;33m%d\033[0m", RPG_num); } if (line == 7) { if (RPG_stage == 1) { prints(" 擲骰面數: \033[1;32m"); prints("%d", RPG_temp); prints("\033[0m"); } if (RPG_stage == 2) prints(" 擲骰面數: \033[1;33m%d\033[0m", RPG_face); } if (line == 9) { if (RPG_stage == 2) prints(" -- 骰子已經擲出, 請按 ENTER 繼續 -- "); } if (line == 23) { prints(" 按 [\033[1;32m0-9\033[0m] 輸入數字 [" "\033[1;32mENTER\033[0m] "); if (RPG_stage == 0) { prints("決定輸入 "); } else prints("儲存並退出 "); prints("[\033[1;32mQ\033[0m] 取消並退出" ); } return; } static void display_RPG() { int i; for (i=0; i<24; i++) RPG_drawline(i); } /* 主程式、鍵盤處理 */ int vedit_RPG(char *fpath, int saveheader, int *islocal) { int ch; int exit_flag = 0; RPG_stage = 0; RPG_temp = 0; clear(); display_RPG(); while (exit_flag == 0) { oflush(); ch = igetkey(); switch (ch) { case '1' : case '2' : case '3' : case '4' : case '5' : case '6' : case '7' : case '8' : case '9' : case '0' : RPG_temp = RPG_temp * 10 + (ch - '0'); if (RPG_temp > 100) RPG_temp = (ch - '0'); if (RPG_stage == 0) RPG_drawline(5); if (RPG_stage == 1) RPG_drawline(7); break; case '\r' : if (RPG_stage == 0) { if ((RPG_temp > 0) && (RPG_temp <= 100)) { RPG_num = RPG_temp; RPG_stage++; RPG_temp = 0; display_RPG(); break; } } else if (RPG_stage == 1) { if ((RPG_temp > 0) && (RPG_temp <= 100)) { RPG_face = RPG_temp; RPG_stage++; RPG_temp = 0; display_RPG(); RPG_write_file(fpath, NULL); return 0; break; } } break; case 'Q': case 'q': exit_flag = 1; return -1; break; } } return -1; }