pigroom.c

来自「C实现的MUD,对大家基本入门网络游戏很有帮助!」· C语言 代码 · 共 655 行 · 第 1/2 页

C
655
字号
// pigroom.c 拱猪房// Written by Xiang Tu <tu@uwalpha.uwinnipeg.ca>#include <pig.h>//inherit F_CLEAN_UP;inherit ROOM;string 	*seat = ({ "north", "west", "south", "east" });mapping chinese_seat = ([ 	"north": "北边",	"west" : "西边",	"south": "南边",	"east" : "东边",]);int pig_stage;int round_no, roundcard_count;string *round_order = allocate(4);int bid_flag;string bidcard_str = "";object server;string claimer;mapping	pl = allocate_mapping(4), 	cards = allocate_mapping(4),	card_count = allocate_mapping(4),	roundcards = allocate_mapping(4),	picks = allocate_mapping(4),	pick_count = allocate_mapping(4),	passed = allocate_mapping(4),	agreed = allocate_mapping(4),	hscore = allocate_mapping(4),	tscore = allocate_mapping(4);	string	dealer;int	*allow_playbid = allocate(4);int 	*oldcards = allocate(52), 	*newcards = allocate(52);int pl_count();void pig_init();void deal_init();void bid_init();void after_bid();void round_init(string w);void after_round();void play_init();void after_claim();void after_play();void after_round();void after_winner(string rw);void after_hand();void auto_play();string refresh_str(string dir);string picks_str();string table_str(string dir);string scoreboard_str();void reset()	// set this room to no_reset{}int pl_count(){	int i, r;	for (i = r = 0; i < 4; i++)		if (objectp(pl[seat[i]]))			r++;		else			map_delete(pl, seat[i]);	return r;}void pig_init(){	int i;	pig_stage = PIG_INITTING;	for (i = 0; i < 4; i++) {		tscore[seat[i]] = hscore[seat[i]] = 0;		cards[seat[i]] = allocate(13);		picks[seat[i]] = allocate(16);	}	for (i = 0; i < 52; i++)		oldcards[i] = i;}void deal_init(){	pig_stage = PIG_DEALING;	tell_room(this_object(), scoreboard_str());	tell_room(this_object(),"桌长请 deal !\n");}void bid_init(){	int i;	pig_stage = PIG_BIDDING;	bidcard_str = "";	bid_flag = 0;	for (i = 0; i < 4; i++) {		allow_playbid[i] = 1;		passed[seat[i]] = 0;	}}void play_init(){	int i, j;	pig_stage = PIG_PLAYING;	round_no = 1;	for (i = 0; i < 4; i++) {		pick_count[seat[i]] = 0;		card_count[seat[i]] = 13;		for (j = 0; j < 16; j++)			picks[seat[i]][j] = 53;		claimer = "";		agreed[seat[i]] = 0;	}	round_init(dealer);}void round_init(string rw){	int i;	for (i = 0; i < 4; i++) 		roundcards[seat[i]] = -1;	roundcard_count = 0;	round_order = PIG_D->order_turn(rw);	if (pig_stage == PIG_PLAYING)		tell_object(pl[rw], refresh_str(rw) + "现在轮到你出牌!\n");}	void init(){	add_action("do_sit", "sit");	add_action("do_leave", "leave");	add_action("do_deal", "deal");	add_action("do_bid", "bid");	add_action("do_bid", "sell");	add_action("do_pass", "pass");	add_action("do_play", "play");	add_action("do_refresh", "refresh");	add_action("do_skip", "skip");	add_action("do_claim", "claim");}string picks_str(){	int i;        string r = "", t;         for (i = 0; i < 4; i++) {		t = "";		if (objectp(pl[seat[i]]))                	t = pl[seat[i]]->query("name");		else 			t = chinese_seat[seat[i]];                if (pick_count[seat[i]] > 0) {                        t += "捡了下面这些牌:\n";                        t += PIG_D->refresh(picks[seat[i]], 0, pick_count[seat[i]] - 1);                }                else                       	t = "";		r += t;        }	return r;}string refresh_str(string dir){//	if (dir != "north" && dir != "west" && dir != "south" && dir != "east")		return PIG_D->refresh(cards[dir], 0, card_count[dir] - 1);//	return "";}	string table_str(string dir)	// what's going on in table ?{	int i;	mapping rseat = ([]);	string r = "", z = "";	if (pig_stage == PIG_PLAYING && pl_count() == 4) { // if in playing mode		if (dir != "north" && dir != "west" && dir != "south" 			&& dir != "east")			rseat = PIG_D->order_turn("north");		else			rseat = PIG_D->order_turn(dir);//		r = "桌上面正在激烈的拱着!!\n";			if (roundcard_count < 4)			r = sprintf("现在是第%s轮,该由%s出牌。\n", 			chinese_number(round_no), 			pl[round_order[roundcard_count]]->query("name"));		if (bidcard_str != "")			r += "卖了的牌:" + bidcard_str + "\n\n";		else			r += "没有人卖牌。\n";		r = sprintf("%s%24s(%s)\n", r, "", pl[rseat[2]]->query("name"));	// writes north name		r = sprintf("%s%26s%s\n", r, "", 			PIG_D->card_str(roundcards[rseat[2]]));		r = sprintf("%s%4s%16s%6s%6s%6s%s\n", r, "", "(" + 			pl[rseat[3]]->query("name") + ")", 			PIG_D->card_str(roundcards[rseat[3]]), "", 			PIG_D->card_str(roundcards[rseat[1]]), "(" +			pl[rseat[1]]->query("name") + ")");		r = sprintf("%s%26s%s\n", r, "",			PIG_D->card_str(roundcards[rseat[0]]));		r = sprintf("%s%24s(%s)\n", r, "", pl[rseat[0]]->query("name"));		if (card_count[dir] > 0)			r += refresh_str(dir);		r += picks_str();	}	else {	        r = "这是一张专门用于拱猪的四方桌。\n\n";               	if (bidcard_str != "")                        r += "卖了的牌:" + bidcard_str + "\n\n";                else                        r += "没有人卖牌。\n";		for (i = 0; i < 4; i++) 			if (objectp(pl[seat[i]])) {				if (pl[seat[i]] == server) z = "@"; else z = "";				r = sprintf("%s%s的椅子上坐的是:%s(%s)%s。\n", r,				chinese_seat[seat[i]], pl[seat[i]]->query("name"),				pl[seat[i]]->query("id"), z);			}			else				r = sprintf("%s%4s的椅子是空的。如果你想玩,可以用 sit %-5s 坐上去。\n",				r, chinese_seat[seat[i]], seat[i]);	}	return r;}string scoreboard_str(){	int i;	string r;	r = "拱猪成绩表(Scoreboard)\n-----------------\n姓名        盘分   总分\n-----------------\n";	for (i = 0; i < 4; i++)		if (objectp(pl[seat[i]]))			r = sprintf("%s%-14s%10d%10d\n", r,			(string)pl[seat[i]]->query("name"),			(int)hscore[seat[i]], (int)tscore[seat[i]]);	return r + "-----------------\n";}void score_reset(){	int i;	for (i = 0; i < 4; i++)		tscore[seat[i]] = 0;}int do_skip(string arg){	if (!this_player()->query_temp("pigging_seat"))		return notify_fail("你没有在拱猪!\n");	if (this_player() != server)		return notify_fail("只有桌长才能跳过这副牌!\n");	if (pig_stage < PIG_BIDDING)		return notify_fail("牌都没有,跳什么?\n");	message_vision("桌长$N决定跳过这副牌!!\n", server);	if (pl_count() == 4)		deal_init();	return 1;}void after_claim(){	int i, j, k;	for (i = 0; i < roundcard_count; i++) 		if (PIG_D->is_special(roundcards[i]))			picks[claimer][pick_count[claimer]++] = roundcards[j];	for (i = 0; i < 4; i++)		for (j = 0; j < card_count[seat[i]]; j++)			if (PIG_D->is_special(cards[seat[i]][j]))				picks[claimer][pick_count[claimer]++] = cards[seat[i]][j];	after_hand();}int do_claim(string arg){	int i;	object me = this_player();	if (!me->query_temp("pigging_seat"))		return notify_fail("你没有在拱猪!\n");	if (pl_count() != 4)		return notify_fail("现在桌子上没坐满!\n");	if (pig_stage != PIG_PLAYING)		return notify_fail("你想干什么?\n");	if (claimer == me->query_temp("pigging_seat"))		return notify_fail("一次就够了!\n");	if (!arg) {		if (claimer != "")			return notify_fail("claim yes|no ?\n");		agreed[claimer = me->query_temp("pigging_seat")] = 1;		write("你发出全收的要求!等待回音……\n");		for (i = 0; i < 4; i++)			if (seat[i] != claimer)				tell_object(pl[seat[i]], me->query("name") + 					"认为他手中的牌都是大的了!\n" +					refresh_str(me->query_temp("pigging_seat")) +					"请用 claim yes 通过,或者 claim no 否决。\n");		return 1;	}	if (arg == "yes") {		if (claimer == "")			return notify_fail("没有人想全收!\n");		if (!agreed[me->query_temp("pigging_seat")]) {			agreed[me->query_temp("pigging_seat")] = 1;			message_vision("$N同意$n的牌都是大的了!\n", me, pl[claimer]);			for (i = 0; i < 4; i++)				if (agreed[seat[i]] != 1)					return 1;			message_vision("$N的要求被通过了!!\n", pl[claimer]);			after_claim();			return 1;		}	}	if (arg == "no") {		if (claimer == "")			return notify_fail("没有人想全收!\n");		message_vision("$N否决了$n的要求!!\n继续出牌!\n", me, pl[claimer]);		claimer = "";		for (i = 0; i < 4; i++)			agreed[seat[i]] = 0;		return 1;	}	else		return notify_fail("claim 什么?\n");}	

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?