diff options
Diffstat (limited to 'mbbsd/card.c')
-rw-r--r-- | mbbsd/card.c | 208 |
1 files changed, 135 insertions, 73 deletions
diff --git a/mbbsd/card.c b/mbbsd/card.c index b2c3300b..b2de67ec 100644 --- a/mbbsd/card.c +++ b/mbbsd/card.c @@ -1,9 +1,72 @@ /* $Id$ */ #include "bbs.h" +////////////////////////////////////////////////////// +// +// we don't use real user money anymore, because there +// are too many bots... +// +// if you want to associate card games with real money, +// override the functions below. +// +////////////////////////////////////////////////////// + +static int card_money = 0; + +int card_reset_money() +{ + card_money = 100; // initialize + // alert user for the new money change + clear(); + move(t_lines/2-2, 0); + prints( " 請注意: 本遊樂場目前已改為使用與 BBS 系統金錢無關的籌碼,\n\n" + " 每場遊戲開始您都會重新獲得 %u 枚籌碼,並在結算後重置。\n" + , card_money); + vmsg(NULL); + return card_money; +} + +int card_get_money() +{ + return card_money; +} + +int card_add_money(int delta) +{ + if (card_money + delta < 0) + return (card_money = 0); + card_money += delta; + return card_money; +} + +void card_end_game() +{ + clear(); + vs_hdr("遊樂場"); + if (card_get_money()) + { + prints("\n遊戲結束,您目前手上的籌碼共有 " + ANSI_COLOR(1;33) "%u" ANSI_RESET " 枚。\n" + "感謝您的光臨!\n", + card_get_money()); + } else { + prints("\n抱歉,您已經輸光了。\n"); + } + vmsg(NULL); +} + +void card_anti_bot_sleep() +{ + // sleep 1 second + sleep(1); +} + +////////////////////////////////////////////////////// + enum CardSuit { Spade, Heart, Diamond, Club }; + static int card_remain(int cards[]) { @@ -359,10 +422,12 @@ card_99(void) static int game_log(int type, int money) { - FILE *fp; - if (money > 0) - demoney(money); + card_add_money(money); + + // if the money is not real user money, no need to log anymore. +#if 0 + FILE *fp; switch (type) { case JACK: @@ -380,7 +445,8 @@ game_log(int type, int money) fclose(fp); break; } - usleep(2*1000000); // sleep 2s +#endif + return 0; } @@ -390,10 +456,9 @@ card_double_ask(void) char buf[100], buf2[3]; snprintf(buf, sizeof(buf), - "[ %s ]您現在共有 %d 元, 現在要分組(加收 %d 元)嗎? [y/N]", - cuser.userid, cuser.money, JACK); - reload_money(); - if (cuser.money < JACK) + "[ %s ]您現在共有 %d 枚籌碼, 現在要分組(加收 %d 枚)嗎? [y/N]", + cuser.userid, card_get_money(), JACK); + if (card_get_money() < JACK) return 0; getdata(20, 0, buf, buf2, sizeof(buf2), LCECHO); if (buf2[0] == 'y' || buf2[0] == 'Y') @@ -406,8 +471,8 @@ card_ask(void) { char buf[100], buf2[3]; - snprintf(buf, sizeof(buf), "[ %s ]您現在共有 %d 元, 還要加牌嗎? [y/N]", - cuser.userid, cuser.money); + snprintf(buf, sizeof(buf), "[ %s ]您現在共有 %d 枚籌碼, 還要加牌嗎? [y/N]", + cuser.userid, card_get_money()); getdata(20, 0, buf, buf2, sizeof(buf2), LCECHO); if (buf2[0] == 'y' || buf2[0] == 'Y') return 1; @@ -474,11 +539,11 @@ card_jack(int *db) c[0]=1; card_show(6, cpu, c, me, m); game_log(JACK, JACK); - vmsgf("你跟電腦都拿到黑傑克, 退還 %d 元", JACK); + vmsgf("你跟電腦都拿到黑傑克, 退還 %d 枚籌碼", JACK); return 0; } game_log(JACK, JACK * 5/2); - vmsgf("很不錯唷! (黑傑克!! 加 %d 元)", JACK * 5/2); + vmsgf("很不錯唷! (黑傑克!! 加 %d 枚籌碼)", JACK * 5/2); return 0; } else if(card_isblackjack(cpu[0],cpu[1])) { c[0] = 1; @@ -510,7 +575,7 @@ card_jack(int *db) } if (i == 6) { /* 畫面只能擺六張牌, 因此直接算玩家贏. 黑傑克實際上沒這規則 */ game_log(JACK, JACK * 10); - vmsgf("好厲害唷! 六張牌還沒爆! 加 %d 元!", 5 * JACK); + vmsgf("好厲害唷! 六張牌還沒爆! 加 %d 枚籌碼!", 5 * JACK); return 0; } @@ -522,7 +587,7 @@ card_jack(int *db) if (card_alls_lower(cpu) > 21) { card_show(6, cpu, c, me, m); game_log(JACK, JACK * 2); - vmsgf("呵呵...電腦爆掉了! 你贏了! 可得 %d 元", JACK * 2); + vmsgf("呵呵...電腦爆掉了! 你贏了! 可得 %d 枚籌碼", JACK * 2); return 0; } j++; @@ -530,12 +595,12 @@ card_jack(int *db) card_show(6, cpu, c, me, m); if(card_alls_upper(cpu)==card_alls_upper(me)) { game_log(JACK, JACK); - vmsgf("平局,退回 %d 元!", JACK); + vmsgf("平局,退回 %d 枚籌碼!", JACK); return 0; } if(card_alls_upper(cpu)<card_alls_upper(me)) { game_log(JACK, JACK * 2); - vmsgf("呵呵...電腦比較小! 你贏了! 可得 %d 元", JACK * 2); + vmsgf("呵呵...電腦比較小! 你贏了! 可得 %d 枚籌碼", JACK * 2); return 0; } game_log(JACK, 0); @@ -543,43 +608,6 @@ card_jack(int *db) return 0; } -int -g_card_jack(void) -{ - int db; - char buf[3]; - // int times = 0; - - setutmpmode(JACK_CARD); - while (1) { - reload_money(); - if (cuser.money < PMONEY) { - outs("您的錢不夠唷!去多發表些有意義的文章再來~~~"); - return 0; - } -#if 0 // should we also notify this? - if (times++ % 5 == 0) - { - move(b_lines-2, 0); clrtoeol(); - outs(ANSI_COLOR(1;31) - "警告: 本遊戲由 PttGames 看板評鑑為黑店,請小心!" ANSI_RESET); - } -#endif - getdata(b_lines - 1, 0, "確定要玩黑傑克嗎 一次十元唷?(Y/N)?[N]", - buf, 3, LCECHO); - if ((*buf != 'y') && (*buf != 'Y')) - break; - else { - db = -1; - vice(PMONEY, "黑傑克"); - do { - card_jack(&db); - } while(db>=0); - } - } - return 0; -} - static int card_all(int all[]) { @@ -623,7 +651,7 @@ ten_helf(void) } if (i == 5) { /* 過五關 */ game_log(TEN_HALF, PMONEY * 5); - vmsgf("好厲害唷! 過五關嘍! 加 %d 元!", 5 * PMONEY); + vmsgf("好厲害唷! 過五關嘍! 加 %d 枚籌碼!", 5 * PMONEY); return 0; } j = 1; @@ -635,7 +663,7 @@ ten_helf(void) if (card_all(cpu) > 21) { card_show(5, cpu, c, me, m); game_log(TEN_HALF, PMONEY * 2); - vmsgf("呵呵...電腦爆掉了! 你贏了! 可得 %d 元", PMONEY * 2); + vmsgf("呵呵...電腦爆掉了! 你贏了! 可得 %d 枚籌碼", PMONEY * 2); return 0; } j++; @@ -646,36 +674,70 @@ ten_helf(void) return 0; } +// Main Game Loops + +int +g_card_jack(void) +{ + int db; + char buf[3]; + + setutmpmode(JACK_CARD); + card_reset_money(); + + buf[0] = 'y'; + while (1) { + + if (buf[0] == 'n') + { + card_end_game(); + break; + } + + db = -1; + card_add_money(-PMONEY); + do { + card_jack(&db); + } while(db>=0); + + if (card_get_money() >= PMONEY) + { + getdata(b_lines - 1, 0, "再玩一局? (Y/n) [Y]", + buf, 3, LCECHO); + card_anti_bot_sleep(); + } else + buf[0] = 'n'; + } + return 0; +} + int g_ten_helf(void) { char buf[3]; - int times = 0; setutmpmode(TENHALF); + card_reset_money(); + + buf[0] = 'y'; while (1) { - reload_money(); - if (cuser.money < PMONEY) { - outs("您的錢不夠唷!去多發表些有意義的文章再來~~~"); - return 0; - } - if (times++ == 0) + if (buf[0] == 'n') { - move(b_lines-2, 0); clrtoeol(); - outs(ANSI_COLOR(1;31) - "警告: 本遊戲由 PttGames 看板評鑑為極度黑店,請小心!" ANSI_RESET); + card_end_game(); + break; } - getdata(b_lines - 1, 0, - ANSI_COLOR(1;37) "確定要玩十點半嗎 一次十元唷?(Y/N)?[N]" ANSI_RESET, + card_add_money(-PMONEY); + ten_helf(); + + if (card_get_money() >= PMONEY) + { + getdata(b_lines - 1, 0, "再玩一局? (Y/n) [Y]", buf, 3, LCECHO); - if (buf[0] != 'y' && buf[0] != 'Y') - return 0; - else { - vice(PMONEY, "十點半"); - ten_helf(); - } + card_anti_bot_sleep(); + } else + buf[0] = 'n'; } return 0; } |