pigroom.c
来自「C实现的MUD,对大家基本入门网络游戏很有帮助!」· C语言 代码 · 共 655 行 · 第 1/2 页
C
655 行
int do_sit(string arg){ object me = this_player(); if (!arg || (arg != "north" && arg != "west" && arg != "south" && arg != "east")) return notify_fail("你想坐在哪里?\n"); if (server == me) return notify_fail("桌长不能换坐位!\n"); map_delete(pl, (string)me->query_temp("pigging_seat")); if (!objectp(pl[arg])) { if (!pl_count()) { pig_init(); server = me; write("你现在是桌长!\n"); round_order = PIG_D->order_turn(dealer = arg); } pl[arg] = me; me->set_temp("pigging_seat", arg); message_vision("$N坐上了" + chinese_seat[arg] + "的位子。\n", me); if (pl_count() == 3) tell_room(this_object(), "现在是三缺一,你们只再需要一个玩家就可以开拱了!\n"); if (pl_count() == 4) { tell_room(this_object(), "好,人凑齐了!\n"); deal_init(); } return 1; } else return notify_fail("这个位子上已经有人了!\n");}int do_leave(string arg){ int i; object me = this_player(); if (!me->query_temp("pigging_seat", arg)) return notify_fail("你现在没有在拱猪!\n"); else if (server == me) { message_vision("桌长$N不想再拱下去了!\n", me); server = 0; for (i = 0; i < 4; i++) if (objectp(pl[seat[i]])) { message_vision("$N站了起来。\n", pl[seat[i]]); pl[seat[i]]->delete_temp("pigging_seat"); map_delete(pl, seat[i]); } pig_stage = PIG_INITTING; return 1; } else { map_delete(pl, (string)me->query_temp("pigging_seat")); me->delete_temp("pigging_seat"); message_vision("$N不想再拱了,站了起来!\n", me); return 1; }}void do_assign_cards() // assign cards to players{ int i, j, k = 0; for (i = 0; i < 13; i++) for (j = 0; j < 4; j++) cards[seat[j]][i] = newcards[k++]; for (i = 0; i < 4; i++) { cards[seat[i]] = sort_array(cards[seat[i]], 1); tell_object(pl[seat[i]], PIG_D->refresh(cards[seat[i]], 0, 12)); card_count[seat[i]] = 13; }}int do_deal(string arg){ int i, j, k; object me = this_player(); if (me != server) return notify_fail("你不是桌长!\n"); if (pig_stage != PIG_DEALING || pl_count() != 4) return notify_fail("现在不能发牌!\n"); PIG_D->shuffle(oldcards, newcards, 2); for (i = 0; i < 13; i++) for (j = 0; j < 4; j++) cards[seat[j]][i] = newcards[k++]; for (i = 0; i < 4; i++) { cards[seat[i]] = sort_array(cards[seat[i]], 1); tell_object(pl[seat[i]], "你得到的牌为:\n" + PIG_D->refresh(cards[seat[i]], 0, 12)); card_count[seat[i]] = 13; } tell_room(this_object(), "发完牌了,有谁要卖牌的没有?\n"); tell_room(this_object(), "如果你卖完了牌,打一下 pass 。\n"); bid_init(); return 1;}int do_refresh(string arg){ object me = this_player(); if (!me->query_temp("pigging_seat")) return notify_fail("你没有在拱猪!\n"); if (pig_stage < PIG_BIDDING || card_count[me->query_temp("pigging_seat")] < 1) return notify_fail("你手上没有牌!\n"); tell_object(pl[(string)me->query_temp("pigging_seat")], "你手上有这些牌:\n" + refresh_str(me->query_temp("pigging_seat"))); return 1;}int do_bid(string arg){ object me = this_player(); int c, b; string ts; if (!me->query_temp("pigging_seat")) return notify_fail("你没有在拱猪!\n"); if (pig_stage != PIG_BIDDING) return notify_fail("现在不是卖牌的时候!\n"); if (!arg) return notify_fail("你想卖什么?\n"); if ((c = PIG_D->is_validcard(arg)) == -1 || !PIG_D->has_card(cards[me->query_temp("pigging_seat")], 0, 12, c)) return notify_fail("你手上没有这张牌!\n"); if (!(b = PIG_D->is_validbid(c))) return notify_fail("这张牌不能被卖!\n"); if (bid_flag & b) return notify_fail("这张牌已经被卖过了!\n"); bid_flag |= b; switch (b) { case BID_SPIG : allow_playbid[0] = 0; break; case BID_HACE : allow_playbid[1] = 0; break; case BID_DSHEEP : allow_playbid[2] = 0; break; case BID_CTRANS : allow_playbid[3] = 0; break; } message_vision("$N说道:我卖" + PIG_D->card_str(c) + "!\n", me); ts = ""; if (bidcard_str != "") ts = ","; bidcard_str = PIG_D->card_str(c) + "(" + me->query("name") + ")" + ts + bidcard_str; return 1;}int do_pass(string arg){ object me = this_player(); int i; if (!me->query_temp("pigging_seat")) return notify_fail("你没有在拱猪!\n"); if (pig_stage != PIG_BIDDING) return notify_fail("你想干什么?\n"); if (passed[me->query_temp("pigging_seat")] == 1) return notify_fail("你已经停卖了!\n"); passed[me->query_temp("pigging_seat")] = 1; message_vision("$N说道:我停卖!\n", me); for (i = 0; i < 4; i++) if ((int)passed[seat[i]] == 0) return 1; for (i = 0; i < 4; i++) passed[seat[i]] = 0; tell_room(this_object(), "全部停卖,开拱!!\n"); tell_room(this_object(), "这把由" + pl[dealer]->query("name") + "先出。\n"); play_init(); return 1;}void after_play(){ int i; roundcard_count++; for (i = 0; i < 4; i++) if (card_count[seat[i]] > 0) tell_object(pl[seat[i]], table_str(seat[i])); if (roundcard_count > 3) after_round();} void after_winner(string rw){ int i; message_vision("$N的" + PIG_D->card_str(roundcards[rw]) + "最大!\n", pl[rw]); for (i = 0; i < 4; i++) if (PIG_D->is_special(roundcards[seat[i]])) { picks[rw][pick_count[rw]++] = roundcards[seat[i]]; if (roundcards[seat[i]] == SPIG) { message_vision("$N得到了猪头!!\n", pl[rw]); dealer = rw; } } picks[rw] = sort_array(picks[rw], 1);}void after_round(){ int i; string rw; allow_playbid[SUIT(roundcards[round_order[0]])] = 1; after_winner(rw = PIG_D->card_cmp4(roundcards, SUIT(roundcards[round_order[0]]))); round_init(rw); if (round_no++ == 12) auto_play(); // starts auto_play}void auto_play(){ int i; for (i = 0; i < 4; i++) roundcards[seat[i]] = cards[seat[i]][0]; roundcard_count = 4; for (i = 0; i < 4; i++) { card_count[seat[i]] = 0; tell_object(pl[seat[i]], table_str(seat[i])); } after_winner(PIG_D->card_cmp4(roundcards, SUIT(roundcards[round_order[0]]))); after_hand();}void after_hand(){ // doing the scoring here int i; string collect_all = ""; for (i = 0; i < 4; i++) { hscore[seat[i]] = PIG_D->count_score(picks[seat[i]], bid_flag); if (hscore[seat[i]] == 1000) collect_all = seat[i]; pl[seat[i]]->add("pig_played", 1); pl[seat[i]]->add("pig_score", hscore[seat[i]]); } if (collect_all == "") for (i = 0; i < 4; i++) { tscore[seat[i]] += hscore[seat[i]]; if (tscore[seat[i]] <= -1000) pl[seat[i]]->add("pig_head", 1); } else { for (i = 0; i < 4; i++) if (seat[i] != collect_all) pl[seat[i]]->add("pig_head", 1); } for (i = 0; i < 4; i++) if (tscore[seat[i]] <= -1000) message_vision("$N是一头猪!\n", pl[seat[i]]); for (i = 0; i < 4; i++) if (tscore[seat[i]] <= -1000) { score_reset(); break; } deal_init();} int do_play(string arg){ object me = this_player(); int i, c, sc, nbc = 0, cpos = -1; string ms; if (!(ms = me->query_temp("pigging_seat"))) return notify_fail("你没有在拱猪!\n"); if (pig_stage != PIG_PLAYING) return notify_fail("现在不是出牌阶段!\n"); if (ms != round_order[roundcard_count]) return notify_fail("还没轮到你出牌!\n"); if (!arg || (c = PIG_D->is_validcard(arg)) == -1) return notify_fail("你要出哪张牌?\n"); for (i = 0; i < card_count[ms]; i++) if (cards[ms][i] == c) { cpos = i; break; } if (cpos == -1) return notify_fail("你手里没有这张牌!\n"); if (roundcard_count > 0 && (sc = PIG_D->has_suit(cards[ms], 0, card_count[ms] - 1, SUIT(roundcards[round_order[0]]))) > 0 && SUIT(c) != SUIT(roundcards[round_order[0]])) return notify_fail("你不能出这张牌!\n"); if (roundcard_count == 0 || sc > 1) { switch (c) { case SPIG : if (!allow_playbid[SPADE]) nbc = 1; break; case HACE : if (!allow_playbid[HEART]) nbc = 1; break; case DSHEEP : if (!allow_playbid[DIAMOND]) nbc = 1; break; case CTRANS : if (!allow_playbid[CLUB]) nbc = 1; break; } if (nbc) return notify_fail("卖过的牌不能在第一轮出!\n"); } for (i = cpos; i < card_count[ms] - 1; i++) cards[ms][i] = cards[ms][i+1]; cards[ms][13 - round_no] = 53; roundcards[ms] = c; card_count[ms]--; if (roundcard_count > 0 && SUIT(c) != SUIT(roundcards[round_order[0]])) message_vision("$N垫了一张" + PIG_D->card_str(c) + "!\n", me); else message_vision("$N出了一张" + PIG_D->card_str(c) + "!\n", me); after_play(); return 1;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?